2016-01-14 15:30:56 -04:00
|
|
|
#include "Sub.h"
|
2017-02-03 00:18:27 -04:00
|
|
|
|
|
|
|
#include "GCS_Mavlink.h"
|
2015-12-30 18:57:56 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* !!NOTE!!
|
|
|
|
*
|
|
|
|
* the use of NOINLINE separate functions for each message type avoids
|
|
|
|
* a compiler bug in gcc that would cause it to use far more stack
|
|
|
|
* space than is needed. Without the NOINLINE we use the sum of the
|
|
|
|
* stack needed for each message type. Please be careful to follow the
|
|
|
|
* pattern below when adding any new messages
|
|
|
|
*/
|
|
|
|
|
2019-03-01 20:09:34 -04:00
|
|
|
MAV_TYPE GCS_Sub::frame_type() const
|
2015-12-30 18:57:56 -04:00
|
|
|
{
|
2018-03-22 06:38:37 -03:00
|
|
|
return MAV_TYPE_SUBMARINE;
|
|
|
|
}
|
2015-12-30 18:57:56 -04:00
|
|
|
|
2018-03-22 06:38:37 -03:00
|
|
|
MAV_MODE GCS_MAVLINK_Sub::base_mode() const
|
|
|
|
{
|
2018-04-03 11:35:43 -03:00
|
|
|
uint8_t _base_mode = MAV_MODE_FLAG_STABILIZE_ENABLED;
|
2015-12-30 18:57:56 -04:00
|
|
|
|
|
|
|
// work out the base_mode. This value is not very useful
|
|
|
|
// for APM, but we calculate it as best we can so a generic
|
|
|
|
// MAVLink enabled ground station can work out something about
|
|
|
|
// what the MAV is up to. The actual bit values are highly
|
|
|
|
// ambiguous for most of the APM flight modes. In practice, you
|
|
|
|
// only get useful information from the custom_mode, which maps to
|
|
|
|
// the APM flight mode and has a well defined meaning in the
|
|
|
|
// ArduPlane documentation
|
2018-03-22 06:38:37 -03:00
|
|
|
switch (sub.control_mode) {
|
2015-12-30 18:57:56 -04:00
|
|
|
case AUTO:
|
|
|
|
case GUIDED:
|
|
|
|
case CIRCLE:
|
|
|
|
case POSHOLD:
|
2018-04-03 11:35:43 -03:00
|
|
|
_base_mode |= MAV_MODE_FLAG_GUIDED_ENABLED;
|
2015-12-30 18:57:56 -04:00
|
|
|
// note that MAV_MODE_FLAG_AUTO_ENABLED does not match what
|
|
|
|
// APM does in any mode, as that is defined as "system finds its own goal
|
|
|
|
// positions", which APM does not currently do
|
|
|
|
break;
|
2016-04-18 01:38:21 -03:00
|
|
|
default:
|
2017-02-03 17:33:27 -04:00
|
|
|
break;
|
2015-12-30 18:57:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// all modes except INITIALISING have some form of manual
|
|
|
|
// override if stick mixing is enabled
|
2018-04-03 11:35:43 -03:00
|
|
|
_base_mode |= MAV_MODE_FLAG_MANUAL_INPUT_ENABLED;
|
2015-12-30 18:57:56 -04:00
|
|
|
|
2018-03-22 06:38:37 -03:00
|
|
|
if (sub.motors.armed()) {
|
2018-04-03 11:35:43 -03:00
|
|
|
_base_mode |= MAV_MODE_FLAG_SAFETY_ARMED;
|
2015-12-30 18:57:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// indicate we have set a custom mode
|
2018-04-03 11:35:43 -03:00
|
|
|
_base_mode |= MAV_MODE_FLAG_CUSTOM_MODE_ENABLED;
|
2015-12-30 18:57:56 -04:00
|
|
|
|
2018-04-03 11:35:43 -03:00
|
|
|
return (MAV_MODE)_base_mode;
|
2018-03-22 06:38:37 -03:00
|
|
|
}
|
|
|
|
|
2019-03-01 20:09:34 -04:00
|
|
|
uint32_t GCS_Sub::custom_mode() const
|
2018-03-22 06:38:37 -03:00
|
|
|
{
|
|
|
|
return sub.control_mode;
|
|
|
|
}
|
|
|
|
|
2019-11-25 22:46:33 -04:00
|
|
|
MAV_STATE GCS_MAVLINK_Sub::vehicle_system_status() const
|
2018-03-22 06:38:37 -03:00
|
|
|
{
|
|
|
|
// set system as critical if any failsafe have triggered
|
|
|
|
if (sub.any_failsafe_triggered()) {
|
|
|
|
return MAV_STATE_CRITICAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sub.motors.armed()) {
|
|
|
|
return MAV_STATE_ACTIVE;
|
|
|
|
}
|
2017-02-03 00:18:27 -04:00
|
|
|
|
2018-03-22 06:38:37 -03:00
|
|
|
return MAV_STATE_STANDBY;
|
2015-12-30 18:57:56 -04:00
|
|
|
}
|
|
|
|
|
2021-02-08 21:36:19 -04:00
|
|
|
void GCS_MAVLINK_Sub::send_banner()
|
|
|
|
{
|
|
|
|
GCS_MAVLINK::send_banner();
|
|
|
|
send_text(MAV_SEVERITY_INFO, "Frame: %s", sub.motors.get_frame_string());
|
|
|
|
}
|
|
|
|
|
2018-05-04 21:09:13 -03:00
|
|
|
void GCS_MAVLINK_Sub::send_nav_controller_output() const
|
2015-12-30 18:57:56 -04:00
|
|
|
{
|
2018-05-04 21:09:13 -03:00
|
|
|
const Vector3f &targets = sub.attitude_control.get_att_target_euler_cd();
|
2015-12-30 18:57:56 -04:00
|
|
|
mavlink_msg_nav_controller_output_send(
|
|
|
|
chan,
|
2017-06-19 02:39:46 -03:00
|
|
|
targets.x * 1.0e-2f,
|
|
|
|
targets.y * 1.0e-2f,
|
|
|
|
targets.z * 1.0e-2f,
|
2018-05-04 21:09:13 -03:00
|
|
|
sub.wp_nav.get_wp_bearing_to_destination() * 1.0e-2f,
|
|
|
|
MIN(sub.wp_nav.get_wp_distance_to_destination() * 1.0e-2f, UINT16_MAX),
|
2021-04-27 03:50:06 -03:00
|
|
|
sub.pos_control.get_pos_error_z_cm() * 1.0e-2f,
|
2015-12-30 18:57:56 -04:00
|
|
|
0,
|
2017-02-07 13:24:39 -04:00
|
|
|
0);
|
2015-12-30 18:57:56 -04:00
|
|
|
}
|
|
|
|
|
2018-01-30 22:59:06 -04:00
|
|
|
int16_t GCS_MAVLINK_Sub::vfr_hud_throttle() const
|
2015-12-30 18:57:56 -04:00
|
|
|
{
|
2018-01-30 22:59:06 -04:00
|
|
|
return (int16_t)(sub.motors.get_throttle() * 100);
|
2015-12-30 18:57:56 -04:00
|
|
|
}
|
|
|
|
|
2017-01-13 15:51:48 -04:00
|
|
|
// Work around to get temperature sensor data out
|
2018-05-02 23:06:53 -03:00
|
|
|
void GCS_MAVLINK_Sub::send_scaled_pressure3()
|
2017-02-03 17:33:27 -04:00
|
|
|
{
|
2018-05-02 23:06:53 -03:00
|
|
|
if (!sub.celsius.healthy()) {
|
2017-02-03 17:33:27 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
mavlink_msg_scaled_pressure3_send(
|
|
|
|
chan,
|
|
|
|
AP_HAL::millis(),
|
|
|
|
0,
|
|
|
|
0,
|
2020-07-28 08:05:51 -03:00
|
|
|
sub.celsius.temperature() * 100,
|
|
|
|
0); // TODO: use differential pressure temperature
|
2017-01-13 15:51:48 -04:00
|
|
|
}
|
2015-12-30 18:57:56 -04:00
|
|
|
|
2018-05-16 03:49:23 -03:00
|
|
|
bool GCS_MAVLINK_Sub::send_info()
|
2017-05-08 20:37:42 -03:00
|
|
|
{
|
|
|
|
// Just do this all at once, hopefully the hard-wire telemetry requirement means this is ok
|
|
|
|
// Name is char[10]
|
2018-05-16 03:49:23 -03:00
|
|
|
CHECK_PAYLOAD_SIZE(NAMED_VALUE_FLOAT);
|
|
|
|
send_named_float("CamTilt",
|
|
|
|
1 - (SRV_Channels::get_output_norm(SRV_Channel::k_mount_tilt) / 2.0f + 0.5f));
|
2017-05-08 20:37:42 -03:00
|
|
|
|
2018-05-16 03:49:23 -03:00
|
|
|
CHECK_PAYLOAD_SIZE(NAMED_VALUE_FLOAT);
|
|
|
|
send_named_float("CamPan",
|
|
|
|
1 - (SRV_Channels::get_output_norm(SRV_Channel::k_mount_pan) / 2.0f + 0.5f));
|
2018-02-15 15:56:35 -04:00
|
|
|
|
2018-05-16 03:49:23 -03:00
|
|
|
CHECK_PAYLOAD_SIZE(NAMED_VALUE_FLOAT);
|
|
|
|
send_named_float("TetherTrn",
|
|
|
|
sub.quarter_turn_count/4);
|
2017-05-08 20:37:42 -03:00
|
|
|
|
2018-05-16 03:49:23 -03:00
|
|
|
CHECK_PAYLOAD_SIZE(NAMED_VALUE_FLOAT);
|
|
|
|
send_named_float("Lights1",
|
|
|
|
SRV_Channels::get_output_norm(SRV_Channel::k_rcin9) / 2.0f + 0.5f);
|
2017-05-08 20:37:42 -03:00
|
|
|
|
2018-05-16 03:49:23 -03:00
|
|
|
CHECK_PAYLOAD_SIZE(NAMED_VALUE_FLOAT);
|
|
|
|
send_named_float("Lights2",
|
|
|
|
SRV_Channels::get_output_norm(SRV_Channel::k_rcin10) / 2.0f + 0.5f);
|
2017-05-08 20:37:42 -03:00
|
|
|
|
2018-05-16 03:49:23 -03:00
|
|
|
CHECK_PAYLOAD_SIZE(NAMED_VALUE_FLOAT);
|
|
|
|
send_named_float("PilotGain", sub.gain);
|
2017-05-08 20:37:42 -03:00
|
|
|
|
2018-05-16 03:49:23 -03:00
|
|
|
CHECK_PAYLOAD_SIZE(NAMED_VALUE_FLOAT);
|
|
|
|
send_named_float("InputHold", sub.input_hold_engaged);
|
2017-05-08 20:37:42 -03:00
|
|
|
|
2020-02-20 14:40:01 -04:00
|
|
|
CHECK_PAYLOAD_SIZE(NAMED_VALUE_FLOAT);
|
|
|
|
send_named_float("RollPitch", sub.roll_pitch_flag);
|
|
|
|
|
2017-05-08 20:37:42 -03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-30 18:57:56 -04:00
|
|
|
/*
|
|
|
|
send PID tuning message
|
|
|
|
*/
|
2019-02-28 19:33:10 -04:00
|
|
|
void GCS_MAVLINK_Sub::send_pid_tuning()
|
2015-12-30 18:57:56 -04:00
|
|
|
{
|
2019-02-28 19:33:10 -04:00
|
|
|
const Parameters &g = sub.g;
|
|
|
|
AP_AHRS &ahrs = AP::ahrs();
|
|
|
|
AC_AttitudeControl_Sub &attitude_control = sub.attitude_control;
|
|
|
|
|
2015-12-30 18:57:56 -04:00
|
|
|
const Vector3f &gyro = ahrs.get_gyro();
|
|
|
|
if (g.gcs_pid_mask & 1) {
|
2019-01-18 00:23:42 -04:00
|
|
|
const AP_Logger::PID_Info &pid_info = attitude_control.get_rate_roll_pid().get_pid_info();
|
2017-02-03 17:33:27 -04:00
|
|
|
mavlink_msg_pid_tuning_send(chan, PID_TUNING_ROLL,
|
2019-06-27 06:31:52 -03:00
|
|
|
pid_info.target*0.01f,
|
2015-12-30 18:57:56 -04:00
|
|
|
degrees(gyro.x),
|
|
|
|
pid_info.FF*0.01f,
|
|
|
|
pid_info.P*0.01f,
|
|
|
|
pid_info.I*0.01f,
|
|
|
|
pid_info.D*0.01f);
|
|
|
|
if (!HAVE_PAYLOAD_SPACE(chan, PID_TUNING)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (g.gcs_pid_mask & 2) {
|
2019-01-18 00:23:42 -04:00
|
|
|
const AP_Logger::PID_Info &pid_info = attitude_control.get_rate_pitch_pid().get_pid_info();
|
2017-02-03 17:33:27 -04:00
|
|
|
mavlink_msg_pid_tuning_send(chan, PID_TUNING_PITCH,
|
2019-06-27 06:31:52 -03:00
|
|
|
pid_info.target*0.01f,
|
2015-12-30 18:57:56 -04:00
|
|
|
degrees(gyro.y),
|
|
|
|
pid_info.FF*0.01f,
|
|
|
|
pid_info.P*0.01f,
|
|
|
|
pid_info.I*0.01f,
|
|
|
|
pid_info.D*0.01f);
|
|
|
|
if (!HAVE_PAYLOAD_SPACE(chan, PID_TUNING)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (g.gcs_pid_mask & 4) {
|
2019-01-18 00:23:42 -04:00
|
|
|
const AP_Logger::PID_Info &pid_info = attitude_control.get_rate_yaw_pid().get_pid_info();
|
2017-02-03 17:33:27 -04:00
|
|
|
mavlink_msg_pid_tuning_send(chan, PID_TUNING_YAW,
|
2019-06-27 06:31:52 -03:00
|
|
|
pid_info.target*0.01f,
|
2015-12-30 18:57:56 -04:00
|
|
|
degrees(gyro.z),
|
|
|
|
pid_info.FF*0.01f,
|
|
|
|
pid_info.P*0.01f,
|
|
|
|
pid_info.I*0.01f,
|
|
|
|
pid_info.D*0.01f);
|
|
|
|
if (!HAVE_PAYLOAD_SPACE(chan, PID_TUNING)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (g.gcs_pid_mask & 8) {
|
2019-02-28 19:33:10 -04:00
|
|
|
const AP_Logger::PID_Info &pid_info = sub.pos_control.get_accel_z_pid().get_pid_info();
|
2017-02-03 17:33:27 -04:00
|
|
|
mavlink_msg_pid_tuning_send(chan, PID_TUNING_ACCZ,
|
2019-06-27 06:31:52 -03:00
|
|
|
pid_info.target*0.01f,
|
2015-12-30 18:57:56 -04:00
|
|
|
-(ahrs.get_accel_ef_blended().z + GRAVITY_MSS),
|
|
|
|
pid_info.FF*0.01f,
|
|
|
|
pid_info.P*0.01f,
|
|
|
|
pid_info.I*0.01f,
|
|
|
|
pid_info.D*0.01f);
|
|
|
|
if (!HAVE_PAYLOAD_SPACE(chan, PID_TUNING)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-12 04:51:23 -03:00
|
|
|
uint8_t GCS_MAVLINK_Sub::sysid_my_gcs() const
|
|
|
|
{
|
|
|
|
return sub.g.sysid_my_gcs;
|
|
|
|
}
|
|
|
|
|
2019-03-01 07:50:31 -04:00
|
|
|
bool GCS_Sub::vehicle_initialised() const {
|
2018-12-17 22:09:01 -04:00
|
|
|
return sub.ap.initialised;
|
|
|
|
}
|
|
|
|
|
2015-12-30 18:57:56 -04:00
|
|
|
// try to send a message, return false if it won't fit in the serial tx buffer
|
2017-02-03 00:18:27 -04:00
|
|
|
bool GCS_MAVLINK_Sub::try_send_message(enum ap_message id)
|
2015-12-30 18:57:56 -04:00
|
|
|
{
|
2017-02-03 17:33:27 -04:00
|
|
|
switch (id) {
|
2017-05-08 20:37:42 -03:00
|
|
|
|
|
|
|
case MSG_NAMED_FLOAT:
|
2018-05-16 03:49:23 -03:00
|
|
|
send_info();
|
2017-05-08 20:37:42 -03:00
|
|
|
break;
|
|
|
|
|
2015-12-30 18:57:56 -04:00
|
|
|
case MSG_TERRAIN:
|
|
|
|
#if AP_TERRAIN_AVAILABLE && AC_TERRAIN
|
|
|
|
CHECK_PAYLOAD_SIZE(TERRAIN_REQUEST);
|
2016-01-14 15:30:56 -04:00
|
|
|
sub.terrain.send_request(chan);
|
2015-12-30 18:57:56 -04:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
2017-07-17 22:21:35 -03:00
|
|
|
default:
|
|
|
|
return GCS_MAVLINK::try_send_message(id);
|
2015-12-30 18:57:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-19 07:32:27 -03:00
|
|
|
const AP_Param::GroupInfo GCS_MAVLINK_Parameters::var_info[] = {
|
2015-12-30 18:57:56 -04:00
|
|
|
// @Param: RAW_SENS
|
|
|
|
// @DisplayName: Raw sensor stream rate
|
|
|
|
// @Description: Stream rate of RAW_IMU, SCALED_IMU2, SCALED_PRESSURE, and SENSOR_OFFSETS to ground station
|
|
|
|
// @Units: Hz
|
2021-02-19 11:32:55 -04:00
|
|
|
// @Range: 0 50
|
2015-12-30 18:57:56 -04:00
|
|
|
// @Increment: 1
|
|
|
|
// @User: Advanced
|
2019-06-19 07:32:27 -03:00
|
|
|
AP_GROUPINFO("RAW_SENS", 0, GCS_MAVLINK_Parameters, streamRates[GCS_MAVLINK::STREAM_RAW_SENSORS], 0),
|
2015-12-30 18:57:56 -04:00
|
|
|
|
|
|
|
// @Param: EXT_STAT
|
|
|
|
// @DisplayName: Extended status stream rate to ground station
|
|
|
|
// @Description: Stream rate of SYS_STATUS, MEMINFO, MISSION_CURRENT, GPS_RAW_INT, NAV_CONTROLLER_OUTPUT, and LIMITS_STATUS to ground station
|
|
|
|
// @Units: Hz
|
2021-02-19 11:32:55 -04:00
|
|
|
// @Range: 0 50
|
2015-12-30 18:57:56 -04:00
|
|
|
// @Increment: 1
|
|
|
|
// @User: Advanced
|
2019-06-19 07:32:27 -03:00
|
|
|
AP_GROUPINFO("EXT_STAT", 1, GCS_MAVLINK_Parameters, streamRates[GCS_MAVLINK::STREAM_EXTENDED_STATUS], 0),
|
2015-12-30 18:57:56 -04:00
|
|
|
|
|
|
|
// @Param: RC_CHAN
|
|
|
|
// @DisplayName: RC Channel stream rate to ground station
|
|
|
|
// @Description: Stream rate of SERVO_OUTPUT_RAW and RC_CHANNELS_RAW to ground station
|
|
|
|
// @Units: Hz
|
2021-02-19 11:32:55 -04:00
|
|
|
// @Range: 0 50
|
2015-12-30 18:57:56 -04:00
|
|
|
// @Increment: 1
|
|
|
|
// @User: Advanced
|
2019-06-19 07:32:27 -03:00
|
|
|
AP_GROUPINFO("RC_CHAN", 2, GCS_MAVLINK_Parameters, streamRates[GCS_MAVLINK::STREAM_RC_CHANNELS], 0),
|
2015-12-30 18:57:56 -04:00
|
|
|
|
|
|
|
// @Param: POSITION
|
|
|
|
// @DisplayName: Position stream rate to ground station
|
|
|
|
// @Description: Stream rate of GLOBAL_POSITION_INT to ground station
|
|
|
|
// @Units: Hz
|
2021-02-19 11:32:55 -04:00
|
|
|
// @Range: 0 50
|
2015-12-30 18:57:56 -04:00
|
|
|
// @Increment: 1
|
|
|
|
// @User: Advanced
|
2019-06-19 07:32:27 -03:00
|
|
|
AP_GROUPINFO("POSITION", 4, GCS_MAVLINK_Parameters, streamRates[GCS_MAVLINK::STREAM_POSITION], 0),
|
2015-12-30 18:57:56 -04:00
|
|
|
|
|
|
|
// @Param: EXTRA1
|
|
|
|
// @DisplayName: Extra data type 1 stream rate to ground station
|
|
|
|
// @Description: Stream rate of ATTITUDE and SIMSTATE (SITL only) to ground station
|
|
|
|
// @Units: Hz
|
2021-02-19 11:32:55 -04:00
|
|
|
// @Range: 0 50
|
2015-12-30 18:57:56 -04:00
|
|
|
// @Increment: 1
|
|
|
|
// @User: Advanced
|
2019-06-19 07:32:27 -03:00
|
|
|
AP_GROUPINFO("EXTRA1", 5, GCS_MAVLINK_Parameters, streamRates[GCS_MAVLINK::STREAM_EXTRA1], 0),
|
2015-12-30 18:57:56 -04:00
|
|
|
|
|
|
|
// @Param: EXTRA2
|
|
|
|
// @DisplayName: Extra data type 2 stream rate to ground station
|
|
|
|
// @Description: Stream rate of VFR_HUD to ground station
|
|
|
|
// @Units: Hz
|
2021-02-19 11:32:55 -04:00
|
|
|
// @Range: 0 50
|
2015-12-30 18:57:56 -04:00
|
|
|
// @Increment: 1
|
|
|
|
// @User: Advanced
|
2019-06-19 07:32:27 -03:00
|
|
|
AP_GROUPINFO("EXTRA2", 6, GCS_MAVLINK_Parameters, streamRates[GCS_MAVLINK::STREAM_EXTRA2], 0),
|
2015-12-30 18:57:56 -04:00
|
|
|
|
|
|
|
// @Param: EXTRA3
|
|
|
|
// @DisplayName: Extra data type 3 stream rate to ground station
|
|
|
|
// @Description: Stream rate of AHRS, HWSTATUS, and SYSTEM_TIME to ground station
|
|
|
|
// @Units: Hz
|
2021-02-19 11:32:55 -04:00
|
|
|
// @Range: 0 50
|
2015-12-30 18:57:56 -04:00
|
|
|
// @Increment: 1
|
|
|
|
// @User: Advanced
|
2019-06-19 07:32:27 -03:00
|
|
|
AP_GROUPINFO("EXTRA3", 7, GCS_MAVLINK_Parameters, streamRates[GCS_MAVLINK::STREAM_EXTRA3], 0),
|
2015-12-30 18:57:56 -04:00
|
|
|
|
|
|
|
// @Param: PARAMS
|
|
|
|
// @DisplayName: Parameter stream rate to ground station
|
|
|
|
// @Description: Stream rate of PARAM_VALUE to ground station
|
|
|
|
// @Units: Hz
|
2021-02-19 11:32:55 -04:00
|
|
|
// @Range: 0 50
|
2015-12-30 18:57:56 -04:00
|
|
|
// @Increment: 1
|
|
|
|
// @User: Advanced
|
2019-06-19 07:32:27 -03:00
|
|
|
AP_GROUPINFO("PARAMS", 8, GCS_MAVLINK_Parameters, streamRates[GCS_MAVLINK::STREAM_PARAMS], 0),
|
2017-02-03 17:33:27 -04:00
|
|
|
AP_GROUPEND
|
2015-12-30 18:57:56 -04:00
|
|
|
};
|
|
|
|
|
2018-05-21 01:07:03 -03:00
|
|
|
static const ap_message STREAM_RAW_SENSORS_msgs[] = {
|
2018-12-06 18:00:35 -04:00
|
|
|
MSG_RAW_IMU,
|
|
|
|
MSG_SCALED_IMU2,
|
|
|
|
MSG_SCALED_IMU3,
|
2018-12-07 02:29:45 -04:00
|
|
|
MSG_SCALED_PRESSURE,
|
|
|
|
MSG_SCALED_PRESSURE2,
|
|
|
|
MSG_SCALED_PRESSURE3,
|
2018-12-04 01:54:27 -04:00
|
|
|
MSG_SENSOR_OFFSETS
|
2017-08-21 03:08:52 -03:00
|
|
|
};
|
2018-05-21 01:07:03 -03:00
|
|
|
static const ap_message STREAM_EXTENDED_STATUS_msgs[] = {
|
2018-12-17 22:09:01 -04:00
|
|
|
MSG_SYS_STATUS,
|
|
|
|
MSG_POWER_STATUS,
|
2018-12-04 01:18:44 -04:00
|
|
|
MSG_MEMINFO,
|
2017-08-21 03:08:52 -03:00
|
|
|
MSG_CURRENT_WAYPOINT,
|
|
|
|
MSG_GPS_RAW,
|
|
|
|
MSG_GPS_RTK,
|
|
|
|
MSG_GPS2_RAW,
|
|
|
|
MSG_GPS2_RTK,
|
|
|
|
MSG_NAV_CONTROLLER_OUTPUT,
|
2018-05-21 05:15:54 -03:00
|
|
|
MSG_FENCE_STATUS,
|
2017-08-21 03:08:52 -03:00
|
|
|
MSG_NAMED_FLOAT
|
|
|
|
};
|
2018-05-21 01:07:03 -03:00
|
|
|
static const ap_message STREAM_POSITION_msgs[] = {
|
2017-08-21 03:08:52 -03:00
|
|
|
MSG_LOCATION,
|
|
|
|
MSG_LOCAL_POSITION
|
|
|
|
};
|
2018-05-21 01:07:03 -03:00
|
|
|
static const ap_message STREAM_RC_CHANNELS_msgs[] = {
|
2017-08-21 03:08:52 -03:00
|
|
|
MSG_SERVO_OUTPUT_RAW,
|
2019-07-06 20:02:45 -03:00
|
|
|
MSG_RC_CHANNELS,
|
|
|
|
MSG_RC_CHANNELS_RAW, // only sent on a mavlink1 connection
|
2017-08-21 03:08:52 -03:00
|
|
|
};
|
2018-05-21 01:07:03 -03:00
|
|
|
static const ap_message STREAM_EXTRA1_msgs[] = {
|
2017-08-21 03:08:52 -03:00
|
|
|
MSG_ATTITUDE,
|
2018-12-18 16:23:25 -04:00
|
|
|
MSG_SIMSTATE,
|
|
|
|
MSG_AHRS2,
|
2017-08-21 03:08:52 -03:00
|
|
|
MSG_PID_TUNING
|
|
|
|
};
|
2018-05-21 01:07:03 -03:00
|
|
|
static const ap_message STREAM_EXTRA2_msgs[] = {
|
2017-08-21 03:08:52 -03:00
|
|
|
MSG_VFR_HUD
|
|
|
|
};
|
2018-05-21 01:07:03 -03:00
|
|
|
static const ap_message STREAM_EXTRA3_msgs[] = {
|
2017-08-21 03:08:52 -03:00
|
|
|
MSG_AHRS,
|
|
|
|
MSG_HWSTATUS,
|
|
|
|
MSG_SYSTEM_TIME,
|
|
|
|
MSG_RANGEFINDER,
|
2018-12-18 06:47:39 -04:00
|
|
|
MSG_DISTANCE_SENSOR,
|
2015-12-30 18:57:56 -04:00
|
|
|
#if AP_TERRAIN_AVAILABLE && AC_TERRAIN
|
2017-08-21 03:08:52 -03:00
|
|
|
MSG_TERRAIN,
|
2015-12-30 18:57:56 -04:00
|
|
|
#endif
|
2017-08-21 03:08:52 -03:00
|
|
|
MSG_BATTERY2,
|
|
|
|
MSG_BATTERY_STATUS,
|
|
|
|
MSG_MOUNT_STATUS,
|
|
|
|
MSG_OPTICAL_FLOW,
|
|
|
|
MSG_GIMBAL_REPORT,
|
|
|
|
MSG_MAG_CAL_REPORT,
|
|
|
|
MSG_MAG_CAL_PROGRESS,
|
|
|
|
MSG_EKF_STATUS_REPORT,
|
|
|
|
MSG_VIBRATION,
|
2016-11-25 18:58:31 -04:00
|
|
|
#if RPM_ENABLED == ENABLED
|
2018-06-20 20:51:06 -03:00
|
|
|
MSG_RPM,
|
2016-11-25 18:58:31 -04:00
|
|
|
#endif
|
2018-06-20 20:51:06 -03:00
|
|
|
MSG_ESC_TELEMETRY,
|
2017-08-21 03:08:52 -03:00
|
|
|
};
|
2018-05-22 22:23:49 -03:00
|
|
|
static const ap_message STREAM_PARAMS_msgs[] = {
|
|
|
|
MSG_NEXT_PARAM
|
|
|
|
};
|
2015-12-30 18:57:56 -04:00
|
|
|
|
2017-08-21 03:08:52 -03:00
|
|
|
const struct GCS_MAVLINK::stream_entries GCS_MAVLINK::all_stream_entries[] = {
|
|
|
|
MAV_STREAM_ENTRY(STREAM_RAW_SENSORS),
|
|
|
|
MAV_STREAM_ENTRY(STREAM_EXTENDED_STATUS),
|
|
|
|
MAV_STREAM_ENTRY(STREAM_POSITION),
|
|
|
|
MAV_STREAM_ENTRY(STREAM_RC_CHANNELS),
|
|
|
|
MAV_STREAM_ENTRY(STREAM_EXTRA1),
|
|
|
|
MAV_STREAM_ENTRY(STREAM_EXTRA2),
|
|
|
|
MAV_STREAM_ENTRY(STREAM_EXTRA3),
|
2018-05-22 22:23:49 -03:00
|
|
|
MAV_STREAM_ENTRY(STREAM_PARAMS),
|
2017-08-21 03:08:52 -03:00
|
|
|
MAV_STREAM_TERMINATOR // must have this at end of stream_entries
|
|
|
|
};
|
2015-12-30 18:57:56 -04:00
|
|
|
|
2017-02-03 00:18:27 -04:00
|
|
|
bool GCS_MAVLINK_Sub::handle_guided_request(AP_Mission::Mission_Command &cmd)
|
2015-12-30 18:57:56 -04:00
|
|
|
{
|
2016-05-03 01:45:37 -03:00
|
|
|
return sub.do_guided(cmd);
|
2015-12-30 18:57:56 -04:00
|
|
|
}
|
|
|
|
|
2017-02-03 00:18:27 -04:00
|
|
|
void GCS_MAVLINK_Sub::handle_change_alt_request(AP_Mission::Mission_Command &cmd)
|
2015-12-30 18:57:56 -04:00
|
|
|
{
|
|
|
|
// add home alt if needed
|
2019-01-01 22:19:12 -04:00
|
|
|
if (cmd.content.location.relative_alt) {
|
2016-01-14 15:30:56 -04:00
|
|
|
cmd.content.location.alt += sub.ahrs.get_home().alt;
|
2015-12-30 18:57:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// To-Do: update target altitude for loiter or waypoint controller depending upon nav mode
|
|
|
|
}
|
|
|
|
|
2018-03-18 01:18:59 -03:00
|
|
|
MAV_RESULT GCS_MAVLINK_Sub::_handle_command_preflight_calibration_baro()
|
2018-03-17 08:35:01 -03:00
|
|
|
{
|
2018-04-22 12:37:03 -03:00
|
|
|
if (sub.motors.armed()) {
|
|
|
|
gcs().send_text(MAV_SEVERITY_INFO, "Disarm before calibration.");
|
|
|
|
return MAV_RESULT_FAILED;
|
|
|
|
}
|
|
|
|
|
2018-04-22 12:27:22 -03:00
|
|
|
if (!sub.control_check_barometer()) {
|
2018-03-18 01:18:59 -03:00
|
|
|
return MAV_RESULT_FAILED;
|
2018-03-17 08:35:01 -03:00
|
|
|
}
|
|
|
|
|
2018-03-18 01:18:59 -03:00
|
|
|
AP::baro().calibrate(true);
|
|
|
|
return MAV_RESULT_ACCEPTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
MAV_RESULT GCS_MAVLINK_Sub::_handle_command_preflight_calibration(const mavlink_command_long_t &packet)
|
|
|
|
{
|
2018-03-17 08:35:01 -03:00
|
|
|
if (is_equal(packet.param6,1.0f)) {
|
|
|
|
// compassmot calibration
|
|
|
|
//result = sub.mavlink_compassmot(chan);
|
|
|
|
gcs().send_text(MAV_SEVERITY_INFO, "#CompassMot calibration not supported");
|
|
|
|
return MAV_RESULT_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GCS_MAVLINK::_handle_command_preflight_calibration(packet);
|
|
|
|
}
|
|
|
|
|
2018-08-26 08:57:07 -03:00
|
|
|
MAV_RESULT GCS_MAVLINK_Sub::handle_command_do_set_roi(const Location &roi_loc)
|
|
|
|
{
|
2019-04-08 10:51:25 -03:00
|
|
|
if (!roi_loc.check_latlng()) {
|
2018-08-26 08:57:07 -03:00
|
|
|
return MAV_RESULT_FAILED;
|
|
|
|
}
|
|
|
|
sub.set_auto_yaw_roi(roi_loc);
|
|
|
|
return MAV_RESULT_ACCEPTED;
|
|
|
|
}
|
|
|
|
|
2019-09-12 06:51:25 -03:00
|
|
|
bool GCS_MAVLINK_Sub::set_home_to_current_location(bool _lock) {
|
|
|
|
return sub.set_home_to_current_location(_lock);
|
2018-07-06 00:30:54 -03:00
|
|
|
}
|
2019-09-12 06:51:25 -03:00
|
|
|
bool GCS_MAVLINK_Sub::set_home(const Location& loc, bool _lock) {
|
|
|
|
return sub.set_home(loc, _lock);
|
2018-07-03 23:45:30 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-03 23:53:57 -03:00
|
|
|
MAV_RESULT GCS_MAVLINK_Sub::handle_command_long_packet(const mavlink_command_long_t &packet)
|
2015-12-30 18:57:56 -04:00
|
|
|
{
|
2018-07-03 23:53:57 -03:00
|
|
|
switch (packet.command) {
|
|
|
|
case MAV_CMD_NAV_LOITER_UNLIM:
|
2019-10-17 00:50:07 -03:00
|
|
|
if (!sub.set_mode(POSHOLD, ModeReason::GCS_COMMAND)) {
|
2018-07-03 23:53:57 -03:00
|
|
|
return MAV_RESULT_FAILED;
|
|
|
|
}
|
|
|
|
return MAV_RESULT_ACCEPTED;
|
|
|
|
|
|
|
|
case MAV_CMD_NAV_LAND:
|
2019-10-17 00:50:07 -03:00
|
|
|
if (!sub.set_mode(SURFACE, ModeReason::GCS_COMMAND)) {
|
2018-07-03 23:53:57 -03:00
|
|
|
return MAV_RESULT_FAILED;
|
|
|
|
}
|
|
|
|
return MAV_RESULT_ACCEPTED;
|
|
|
|
|
|
|
|
case MAV_CMD_CONDITION_YAW:
|
|
|
|
// param1 : target angle [0-360]
|
|
|
|
// param2 : speed during change [deg per second]
|
|
|
|
// param3 : direction (-1:ccw, +1:cw)
|
|
|
|
// param4 : relative offset (1) or absolute angle (0)
|
|
|
|
if ((packet.param1 >= 0.0f) &&
|
|
|
|
(packet.param1 <= 360.0f) &&
|
|
|
|
(is_zero(packet.param4) || is_equal(packet.param4,1.0f))) {
|
|
|
|
sub.set_auto_yaw_look_at_heading(packet.param1, packet.param2, (int8_t)packet.param3, (uint8_t)packet.param4);
|
|
|
|
return MAV_RESULT_ACCEPTED;
|
|
|
|
}
|
|
|
|
return MAV_RESULT_FAILED;
|
|
|
|
|
|
|
|
case MAV_CMD_DO_CHANGE_SPEED:
|
|
|
|
// param1 : unused
|
|
|
|
// param2 : new speed in m/s
|
|
|
|
// param3 : unused
|
|
|
|
// param4 : unused
|
|
|
|
if (packet.param2 > 0.0f) {
|
|
|
|
sub.wp_nav.set_speed_xy(packet.param2 * 100.0f);
|
|
|
|
return MAV_RESULT_ACCEPTED;
|
|
|
|
}
|
|
|
|
return MAV_RESULT_FAILED;
|
|
|
|
|
|
|
|
case MAV_CMD_MISSION_START:
|
2019-10-17 00:50:07 -03:00
|
|
|
if (sub.motors.armed() && sub.set_mode(AUTO, ModeReason::GCS_COMMAND)) {
|
2018-07-03 23:53:57 -03:00
|
|
|
return MAV_RESULT_ACCEPTED;
|
|
|
|
}
|
|
|
|
return MAV_RESULT_FAILED;
|
2015-12-30 18:57:56 -04:00
|
|
|
|
2018-07-03 23:53:57 -03:00
|
|
|
case MAV_CMD_DO_MOTOR_TEST:
|
|
|
|
// param1 : motor sequence number (a number from 1 to max number of motors on the vehicle)
|
|
|
|
// param2 : throttle type (0=throttle percentage, 1=PWM, 2=pilot throttle channel pass-through. See MOTOR_TEST_THROTTLE_TYPE enum)
|
|
|
|
// param3 : throttle (range depends upon param2)
|
|
|
|
// param4 : timeout (in seconds)
|
|
|
|
if (!sub.handle_do_motor_test(packet)) {
|
|
|
|
return MAV_RESULT_FAILED;
|
|
|
|
}
|
|
|
|
return MAV_RESULT_ACCEPTED;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return GCS_MAVLINK::handle_command_long_packet(packet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-30 07:22:51 -03:00
|
|
|
void GCS_MAVLINK_Sub::handleMessage(const mavlink_message_t &msg)
|
2018-07-03 23:53:57 -03:00
|
|
|
{
|
2019-04-30 07:22:51 -03:00
|
|
|
switch (msg.msgid) {
|
2015-12-30 18:57:56 -04:00
|
|
|
|
2017-02-03 17:33:27 -04:00
|
|
|
case MAVLINK_MSG_ID_MANUAL_CONTROL: { // MAV ID: 69
|
2019-04-30 07:22:51 -03:00
|
|
|
if (msg.sysid != sub.g.sysid_my_gcs) {
|
2017-02-03 17:33:27 -04:00
|
|
|
break; // Only accept control from our gcs
|
|
|
|
}
|
|
|
|
mavlink_manual_control_t packet;
|
2019-04-30 07:22:51 -03:00
|
|
|
mavlink_msg_manual_control_decode(&msg, &packet);
|
2016-01-10 20:23:03 -04:00
|
|
|
|
2018-04-03 20:20:40 -03:00
|
|
|
if (packet.target != sub.g.sysid_this_mav) {
|
|
|
|
break; // only accept control aimed at us
|
|
|
|
}
|
|
|
|
|
2017-02-03 17:33:27 -04:00
|
|
|
sub.transform_manual_control_to_rc_override(packet.x,packet.y,packet.z,packet.r,packet.buttons);
|
2016-01-10 20:23:03 -04:00
|
|
|
|
2017-04-14 16:58:54 -03:00
|
|
|
sub.failsafe.last_pilot_input_ms = AP_HAL::millis();
|
2021-02-04 22:28:08 -04:00
|
|
|
// a RC override message is considered to be a 'heartbeat'
|
|
|
|
// from the ground station for failsafe purposes
|
|
|
|
gcs().sysid_myggcs_seen(AP_HAL::millis());
|
2017-02-03 17:33:27 -04:00
|
|
|
break;
|
|
|
|
}
|
2016-01-10 15:32:45 -04:00
|
|
|
|
2019-02-03 17:46:58 -04:00
|
|
|
|
2017-02-03 17:33:27 -04:00
|
|
|
case MAVLINK_MSG_ID_SET_ATTITUDE_TARGET: { // MAV ID: 82
|
2015-12-30 18:57:56 -04:00
|
|
|
// decode packet
|
|
|
|
mavlink_set_attitude_target_t packet;
|
2019-04-30 07:22:51 -03:00
|
|
|
mavlink_msg_set_attitude_target_decode(&msg, &packet);
|
2015-12-30 18:57:56 -04:00
|
|
|
|
2018-04-14 00:15:15 -03:00
|
|
|
// ensure type_mask specifies to use attitude
|
|
|
|
// the thrust can be used from the altitude hold
|
|
|
|
if (packet.type_mask & (1<<6)) {
|
|
|
|
sub.set_attitude_target_no_gps = {AP_HAL::millis(), packet};
|
|
|
|
}
|
|
|
|
|
2015-12-30 18:57:56 -04:00
|
|
|
// ensure type_mask specifies to use attitude and thrust
|
|
|
|
if ((packet.type_mask & ((1<<7)|(1<<6))) != 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// convert thrust to climb rate
|
|
|
|
packet.thrust = constrain_float(packet.thrust, 0.0f, 1.0f);
|
|
|
|
float climb_rate_cms = 0.0f;
|
|
|
|
if (is_equal(packet.thrust, 0.5f)) {
|
|
|
|
climb_rate_cms = 0.0f;
|
|
|
|
} else if (packet.thrust > 0.5f) {
|
|
|
|
// climb at up to WPNAV_SPEED_UP
|
2019-01-24 01:04:22 -04:00
|
|
|
climb_rate_cms = (packet.thrust - 0.5f) * 2.0f * sub.wp_nav.get_default_speed_up();
|
2015-12-30 18:57:56 -04:00
|
|
|
} else {
|
|
|
|
// descend at up to WPNAV_SPEED_DN
|
2019-01-24 01:04:22 -04:00
|
|
|
climb_rate_cms = (packet.thrust - 0.5f) * 2.0f * fabsf(sub.wp_nav.get_default_speed_down());
|
2015-12-30 18:57:56 -04:00
|
|
|
}
|
2016-01-14 15:30:56 -04:00
|
|
|
sub.guided_set_angle(Quaternion(packet.q[0],packet.q[1],packet.q[2],packet.q[3]), climb_rate_cms);
|
2015-12-30 18:57:56 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-02-03 17:33:27 -04:00
|
|
|
case MAVLINK_MSG_ID_SET_POSITION_TARGET_LOCAL_NED: { // MAV ID: 84
|
2015-12-30 18:57:56 -04:00
|
|
|
// decode packet
|
|
|
|
mavlink_set_position_target_local_ned_t packet;
|
2019-04-30 07:22:51 -03:00
|
|
|
mavlink_msg_set_position_target_local_ned_decode(&msg, &packet);
|
2015-12-30 18:57:56 -04:00
|
|
|
|
|
|
|
// exit if vehicle is not in Guided mode or Auto-Guided mode
|
2016-01-14 15:30:56 -04:00
|
|
|
if ((sub.control_mode != GUIDED) && !(sub.control_mode == AUTO && sub.auto_mode == Auto_NavGuided)) {
|
2015-12-30 18:57:56 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for supported coordinate frames
|
|
|
|
if (packet.coordinate_frame != MAV_FRAME_LOCAL_NED &&
|
2017-02-03 17:33:27 -04:00
|
|
|
packet.coordinate_frame != MAV_FRAME_LOCAL_OFFSET_NED &&
|
|
|
|
packet.coordinate_frame != MAV_FRAME_BODY_NED &&
|
|
|
|
packet.coordinate_frame != MAV_FRAME_BODY_OFFSET_NED) {
|
2015-12-30 18:57:56 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool pos_ignore = packet.type_mask & MAVLINK_SET_POS_TYPE_MASK_POS_IGNORE;
|
|
|
|
bool vel_ignore = packet.type_mask & MAVLINK_SET_POS_TYPE_MASK_VEL_IGNORE;
|
|
|
|
bool acc_ignore = packet.type_mask & MAVLINK_SET_POS_TYPE_MASK_ACC_IGNORE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* for future use:
|
|
|
|
* bool force = packet.type_mask & MAVLINK_SET_POS_TYPE_MASK_FORCE;
|
|
|
|
* bool yaw_ignore = packet.type_mask & MAVLINK_SET_POS_TYPE_MASK_YAW_IGNORE;
|
|
|
|
* bool yaw_rate_ignore = packet.type_mask & MAVLINK_SET_POS_TYPE_MASK_YAW_RATE_IGNORE;
|
|
|
|
*/
|
|
|
|
|
|
|
|
// prepare position
|
|
|
|
Vector3f pos_vector;
|
|
|
|
if (!pos_ignore) {
|
|
|
|
// convert to cm
|
|
|
|
pos_vector = Vector3f(packet.x * 100.0f, packet.y * 100.0f, -packet.z * 100.0f);
|
|
|
|
// rotate to body-frame if necessary
|
|
|
|
if (packet.coordinate_frame == MAV_FRAME_BODY_NED ||
|
2017-02-03 17:33:27 -04:00
|
|
|
packet.coordinate_frame == MAV_FRAME_BODY_OFFSET_NED) {
|
2016-01-14 15:30:56 -04:00
|
|
|
sub.rotate_body_frame_to_NE(pos_vector.x, pos_vector.y);
|
2015-12-30 18:57:56 -04:00
|
|
|
}
|
|
|
|
// add body offset if necessary
|
|
|
|
if (packet.coordinate_frame == MAV_FRAME_LOCAL_OFFSET_NED ||
|
2017-02-03 17:33:27 -04:00
|
|
|
packet.coordinate_frame == MAV_FRAME_BODY_NED ||
|
|
|
|
packet.coordinate_frame == MAV_FRAME_BODY_OFFSET_NED) {
|
2016-01-14 15:30:56 -04:00
|
|
|
pos_vector += sub.inertial_nav.get_position();
|
2015-12-30 18:57:56 -04:00
|
|
|
} else {
|
|
|
|
// convert from alt-above-home to alt-above-ekf-origin
|
2016-01-14 15:30:56 -04:00
|
|
|
pos_vector.z = sub.pv_alt_above_origin(pos_vector.z);
|
2015-12-30 18:57:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// prepare velocity
|
|
|
|
Vector3f vel_vector;
|
|
|
|
if (!vel_ignore) {
|
|
|
|
// convert to cm
|
|
|
|
vel_vector = Vector3f(packet.vx * 100.0f, packet.vy * 100.0f, -packet.vz * 100.0f);
|
|
|
|
// rotate to body-frame if necessary
|
|
|
|
if (packet.coordinate_frame == MAV_FRAME_BODY_NED || packet.coordinate_frame == MAV_FRAME_BODY_OFFSET_NED) {
|
2016-01-14 15:30:56 -04:00
|
|
|
sub.rotate_body_frame_to_NE(vel_vector.x, vel_vector.y);
|
2015-12-30 18:57:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// send request
|
|
|
|
if (!pos_ignore && !vel_ignore && acc_ignore) {
|
2018-07-03 23:53:57 -03:00
|
|
|
sub.guided_set_destination_posvel(pos_vector, vel_vector);
|
2015-12-30 18:57:56 -04:00
|
|
|
} else if (pos_ignore && !vel_ignore && acc_ignore) {
|
2016-01-14 15:30:56 -04:00
|
|
|
sub.guided_set_velocity(vel_vector);
|
2015-12-30 18:57:56 -04:00
|
|
|
} else if (!pos_ignore && vel_ignore && acc_ignore) {
|
2018-07-03 23:53:57 -03:00
|
|
|
sub.guided_set_destination(pos_vector);
|
2015-12-30 18:57:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-02-03 17:33:27 -04:00
|
|
|
case MAVLINK_MSG_ID_SET_POSITION_TARGET_GLOBAL_INT: { // MAV ID: 86
|
2015-12-30 18:57:56 -04:00
|
|
|
// decode packet
|
|
|
|
mavlink_set_position_target_global_int_t packet;
|
2019-04-30 07:22:51 -03:00
|
|
|
mavlink_msg_set_position_target_global_int_decode(&msg, &packet);
|
2015-12-30 18:57:56 -04:00
|
|
|
|
2019-08-07 13:02:23 -03:00
|
|
|
// exit if vehicle is not in Guided, Auto-Guided, or Depth Hold modes
|
|
|
|
if ((sub.control_mode != GUIDED)
|
|
|
|
&& !(sub.control_mode == AUTO && sub.auto_mode == Auto_NavGuided)
|
|
|
|
&& !(sub.control_mode == ALT_HOLD)) {
|
2015-12-30 18:57:56 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool pos_ignore = packet.type_mask & MAVLINK_SET_POS_TYPE_MASK_POS_IGNORE;
|
|
|
|
bool vel_ignore = packet.type_mask & MAVLINK_SET_POS_TYPE_MASK_VEL_IGNORE;
|
|
|
|
bool acc_ignore = packet.type_mask & MAVLINK_SET_POS_TYPE_MASK_ACC_IGNORE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* for future use:
|
|
|
|
* bool force = packet.type_mask & MAVLINK_SET_POS_TYPE_MASK_FORCE;
|
|
|
|
* bool yaw_ignore = packet.type_mask & MAVLINK_SET_POS_TYPE_MASK_YAW_IGNORE;
|
|
|
|
* bool yaw_rate_ignore = packet.type_mask & MAVLINK_SET_POS_TYPE_MASK_YAW_RATE_IGNORE;
|
|
|
|
*/
|
|
|
|
|
2019-08-07 13:02:23 -03:00
|
|
|
if (!pos_ignore && sub.control_mode == ALT_HOLD) { // Control only target depth when in ALT_HOLD
|
2021-04-27 03:50:06 -03:00
|
|
|
sub.pos_control.set_pos_target_z_cm(packet.alt*100);
|
2019-08-07 13:02:23 -03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-12-03 13:12:38 -04:00
|
|
|
Vector3f pos_neu_cm; // position (North, East, Up coordinates) in centimeters
|
2015-12-30 18:57:56 -04:00
|
|
|
|
2017-02-03 17:33:27 -04:00
|
|
|
if (!pos_ignore) {
|
|
|
|
// sanity check location
|
2017-02-03 00:18:27 -04:00
|
|
|
if (!check_latlng(packet.lat_int, packet.lon_int)) {
|
|
|
|
break;
|
|
|
|
}
|
2019-03-14 22:44:59 -03:00
|
|
|
Location::AltFrame frame;
|
2019-07-31 22:02:54 -03:00
|
|
|
if (!mavlink_coordinate_frame_to_location_alt_frame((MAV_FRAME)packet.coordinate_frame, frame)) {
|
2019-02-11 23:42:36 -04:00
|
|
|
// unknown coordinate frame
|
2017-02-03 17:33:27 -04:00
|
|
|
break;
|
2019-02-11 23:42:36 -04:00
|
|
|
}
|
|
|
|
const Location loc{
|
|
|
|
packet.lat_int,
|
|
|
|
packet.lon_int,
|
|
|
|
int32_t(packet.alt*100),
|
|
|
|
frame,
|
|
|
|
};
|
|
|
|
if (!loc.get_vector_from_origin_NEU(pos_neu_cm)) {
|
2017-02-03 17:33:27 -04:00
|
|
|
break;
|
2015-12-30 18:57:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pos_ignore && !vel_ignore && acc_ignore) {
|
2018-07-03 23:53:57 -03:00
|
|
|
sub.guided_set_destination_posvel(pos_neu_cm, Vector3f(packet.vx * 100.0f, packet.vy * 100.0f, -packet.vz * 100.0f));
|
2015-12-30 18:57:56 -04:00
|
|
|
} else if (pos_ignore && !vel_ignore && acc_ignore) {
|
2016-01-14 15:30:56 -04:00
|
|
|
sub.guided_set_velocity(Vector3f(packet.vx * 100.0f, packet.vy * 100.0f, -packet.vz * 100.0f));
|
2015-12-30 18:57:56 -04:00
|
|
|
} else if (!pos_ignore && vel_ignore && acc_ignore) {
|
2018-07-03 23:53:57 -03:00
|
|
|
sub.guided_set_destination(pos_neu_cm);
|
2015-12-30 18:57:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case MAVLINK_MSG_ID_TERRAIN_DATA:
|
|
|
|
case MAVLINK_MSG_ID_TERRAIN_CHECK:
|
|
|
|
#if AP_TERRAIN_AVAILABLE && AC_TERRAIN
|
2016-01-14 15:30:56 -04:00
|
|
|
sub.terrain.handle_data(chan, msg);
|
2015-12-30 18:57:56 -04:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
2017-02-03 17:33:27 -04:00
|
|
|
case MAVLINK_MSG_ID_SET_HOME_POSITION: {
|
2015-12-30 18:57:56 -04:00
|
|
|
mavlink_set_home_position_t packet;
|
2019-04-30 07:22:51 -03:00
|
|
|
mavlink_msg_set_home_position_decode(&msg, &packet);
|
2017-02-03 17:33:27 -04:00
|
|
|
if ((packet.latitude == 0) && (packet.longitude == 0) && (packet.altitude == 0)) {
|
2018-05-29 21:47:13 -03:00
|
|
|
if (!sub.set_home_to_current_location(true)) {
|
|
|
|
// ignore this failure
|
|
|
|
}
|
2015-12-30 18:57:56 -04:00
|
|
|
} else {
|
|
|
|
Location new_home_loc;
|
|
|
|
new_home_loc.lat = packet.latitude;
|
|
|
|
new_home_loc.lng = packet.longitude;
|
2016-04-18 02:13:10 -03:00
|
|
|
new_home_loc.alt = packet.altitude / 10;
|
2016-01-14 15:30:56 -04:00
|
|
|
if (sub.far_from_EKF_origin(new_home_loc)) {
|
2015-12-30 18:57:56 -04:00
|
|
|
break;
|
|
|
|
}
|
2018-05-29 21:47:13 -03:00
|
|
|
if (!sub.set_home(new_home_loc, true)) {
|
|
|
|
// silently ignored
|
|
|
|
}
|
2015-12-30 18:57:56 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-04-16 15:11:15 -03:00
|
|
|
// This adds support for leak detectors in a separate enclosure
|
|
|
|
// connected to a mavlink enabled subsystem
|
2017-03-01 23:25:41 -04:00
|
|
|
case MAVLINK_MSG_ID_SYS_STATUS: {
|
2017-02-03 17:33:27 -04:00
|
|
|
uint32_t MAV_SENSOR_WATER = 0x20000000;
|
|
|
|
mavlink_sys_status_t packet;
|
2019-04-30 07:22:51 -03:00
|
|
|
mavlink_msg_sys_status_decode(&msg, &packet);
|
2017-02-03 17:33:27 -04:00
|
|
|
if ((packet.onboard_control_sensors_enabled & MAV_SENSOR_WATER) && !(packet.onboard_control_sensors_health & MAV_SENSOR_WATER)) {
|
|
|
|
sub.leak_detector.set_detect();
|
|
|
|
}
|
2017-03-01 23:25:41 -04:00
|
|
|
}
|
2017-02-03 17:33:27 -04:00
|
|
|
break;
|
2017-02-03 00:18:27 -04:00
|
|
|
|
2017-03-01 23:25:41 -04:00
|
|
|
default:
|
|
|
|
handle_common_message(msg);
|
|
|
|
break;
|
2015-12-30 18:57:56 -04:00
|
|
|
} // end switch
|
|
|
|
} // end handle mavlink
|
|
|
|
|
2018-03-28 22:04:11 -03:00
|
|
|
uint64_t GCS_MAVLINK_Sub::capabilities() const
|
|
|
|
{
|
|
|
|
return (MAV_PROTOCOL_CAPABILITY_MISSION_FLOAT |
|
|
|
|
MAV_PROTOCOL_CAPABILITY_MISSION_INT |
|
|
|
|
MAV_PROTOCOL_CAPABILITY_SET_POSITION_TARGET_LOCAL_NED |
|
|
|
|
MAV_PROTOCOL_CAPABILITY_SET_POSITION_TARGET_GLOBAL_INT |
|
|
|
|
MAV_PROTOCOL_CAPABILITY_FLIGHT_TERMINATION |
|
|
|
|
#if AP_TERRAIN_AVAILABLE && AC_TERRAIN
|
|
|
|
(sub.terrain.enabled() ? MAV_PROTOCOL_CAPABILITY_TERRAIN : 0) |
|
|
|
|
#endif
|
|
|
|
MAV_PROTOCOL_CAPABILITY_SET_ATTITUDE_TARGET |
|
|
|
|
GCS_MAVLINK::capabilities()
|
|
|
|
);
|
|
|
|
}
|
2015-12-30 18:57:56 -04:00
|
|
|
|
2017-07-27 02:23:40 -03:00
|
|
|
MAV_RESULT GCS_MAVLINK_Sub::handle_flight_termination(const mavlink_command_long_t &packet) {
|
|
|
|
if (packet.param1 > 0.5f) {
|
2020-02-21 09:09:58 -04:00
|
|
|
sub.arming.disarm(AP_Arming::Method::TERMINATION);
|
2017-07-27 02:23:40 -03:00
|
|
|
return MAV_RESULT_ACCEPTED;
|
|
|
|
}
|
|
|
|
return MAV_RESULT_FAILED;
|
|
|
|
}
|
|
|
|
|
2018-05-01 09:05:41 -03:00
|
|
|
int32_t GCS_MAVLINK_Sub::global_position_int_alt() const {
|
|
|
|
if (!sub.ap.depth_sensor_present) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return GCS_MAVLINK::global_position_int_alt();
|
|
|
|
}
|
|
|
|
int32_t GCS_MAVLINK_Sub::global_position_int_relative_alt() const {
|
|
|
|
if (!sub.ap.depth_sensor_present) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return GCS_MAVLINK::global_position_int_relative_alt();
|
|
|
|
}
|