public ServoOutputRaw(MavLinkMessage message) : base(null) { if (message.messid.Equals(this.MessageID)) { MAVLink.mavlink_servo_output_raw_t data = (MAVLink.mavlink_servo_output_raw_t)message.data_struct; this.port = data.port; this.servo1_raw = data.servo1_raw; this.servo2_raw = data.servo2_raw; this.servo3_raw = data.servo3_raw; this.servo4_raw = data.servo4_raw; this.servo5_raw = data.servo5_raw; this.servo6_raw = data.servo6_raw; this.servo7_raw = data.servo7_raw; this.servo8_raw = data.servo8_raw; this.time_usec = data.time_usec; } }
public void CheckServoOutputRawObject() { MAVLink.mavlink_servo_output_raw_t data = new MAVLink.mavlink_servo_output_raw_t(); data.port = 1; data.servo1_raw = 2; data.servo2_raw = 3; data.servo3_raw = 4; data.servo4_raw = 5; data.servo5_raw = 6; data.servo6_raw = 7; data.servo7_raw = 8; data.servo8_raw = 9; data.time_usec = 10; MavLinkMessage message = createSampleMessage(MAVLink.MAVLINK_MSG_ID.SERVO_OUTPUT_RAW, data); ServoOutputRaw obj = new ServoOutputRaw(message); Assert.AreEqual(data.port, obj.port); Assert.AreEqual(data.servo1_raw, obj.servo1_raw); Assert.AreEqual(data.servo2_raw, obj.servo2_raw); Assert.AreEqual(data.servo3_raw, obj.servo3_raw); Assert.AreEqual(data.servo4_raw, obj.servo4_raw); Assert.AreEqual(data.servo5_raw, obj.servo5_raw); Assert.AreEqual(data.servo6_raw, obj.servo6_raw); Assert.AreEqual(data.servo7_raw, obj.servo7_raw); Assert.AreEqual(data.servo8_raw, obj.servo8_raw); Assert.AreEqual(data.time_usec, obj.time_usec); ServoOutputRawDTO dto = DTOFactory.createServoOutputRawDTO(obj); Assert.AreEqual(dto.port, obj.port); Assert.AreEqual(dto.servo1_raw, obj.servo1_raw); Assert.AreEqual(dto.servo2_raw, obj.servo2_raw); Assert.AreEqual(dto.servo3_raw, obj.servo3_raw); Assert.AreEqual(dto.servo4_raw, obj.servo4_raw); Assert.AreEqual(dto.servo5_raw, obj.servo5_raw); Assert.AreEqual(dto.servo6_raw, obj.servo6_raw); Assert.AreEqual(dto.servo7_raw, obj.servo7_raw); Assert.AreEqual(dto.servo8_raw, obj.servo8_raw); Assert.AreEqual(dto.time_usec, obj.time_usec); }
public IEnumerable <Flight> GetFlights() { if (flights == null) { flights = new List <Model.Flight>(); int min = int.MaxValue; int max = int.MinValue; // mavlink_servo_output_raw_t is an actual PWM signal, so it toggles between RC0_TRIM (usually 1500) and the // values it is sending to the motor, so we have to weed out the trim values in order to see the actual // values. int trim = 1500; // should get this from the parameter values. // compute the min/max servo settings. foreach (var msg in this.data) { if (msg.TypedValue is MAVLink.mavlink_servo_output_raw_t) { MAVLink.mavlink_servo_output_raw_t servo = (MAVLink.mavlink_servo_output_raw_t)msg.TypedValue; if (servo.servo1_raw != 0 && servo.servo1_raw != trim) { min = Math.Min(min, servo.servo1_raw); max = Math.Max(max, servo.servo1_raw); } } } // find flights DateTime start = this.startTime; DateTime endTime = start; Flight current = null; int offCount = 0; // compute the min/max servo settings. foreach (var msg in this.data) { if (msg.TypedValue is MAVLink.mavlink_servo_output_raw_t) { MAVLink.mavlink_servo_output_raw_t servo = (MAVLink.mavlink_servo_output_raw_t)msg.TypedValue; endTime = start.AddMilliseconds(servo.time_usec / 1000); if (servo.servo1_raw != trim) { if (servo.servo1_raw > min) { if (current == null) { current = new Flight() { Log = this, StartTime = start.AddMilliseconds(servo.time_usec / 1000) }; flights.Add(current); offCount = 0; } } else if (servo.servo1_raw == min && offCount++ > 10) { if (current != null) { current.Duration = endTime - current.StartTime; current = null; } } } } } if (current != null) { current.Duration = endTime - current.StartTime; } } return(flights); }