Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AP_Airspeed: Add support for new message #22709

Merged
merged 7 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AntennaTracker/GCS_Mavlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ static const ap_message STREAM_RAW_SENSORS_msgs[] = {
MSG_SCALED_PRESSURE,
MSG_SCALED_PRESSURE2,
MSG_SCALED_PRESSURE3,
MSG_AIRSPEED,
};
static const ap_message STREAM_EXTENDED_STATUS_msgs[] = {
MSG_SYS_STATUS,
Expand Down
3 changes: 2 additions & 1 deletion ArduCopter/GCS_Mavlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ bool GCS_MAVLINK_Copter::try_send_message(enum ap_message id)
const AP_Param::GroupInfo GCS_MAVLINK_Parameters::var_info[] = {
// @Param: RAW_SENS
// @DisplayName: Raw sensor stream rate
// @Description: MAVLink Stream rate of RAW_IMU, SCALED_IMU2, SCALED_IMU3, SCALED_PRESSURE, SCALED_PRESSURE2, and SCALED_PRESSURE3
// @Description: MAVLink Stream rate of RAW_IMU, SCALED_IMU2, SCALED_IMU3, SCALED_PRESSURE, SCALED_PRESSURE2, SCALED_PRESSURE3 and AIRSPEED
// @Units: Hz
// @Range: 0 50
// @Increment: 1
Expand Down Expand Up @@ -503,6 +503,7 @@ static const ap_message STREAM_RAW_SENSORS_msgs[] = {
MSG_SCALED_PRESSURE,
MSG_SCALED_PRESSURE2,
MSG_SCALED_PRESSURE3,
MSG_AIRSPEED,
};
static const ap_message STREAM_EXTENDED_STATUS_msgs[] = {
MSG_SYS_STATUS,
Expand Down
3 changes: 2 additions & 1 deletion ArduPlane/GCS_Mavlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ void GCS_MAVLINK_Plane::send_hygrometer()
const AP_Param::GroupInfo GCS_MAVLINK_Parameters::var_info[] = {
// @Param: RAW_SENS
// @DisplayName: Raw sensor stream rate
// @Description: MAVLink Stream rate of RAW_IMU, SCALED_IMU2, SCALED_IMU3, SCALED_PRESSURE, SCALED_PRESSURE2, and SCALED_PRESSURE3
// @Description: MAVLink Stream rate of RAW_IMU, SCALED_IMU2, SCALED_IMU3, SCALED_PRESSURE, SCALED_PRESSURE2, SCALED_PRESSURE3 and AIRSPEED
// @Units: Hz
// @Range: 0 50
// @Increment: 1
Expand Down Expand Up @@ -614,6 +614,7 @@ static const ap_message STREAM_RAW_SENSORS_msgs[] = {
MSG_SCALED_PRESSURE,
MSG_SCALED_PRESSURE2,
MSG_SCALED_PRESSURE3,
MSG_AIRSPEED,
};
static const ap_message STREAM_EXTENDED_STATUS_msgs[] = {
MSG_SYS_STATUS,
Expand Down
3 changes: 2 additions & 1 deletion ArduSub/GCS_Mavlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ bool GCS_MAVLINK_Sub::try_send_message(enum ap_message id)
const AP_Param::GroupInfo GCS_MAVLINK_Parameters::var_info[] = {
// @Param: RAW_SENS
// @DisplayName: Raw sensor stream rate
// @Description: Stream rate of RAW_IMU, SCALED_IMU2, SCALED_PRESSURE, and SENSOR_OFFSETS to ground station
// @Description: Stream rate of RAW_IMU, SCALED_IMU2, SCALED_PRESSURE, AIRSPEED, and SENSOR_OFFSETS to ground station
// @Units: Hz
// @Range: 0 50
// @Increment: 1
Expand Down Expand Up @@ -353,6 +353,7 @@ static const ap_message STREAM_RAW_SENSORS_msgs[] = {
MSG_SCALED_PRESSURE,
MSG_SCALED_PRESSURE2,
MSG_SCALED_PRESSURE3,
MSG_AIRSPEED,
};
static const ap_message STREAM_EXTENDED_STATUS_msgs[] = {
MSG_SYS_STATUS,
Expand Down
3 changes: 2 additions & 1 deletion Blimp/GCS_Mavlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ bool GCS_MAVLINK_Blimp::try_send_message(enum ap_message id)
const AP_Param::GroupInfo GCS_MAVLINK_Parameters::var_info[] = {
// @Param: RAW_SENS
// @DisplayName: Raw sensor stream rate
// @Description: Stream rate of RAW_IMU, SCALED_IMU2, SCALED_IMU3, SCALED_PRESSURE, SCALED_PRESSURE2, SCALED_PRESSURE3 and SENSOR_OFFSETS to ground station
// @Description: Stream rate of RAW_IMU, SCALED_IMU2, SCALED_IMU3, SCALED_PRESSURE, SCALED_PRESSURE2, SCALED_PRESSURE3, AIRSPEED and SENSOR_OFFSETS to ground station
// @Units: Hz
// @Range: 0 10
// @Increment: 1
Expand Down Expand Up @@ -315,6 +315,7 @@ static const ap_message STREAM_RAW_SENSORS_msgs[] = {
MSG_SCALED_PRESSURE,
MSG_SCALED_PRESSURE2,
MSG_SCALED_PRESSURE3,
MSG_AIRSPEED,
};
static const ap_message STREAM_EXTENDED_STATUS_msgs[] = {
MSG_SYS_STATUS,
Expand Down
3 changes: 2 additions & 1 deletion Rover/GCS_Mavlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ void GCS_MAVLINK_Rover::packetReceived(const mavlink_status_t &status, const mav
const AP_Param::GroupInfo GCS_MAVLINK_Parameters::var_info[] = {
// @Param: RAW_SENS
// @DisplayName: Raw sensor stream rate
// @Description: MAVLink Stream rate of RAW_IMU, SCALED_IMU2, SCALED_IMU3, SCALED_PRESSURE, SCALED_PRESSURE2, and SCALED_PRESSURE3
// @Description: MAVLink Stream rate of RAW_IMU, SCALED_IMU2, SCALED_IMU3, SCALED_PRESSURE, SCALED_PRESSURE2, SCALED_PRESSURE3 and AIRSPEED
// @Units: Hz
// @Range: 0 50
// @Increment: 1
Expand Down Expand Up @@ -529,6 +529,7 @@ static const ap_message STREAM_RAW_SENSORS_msgs[] = {
MSG_SCALED_PRESSURE,
MSG_SCALED_PRESSURE2,
MSG_SCALED_PRESSURE3,
MSG_AIRSPEED,
};
static const ap_message STREAM_EXTENDED_STATUS_msgs[] = {
MSG_SYS_STATUS,
Expand Down
7 changes: 7 additions & 0 deletions libraries/GCS_MAVLink/GCS.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -360,6 +361,12 @@ class GCS_MAVLINK
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();
Expand Down
62 changes: 62 additions & 0 deletions libraries/GCS_MAVLink/GCS_Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions libraries/GCS_MAVLink/ap_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Loading