GCS_MAVLink: add support for AIRSPEED message

This commit is contained in:
Iampete1 2023-01-21 19:15:43 +00:00 committed by Andrew Tridgell
parent c3393d8d16
commit 8318109546
3 changed files with 70 additions and 0 deletions

View File

@ -27,6 +27,7 @@
#include <AP_Winch/AP_Winch_config.h>
#include <AP_AHRS/AP_AHRS_config.h>
#include <AP_Arming/AP_Arming_config.h>
#include <AP_Airspeed/AP_Airspeed_config.h>
#include "ap_message.h"
@ -360,6 +361,12 @@ public:
void send_scaled_pressure();
void send_scaled_pressure2();
virtual void send_scaled_pressure3(); // allow sub to override this
#if AP_AIRSPEED_ENABLED
// Send per instance airspeed message
// last index is used to rotate through sensors
void send_airspeed();
uint8_t last_airspeed_idx;
#endif
void send_simstate() const;
void send_sim_state() const;
void send_ahrs();

View File

@ -1125,6 +1125,9 @@ ap_message GCS_MAVLINK::mavlink_id_to_ap_message_id(const uint32_t mavlink_id) c
#endif
#if AP_MAVLINK_MSG_RELAY_STATUS_ENABLED
{ MAVLINK_MSG_ID_RELAY_STATUS, MSG_RELAY_STATUS},
#endif
#if AP_AIRSPEED_ENABLED
{ MAVLINK_MSG_ID_AIRSPEED, MSG_AIRSPEED},
#endif
};
@ -2327,6 +2330,58 @@ void GCS_MAVLINK::send_scaled_pressure3()
send_scaled_pressure_instance(2, mavlink_msg_scaled_pressure3_send);
}
#if AP_AIRSPEED_ENABLED
void GCS_MAVLINK::send_airspeed()
{
AP_Airspeed *airspeed = AP_Airspeed::get_singleton();
if (airspeed == nullptr) {
return;
}
for (uint8_t i=0; i<AIRSPEED_MAX_SENSORS; i++) {
// Try and send the next sensor
const uint8_t index = (last_airspeed_idx + 1 + i) % AIRSPEED_MAX_SENSORS;
if (!airspeed->enabled(index)) {
continue;
}
float temperature_float;
int16_t temperature = INT16_MAX;
if (airspeed->get_temperature(index, temperature_float)) {
temperature = int16_t(temperature_float * 100);
}
uint8_t flags = 0;
// Set unhealthy flag
if (!airspeed->healthy(index)) {
flags |= 1U << AIRSPEED_SENSOR_FLAGS::AIRSPEED_SENSOR_UNHEALTHY;
}
// Set using flag if the AHRS is using this sensor
const AP_AHRS &ahrs = AP::ahrs();
if (ahrs.using_airspeed_sensor() && (ahrs.get_active_airspeed_index() == index)) {
flags |= 1U << AIRSPEED_SENSOR_FLAGS::AIRSPEED_SENSOR_USING;
}
// Assemble message and send
const mavlink_airspeed_t msg {
airspeed : airspeed->get_airspeed(index),
raw_press : airspeed->get_differential_pressure(index),
temperature : temperature,
id : index,
flags : flags
};
mavlink_msg_airspeed_send_struct(chan, &msg);
// Only send one msg per call
last_airspeed_idx = index;
return;
}
}
#endif
#if AP_AHRS_ENABLED
void GCS_MAVLINK::send_ahrs()
{
@ -6288,6 +6343,13 @@ bool GCS_MAVLINK::try_send_message(const enum ap_message id)
send_scaled_pressure3();
break;
#if AP_AIRSPEED_ENABLED
case MSG_AIRSPEED:
CHECK_PAYLOAD_SIZE(AIRSPEED);
send_airspeed();
break;
#endif
case MSG_SERVO_OUTPUT_RAW:
CHECK_PAYLOAD_SIZE(SERVO_OUTPUT_RAW);
send_servo_output_raw();

View File

@ -100,5 +100,6 @@ enum ap_message : uint8_t {
#if AP_MAVLINK_MSG_HIGHRES_IMU_ENABLED
MSG_HIGHRES_IMU,
#endif
MSG_AIRSPEED,
MSG_LAST // MSG_LAST must be the last entry in this enum
};