/// <summary> /// Create a row vector from a Vector type. /// </summary> /// <param name="v">Vector to convert</param> public static Matrix CreateRowVector(Vector v) { Matrix resultant = new Matrix(1, 3); resultant[0, 0] = v.X; resultant[0, 1] = v.Y; resultant[0, 2] = v.Z; return resultant; }
/// <summary> /// Create a column vector from a Vector type. /// </summary> /// <param name="v">Vector to convert</param> public static Matrix CreateColumnVector(Vector v) { Matrix resultant = new Matrix(3, 1); resultant[0, 0] = v.X; resultant[1, 0] = v.Y; resultant[2, 0] = v.Z; return resultant; }
/// <summary> /// Event is called when the IMU class has gathered and converted the sensor data /// </summary> private static void Imu_DataProcessed() { // Make a vector of the Y and Z axes acceleration. (forward and backwards, and side to side accelerations) YZ_Vector = new Vector(0, IMU.Data[1], IMU.Data[2]); // If a crash hasn't already been reported and there is a crash. (Crash defined as a magnitude of 4 Gs or greater in the YZ vector) if (crashThread == null && YZ_Vector.Magnitude > 4) { // Begin crash detected thread and warn of a detection with the ready buzz and light crashThread = new Thread(crashEvent); crashThread.Start(); Buzzer.ReadyBuzz(); GoLED.ReadyLight(); } // If we're running a webserver, update the display data if (WebDisplay.Initialized) WebDisplay.UpdateString(IMU.Data); // If we're logging, log the data. if (enableLogging) { buffer = Encoding.UTF8.GetBytes( IMU.Data[0] + "," + IMU.Data[1] + "," + IMU.Data[2] + "," + IMU.Data[3] + "," + IMU.Data[4] + "," + IMU.Data[5] + "," + IMU.Data[6] + "," + IMU.Data[7] + "," + IMU.Data[8] + ",," + IMU.Data[9] + "," + IMU.Data[10] + "," + IMU.Data[11] + "\n"); writer.Write(buffer, 0, buffer.Length); } }