2016-05-27 09:53:19 -03:00
|
|
|
#include "GCS_Mavlink.h"
|
|
|
|
|
2015-05-13 03:09:36 -03:00
|
|
|
#include "Plane.h"
|
2022-09-27 22:37:45 -03:00
|
|
|
#include <AP_RPM/AP_RPM_config.h>
|
2022-10-17 05:36:02 -03:00
|
|
|
#include <AP_Airspeed/AP_Airspeed_config.h>
|
2022-10-21 17:46:05 -03:00
|
|
|
#include <AP_EFI/AP_EFI_config.h>
|
2015-05-13 03:09:36 -03:00
|
|
|
|
2019-03-01 02:27:53 -04:00
|
|
|
MAV_TYPE GCS_Plane::frame_type() const
|
2018-03-22 06:16:35 -03:00
|
|
|
{
|
2021-09-10 03:28:21 -03:00
|
|
|
#if HAL_QUADPLANE_ENABLED
|
2018-03-22 06:16:35 -03:00
|
|
|
return plane.quadplane.get_mav_type();
|
2021-09-10 03:28:21 -03:00
|
|
|
#else
|
|
|
|
return MAV_TYPE_FIXED_WING;
|
|
|
|
#endif
|
2018-03-22 06:16:35 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
MAV_MODE GCS_MAVLINK_Plane::base_mode() const
|
2011-09-18 03:39:09 -03:00
|
|
|
{
|
2018-04-03 11:35:37 -03:00
|
|
|
uint8_t _base_mode = MAV_MODE_FLAG_CUSTOM_MODE_ENABLED;
|
2011-10-16 04:01:14 -03:00
|
|
|
|
2011-10-29 22:41:32 -03:00
|
|
|
// work out the base_mode. This value is not very useful
|
2011-10-16 04:01:14 -03:00
|
|
|
// 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
|
2019-01-15 13:46:13 -04:00
|
|
|
switch (plane.control_mode->mode_number()) {
|
|
|
|
case Mode::Number::MANUAL:
|
|
|
|
case Mode::Number::TRAINING:
|
|
|
|
case Mode::Number::ACRO:
|
2021-09-10 03:28:21 -03:00
|
|
|
#if HAL_QUADPLANE_ENABLED
|
2019-01-15 13:46:13 -04:00
|
|
|
case Mode::Number::QACRO:
|
2018-04-03 11:35:37 -03:00
|
|
|
_base_mode = MAV_MODE_FLAG_MANUAL_INPUT_ENABLED;
|
2011-10-16 04:01:14 -03:00
|
|
|
break;
|
2021-09-10 03:28:21 -03:00
|
|
|
#endif
|
2019-01-15 13:46:13 -04:00
|
|
|
case Mode::Number::STABILIZE:
|
|
|
|
case Mode::Number::FLY_BY_WIRE_A:
|
|
|
|
case Mode::Number::AUTOTUNE:
|
|
|
|
case Mode::Number::FLY_BY_WIRE_B:
|
2021-09-10 03:28:21 -03:00
|
|
|
#if HAL_QUADPLANE_ENABLED
|
2019-01-15 13:46:13 -04:00
|
|
|
case Mode::Number::QSTABILIZE:
|
|
|
|
case Mode::Number::QHOVER:
|
|
|
|
case Mode::Number::QLOITER:
|
|
|
|
case Mode::Number::QLAND:
|
2021-09-10 03:28:21 -03:00
|
|
|
#if QAUTOTUNE_ENABLED
|
2019-01-15 13:46:13 -04:00
|
|
|
case Mode::Number::QAUTOTUNE:
|
2021-09-10 03:28:21 -03:00
|
|
|
#endif
|
|
|
|
#endif // HAL_QUADPLANE_ENABLED
|
|
|
|
case Mode::Number::CRUISE:
|
2018-04-03 11:35:37 -03:00
|
|
|
_base_mode = MAV_MODE_FLAG_STABILIZE_ENABLED;
|
2011-10-16 04:01:14 -03:00
|
|
|
break;
|
2019-01-15 13:46:13 -04:00
|
|
|
case Mode::Number::AUTO:
|
|
|
|
case Mode::Number::RTL:
|
|
|
|
case Mode::Number::LOITER:
|
2020-09-16 04:46:56 -03:00
|
|
|
case Mode::Number::THERMAL:
|
2019-01-15 13:46:13 -04:00
|
|
|
case Mode::Number::AVOID_ADSB:
|
|
|
|
case Mode::Number::GUIDED:
|
|
|
|
case Mode::Number::CIRCLE:
|
2019-05-04 06:56:07 -03:00
|
|
|
case Mode::Number::TAKEOFF:
|
2021-09-10 03:28:21 -03:00
|
|
|
#if HAL_QUADPLANE_ENABLED
|
2019-01-15 13:46:13 -04:00
|
|
|
case Mode::Number::QRTL:
|
2021-09-18 20:15:41 -03:00
|
|
|
case Mode::Number::LOITER_ALT_QLAND:
|
2021-09-10 03:28:21 -03:00
|
|
|
#endif
|
2018-04-03 11:35:37 -03:00
|
|
|
_base_mode = MAV_MODE_FLAG_GUIDED_ENABLED |
|
|
|
|
MAV_MODE_FLAG_STABILIZE_ENABLED;
|
2011-10-16 04:01:14 -03: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;
|
2019-01-15 13:46:13 -04:00
|
|
|
case Mode::Number::INITIALISING:
|
2011-10-16 04:01:14 -03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-03-22 06:16:35 -03:00
|
|
|
if (!plane.training_manual_pitch || !plane.training_manual_roll) {
|
2018-04-03 11:35:37 -03:00
|
|
|
_base_mode |= MAV_MODE_FLAG_STABILIZE_ENABLED;
|
2012-12-04 02:32:37 -04:00
|
|
|
}
|
|
|
|
|
2019-01-15 13:46:13 -04:00
|
|
|
if (plane.control_mode != &plane.mode_manual && plane.control_mode != &plane.mode_initializing) {
|
2011-10-16 04:01:14 -03:00
|
|
|
// stabiliser of some form is enabled
|
2018-04-03 11:35:37 -03:00
|
|
|
_base_mode |= MAV_MODE_FLAG_STABILIZE_ENABLED;
|
2011-10-16 04:01:14 -03:00
|
|
|
}
|
|
|
|
|
2021-11-02 19:57:51 -03:00
|
|
|
if (plane.g.stick_mixing != StickMixing::NONE && plane.control_mode != &plane.mode_initializing) {
|
|
|
|
if ((plane.g.stick_mixing != StickMixing::VTOL_YAW) || (plane.control_mode == &plane.mode_auto)) {
|
2020-03-31 00:49:40 -03:00
|
|
|
// all modes except INITIALISING have some form of manual
|
|
|
|
// override if stick mixing is enabled
|
|
|
|
_base_mode |= MAV_MODE_FLAG_MANUAL_INPUT_ENABLED;
|
|
|
|
}
|
2011-10-16 04:01:14 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// we are armed if we are not initialising
|
2019-01-15 13:46:13 -04:00
|
|
|
if (plane.control_mode != &plane.mode_initializing && plane.arming.is_armed()) {
|
2018-04-03 11:35:37 -03:00
|
|
|
_base_mode |= MAV_MODE_FLAG_SAFETY_ARMED;
|
2011-10-16 04:01:14 -03:00
|
|
|
}
|
|
|
|
|
2011-10-29 22:41:32 -03:00
|
|
|
// indicate we have set a custom mode
|
2018-04-03 11:35:37 -03:00
|
|
|
_base_mode |= MAV_MODE_FLAG_CUSTOM_MODE_ENABLED;
|
2011-10-29 22:41:32 -03:00
|
|
|
|
2018-04-03 11:35:37 -03:00
|
|
|
return (MAV_MODE)_base_mode;
|
2018-03-22 06:16:35 -03:00
|
|
|
}
|
|
|
|
|
2019-03-01 02:27:53 -04:00
|
|
|
uint32_t GCS_Plane::custom_mode() const
|
2018-03-22 06:16:35 -03:00
|
|
|
{
|
2019-01-15 13:46:13 -04:00
|
|
|
return plane.control_mode->mode_number();
|
2011-09-18 03:39:09 -03:00
|
|
|
}
|
|
|
|
|
2019-11-25 22:46:28 -04:00
|
|
|
MAV_STATE GCS_MAVLINK_Plane::vehicle_system_status() const
|
2018-03-22 06:16:35 -03:00
|
|
|
{
|
2019-01-15 13:46:13 -04:00
|
|
|
if (plane.control_mode == &plane.mode_initializing) {
|
2018-03-22 06:16:35 -03:00
|
|
|
return MAV_STATE_CALIBRATING;
|
|
|
|
}
|
|
|
|
if (plane.any_failsafe_triggered()) {
|
|
|
|
return MAV_STATE_CRITICAL;
|
|
|
|
}
|
|
|
|
if (plane.crash_state.is_crashed) {
|
|
|
|
return MAV_STATE_EMERGENCY;
|
|
|
|
}
|
|
|
|
if (plane.is_flying()) {
|
|
|
|
return MAV_STATE_ACTIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return MAV_STATE_STANDBY;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-02 03:51:32 -03:00
|
|
|
void GCS_MAVLINK_Plane::send_attitude() const
|
2011-09-18 03:39:09 -03:00
|
|
|
{
|
2018-05-02 03:51:32 -03:00
|
|
|
const AP_AHRS &ahrs = AP::ahrs();
|
|
|
|
|
2024-01-12 08:40:24 -04:00
|
|
|
float r = ahrs.get_roll();
|
|
|
|
float p = ahrs.get_pitch();
|
|
|
|
float y = ahrs.get_yaw();
|
2021-07-26 21:07:27 -03:00
|
|
|
|
2023-12-13 17:49:48 -04:00
|
|
|
if (!(plane.flight_option_enabled(FlightOptions::GCS_REMOVE_TRIM_PITCH))) {
|
|
|
|
p -= radians(plane.g.pitch_trim);
|
2021-07-26 21:07:27 -03:00
|
|
|
}
|
2021-09-10 03:28:21 -03:00
|
|
|
|
|
|
|
#if HAL_QUADPLANE_ENABLED
|
2020-09-25 18:16:38 -03:00
|
|
|
if (plane.quadplane.show_vtol_view()) {
|
2018-05-02 03:51:32 -03:00
|
|
|
r = plane.quadplane.ahrs_view->roll;
|
|
|
|
p = plane.quadplane.ahrs_view->pitch;
|
|
|
|
y = plane.quadplane.ahrs_view->yaw;
|
2017-02-11 04:12:56 -04:00
|
|
|
}
|
2021-09-10 03:28:21 -03:00
|
|
|
#endif
|
|
|
|
|
2015-05-22 19:57:00 -03:00
|
|
|
const Vector3f &omega = ahrs.get_gyro();
|
2011-09-18 03:39:09 -03:00
|
|
|
mavlink_msg_attitude_send(
|
|
|
|
chan,
|
2015-05-13 19:05:32 -03:00
|
|
|
millis(),
|
2017-02-11 04:12:56 -04:00
|
|
|
r,
|
|
|
|
p,
|
|
|
|
y,
|
2011-09-18 03:39:09 -03:00
|
|
|
omega.x,
|
|
|
|
omega.y,
|
|
|
|
omega.z);
|
|
|
|
}
|
|
|
|
|
2023-10-13 05:40:09 -03:00
|
|
|
void GCS_MAVLINK_Plane::send_attitude_target()
|
|
|
|
{
|
|
|
|
#if HAL_QUADPLANE_ENABLED
|
|
|
|
// Check if the attitude target is valid for reporting
|
|
|
|
const uint32_t now = AP_HAL::millis();
|
|
|
|
if (now - plane.quadplane.last_att_control_ms > 100) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Quaternion quat = plane.quadplane.attitude_control->get_attitude_target_quat();
|
|
|
|
const Vector3f& ang_vel = plane.quadplane.attitude_control->get_attitude_target_ang_vel();
|
|
|
|
const float throttle = plane.quadplane.attitude_control->get_throttle_in();
|
|
|
|
|
|
|
|
const float quat_out[4] {quat.q1, quat.q2, quat.q3, quat.q4};
|
|
|
|
|
|
|
|
const uint16_t typemask = 0;
|
|
|
|
|
|
|
|
mavlink_msg_attitude_target_send(
|
|
|
|
chan,
|
|
|
|
now, // time since boot (ms)
|
|
|
|
typemask, // Bitmask that tells the system what control dimensions should be ignored by the vehicle
|
|
|
|
quat_out, // Target attitude quaternion [w, x, y, z] order, zero-rotation is [1, 0, 0, 0], unit-length
|
|
|
|
ang_vel.x, // bodyframe target roll rate (rad/s)
|
|
|
|
ang_vel.y, // bodyframe target pitch rate (rad/s)
|
|
|
|
ang_vel.z, // bodyframe yaw rate (rad/s)
|
|
|
|
throttle); // Collective thrust, normalized to 0 .. 1
|
|
|
|
|
|
|
|
#endif // HAL_QUADPLANE_ENABLED
|
|
|
|
}
|
|
|
|
|
2019-11-24 18:24:02 -04:00
|
|
|
void GCS_MAVLINK_Plane::send_aoa_ssa()
|
2017-04-09 08:16:50 -03:00
|
|
|
{
|
2019-11-24 18:24:02 -04:00
|
|
|
AP_AHRS &ahrs = AP::ahrs();
|
|
|
|
|
2017-04-09 08:16:50 -03:00
|
|
|
mavlink_msg_aoa_ssa_send(
|
|
|
|
chan,
|
|
|
|
micros(),
|
|
|
|
ahrs.getAOA(),
|
|
|
|
ahrs.getSSA());
|
|
|
|
}
|
|
|
|
|
2018-05-04 21:10:31 -03:00
|
|
|
void GCS_MAVLINK_Plane::send_nav_controller_output() const
|
2011-09-18 03:39:09 -03:00
|
|
|
{
|
2019-01-15 13:46:13 -04:00
|
|
|
if (plane.control_mode == &plane.mode_manual) {
|
2018-05-04 21:10:31 -03:00
|
|
|
return;
|
|
|
|
}
|
2021-09-10 03:28:21 -03:00
|
|
|
#if HAL_QUADPLANE_ENABLED
|
2018-05-04 21:10:31 -03:00
|
|
|
const QuadPlane &quadplane = plane.quadplane;
|
2022-01-28 16:49:00 -04:00
|
|
|
if (quadplane.show_vtol_view() && quadplane.using_wp_nav()) {
|
2018-07-25 18:32:42 -03:00
|
|
|
const Vector3f &targets = quadplane.attitude_control->get_att_target_euler_cd();
|
2022-01-28 16:49:00 -04:00
|
|
|
|
|
|
|
const Vector2f& curr_pos = quadplane.inertial_nav.get_position_xy_cm();
|
|
|
|
const Vector2f& target_pos = quadplane.pos_control->get_pos_target_cm().xy().tofloat();
|
|
|
|
const Vector2f error = (target_pos - curr_pos) * 0.01;
|
2018-07-25 18:32:42 -03:00
|
|
|
|
|
|
|
mavlink_msg_nav_controller_output_send(
|
|
|
|
chan,
|
2021-08-31 16:31:49 -03:00
|
|
|
targets.x * 0.01,
|
|
|
|
targets.y * 0.01,
|
|
|
|
targets.z * 0.01,
|
2022-01-28 16:49:00 -04:00
|
|
|
degrees(error.angle()),
|
2022-03-08 22:16:32 -04:00
|
|
|
MIN(error.length(), UINT16_MAX),
|
2021-08-31 16:31:49 -03:00
|
|
|
(plane.control_mode != &plane.mode_qstabilize) ? quadplane.pos_control->get_pos_error_z_cm() * 0.01 : 0,
|
2021-10-01 07:35:41 -03:00
|
|
|
plane.airspeed_error * 100, // incorrect units; see PR#7933
|
2022-01-28 16:49:00 -04:00
|
|
|
quadplane.wp_nav->crosstrack_error());
|
2021-09-10 03:28:21 -03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
{
|
2018-05-04 21:10:31 -03:00
|
|
|
const AP_Navigation *nav_controller = plane.nav_controller;
|
2018-07-25 18:32:42 -03:00
|
|
|
mavlink_msg_nav_controller_output_send(
|
|
|
|
chan,
|
2021-08-31 16:31:49 -03:00
|
|
|
plane.nav_roll_cd * 0.01,
|
|
|
|
plane.nav_pitch_cd * 0.01,
|
|
|
|
nav_controller->nav_bearing_cd() * 0.01,
|
|
|
|
nav_controller->target_bearing_cd() * 0.01,
|
2018-05-04 21:10:31 -03:00
|
|
|
MIN(plane.auto_state.wp_distance, UINT16_MAX),
|
2024-05-06 04:01:08 -03:00
|
|
|
plane.calc_altitude_error_cm() * 0.01,
|
2021-10-01 07:35:41 -03:00
|
|
|
plane.airspeed_error * 100, // incorrect units; see PR#7933
|
2018-07-25 18:32:42 -03:00
|
|
|
nav_controller->crosstrack_error());
|
|
|
|
}
|
2011-09-18 03:39:09 -03:00
|
|
|
}
|
|
|
|
|
2018-05-11 08:56:26 -03:00
|
|
|
void GCS_MAVLINK_Plane::send_position_target_global_int()
|
2016-04-14 02:22:13 -03:00
|
|
|
{
|
2019-01-15 13:46:13 -04:00
|
|
|
if (plane.control_mode == &plane.mode_manual) {
|
2018-05-11 08:56:26 -03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
Location &next_WP_loc = plane.next_WP_loc;
|
2021-03-16 14:28:33 -03:00
|
|
|
static constexpr uint16_t POSITION_TARGET_TYPEMASK_LAST_BYTE = 0xF000;
|
|
|
|
static constexpr uint16_t TYPE_MASK = POSITION_TARGET_TYPEMASK_VX_IGNORE | POSITION_TARGET_TYPEMASK_VY_IGNORE | POSITION_TARGET_TYPEMASK_VZ_IGNORE |
|
|
|
|
POSITION_TARGET_TYPEMASK_AX_IGNORE | POSITION_TARGET_TYPEMASK_AY_IGNORE | POSITION_TARGET_TYPEMASK_AZ_IGNORE |
|
2021-07-26 03:37:11 -03:00
|
|
|
POSITION_TARGET_TYPEMASK_YAW_IGNORE | POSITION_TARGET_TYPEMASK_YAW_RATE_IGNORE | POSITION_TARGET_TYPEMASK_LAST_BYTE;
|
2022-02-05 20:07:05 -04:00
|
|
|
int32_t alt = 0;
|
|
|
|
if (!next_WP_loc.is_zero()) {
|
|
|
|
UNUSED_RESULT(next_WP_loc.get_alt_cm(Location::AltFrame::ABSOLUTE, alt));
|
|
|
|
}
|
|
|
|
|
2016-04-14 02:22:13 -03:00
|
|
|
mavlink_msg_position_target_global_int_send(
|
|
|
|
chan,
|
|
|
|
AP_HAL::millis(), // time_boot_ms
|
2019-07-26 22:38:30 -03:00
|
|
|
MAV_FRAME_GLOBAL, // targets are always global altitude
|
2021-03-16 14:28:33 -03:00
|
|
|
TYPE_MASK, // ignore everything except the x/y/z components
|
2016-04-14 02:22:13 -03:00
|
|
|
next_WP_loc.lat, // latitude as 1e7
|
|
|
|
next_WP_loc.lng, // longitude as 1e7
|
2022-02-05 20:07:05 -04:00
|
|
|
alt * 0.01, // altitude is sent as a float
|
2016-04-14 02:22:13 -03:00
|
|
|
0.0f, // vx
|
|
|
|
0.0f, // vy
|
|
|
|
0.0f, // vz
|
|
|
|
0.0f, // afx
|
|
|
|
0.0f, // afy
|
|
|
|
0.0f, // afz
|
|
|
|
0.0f, // yaw
|
|
|
|
0.0f); // yaw_rate
|
|
|
|
}
|
|
|
|
|
2013-10-23 08:15:06 -03:00
|
|
|
|
2018-01-28 18:59:58 -04:00
|
|
|
float GCS_MAVLINK_Plane::vfr_hud_airspeed() const
|
2011-09-18 03:39:09 -03:00
|
|
|
{
|
2018-01-28 18:59:58 -04:00
|
|
|
// airspeed sensors are best. While the AHRS airspeed_estimate
|
|
|
|
// will use an airspeed sensor, that value is constrained by the
|
|
|
|
// ground speed. When reporting we should send the true airspeed
|
|
|
|
// value if possible:
|
2022-03-12 07:48:55 -04:00
|
|
|
#if AP_AIRSPEED_ENABLED
|
2018-05-31 19:31:50 -03:00
|
|
|
if (plane.airspeed.enabled() && plane.airspeed.healthy()) {
|
2018-01-28 18:59:58 -04:00
|
|
|
return plane.airspeed.get_airspeed();
|
|
|
|
}
|
2022-03-12 07:48:55 -04:00
|
|
|
#endif
|
2018-01-28 18:59:58 -04:00
|
|
|
|
|
|
|
// airspeed estimates are OK:
|
2012-08-24 09:03:40 -03:00
|
|
|
float aspeed;
|
2020-01-06 20:45:27 -04:00
|
|
|
if (AP::ahrs().airspeed_estimate(aspeed)) {
|
2018-01-28 18:59:58 -04:00
|
|
|
return aspeed;
|
2012-08-24 09:03:40 -03:00
|
|
|
}
|
2018-01-28 18:59:58 -04:00
|
|
|
|
|
|
|
// lying is worst:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int16_t GCS_MAVLINK_Plane::vfr_hud_throttle() const
|
|
|
|
{
|
2019-10-31 19:35:13 -03:00
|
|
|
return plane.throttle_percentage();
|
2018-01-28 18:59:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
float GCS_MAVLINK_Plane::vfr_hud_climbrate() const
|
|
|
|
{
|
2020-09-23 05:16:45 -03:00
|
|
|
#if HAL_SOARING_ENABLED
|
2020-04-05 08:38:19 -03:00
|
|
|
if (plane.g2.soaring_controller.is_active()) {
|
2018-01-28 18:59:58 -04:00
|
|
|
return plane.g2.soaring_controller.get_vario_reading();
|
|
|
|
}
|
2018-07-29 19:57:55 -03:00
|
|
|
#endif
|
2022-01-12 16:12:38 -04:00
|
|
|
return GCS_MAVLINK::vfr_hud_climbrate();
|
2011-09-18 03:39:09 -03:00
|
|
|
}
|
|
|
|
|
2019-11-24 18:28:33 -04:00
|
|
|
void GCS_MAVLINK_Plane::send_wind() const
|
2012-08-11 02:57:13 -03:00
|
|
|
{
|
2019-11-24 18:28:33 -04:00
|
|
|
const Vector3f wind = AP::ahrs().wind_estimate();
|
2012-08-11 02:57:13 -03:00
|
|
|
mavlink_msg_wind_send(
|
|
|
|
chan,
|
2013-01-10 14:42:24 -04:00
|
|
|
degrees(atan2f(-wind.y, -wind.x)), // use negative, to give
|
2012-11-18 16:10:26 -04:00
|
|
|
// direction wind is coming from
|
2012-12-18 22:36:00 -04:00
|
|
|
wind.length(),
|
2012-08-11 02:57:13 -03:00
|
|
|
wind.z);
|
|
|
|
}
|
|
|
|
|
2018-03-02 20:46:46 -04:00
|
|
|
// sends a single pid info over the provided channel
|
2022-03-03 23:29:49 -04:00
|
|
|
void GCS_MAVLINK_Plane::send_pid_info(const AP_PIDInfo *pid_info,
|
2018-03-02 20:46:46 -04:00
|
|
|
const uint8_t axis, const float achieved)
|
|
|
|
{
|
|
|
|
if (pid_info == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!HAVE_PAYLOAD_SPACE(chan, PID_TUNING)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mavlink_msg_pid_tuning_send(chan, axis,
|
2019-06-27 06:31:52 -03:00
|
|
|
pid_info->target,
|
2018-03-02 20:46:46 -04:00
|
|
|
achieved,
|
|
|
|
pid_info->FF,
|
|
|
|
pid_info->P,
|
|
|
|
pid_info->I,
|
2021-08-14 00:11:09 -03:00
|
|
|
pid_info->D,
|
|
|
|
pid_info->slew_rate,
|
|
|
|
pid_info->Dmod);
|
2018-03-02 20:46:46 -04:00
|
|
|
}
|
|
|
|
|
2015-05-22 19:57:00 -03:00
|
|
|
/*
|
|
|
|
send PID tuning message
|
|
|
|
*/
|
2019-02-28 19:33:00 -04:00
|
|
|
void GCS_MAVLINK_Plane::send_pid_tuning()
|
2015-05-22 19:57:00 -03:00
|
|
|
{
|
2019-01-15 13:46:13 -04:00
|
|
|
if (plane.control_mode == &plane.mode_manual) {
|
2019-02-28 19:33:00 -04:00
|
|
|
// no PIDs should be used in manual
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Parameters &g = plane.g;
|
|
|
|
|
2022-03-03 23:29:49 -04:00
|
|
|
const AP_PIDInfo *pid_info;
|
2018-03-02 20:46:46 -04:00
|
|
|
if (g.gcs_pid_mask & TUNING_BITS_ROLL) {
|
2021-09-10 03:28:21 -03:00
|
|
|
pid_info = &plane.rollController.get_pid_info();
|
|
|
|
#if HAL_QUADPLANE_ENABLED
|
2019-02-28 19:33:00 -04:00
|
|
|
if (plane.quadplane.in_vtol_mode()) {
|
|
|
|
pid_info = &plane.quadplane.attitude_control->get_rate_roll_pid().get_pid_info();
|
2016-02-28 23:10:20 -04:00
|
|
|
}
|
2021-09-10 03:28:21 -03:00
|
|
|
#endif
|
2020-05-18 09:11:34 -03:00
|
|
|
send_pid_info(pid_info, PID_TUNING_ROLL, pid_info->actual);
|
2015-05-22 19:57:00 -03:00
|
|
|
}
|
2018-03-02 20:46:46 -04:00
|
|
|
if (g.gcs_pid_mask & TUNING_BITS_PITCH) {
|
2021-09-10 03:28:21 -03:00
|
|
|
pid_info = &plane.pitchController.get_pid_info();
|
|
|
|
#if HAL_QUADPLANE_ENABLED
|
2019-02-28 19:33:00 -04:00
|
|
|
if (plane.quadplane.in_vtol_mode()) {
|
|
|
|
pid_info = &plane.quadplane.attitude_control->get_rate_pitch_pid().get_pid_info();
|
2016-02-28 23:10:20 -04:00
|
|
|
}
|
2021-09-10 03:28:21 -03:00
|
|
|
#endif
|
2020-05-18 09:11:34 -03:00
|
|
|
send_pid_info(pid_info, PID_TUNING_PITCH, pid_info->actual);
|
2015-05-22 19:57:00 -03:00
|
|
|
}
|
2018-03-02 20:46:46 -04:00
|
|
|
if (g.gcs_pid_mask & TUNING_BITS_YAW) {
|
2021-09-10 03:28:21 -03:00
|
|
|
pid_info = &plane.yawController.get_pid_info();
|
|
|
|
#if HAL_QUADPLANE_ENABLED
|
2019-02-28 19:33:00 -04:00
|
|
|
if (plane.quadplane.in_vtol_mode()) {
|
|
|
|
pid_info = &plane.quadplane.attitude_control->get_rate_yaw_pid().get_pid_info();
|
2016-02-28 23:10:20 -04:00
|
|
|
}
|
2021-09-10 03:28:21 -03:00
|
|
|
#endif
|
2020-05-18 09:11:34 -03:00
|
|
|
send_pid_info(pid_info, PID_TUNING_YAW, pid_info->actual);
|
2015-06-22 00:27:40 -03:00
|
|
|
}
|
2018-03-02 20:46:46 -04:00
|
|
|
if (g.gcs_pid_mask & TUNING_BITS_STEER) {
|
2020-05-18 09:11:34 -03:00
|
|
|
pid_info = &plane.steerController.get_pid_info();
|
|
|
|
send_pid_info(pid_info, PID_TUNING_STEER, pid_info->actual);
|
2015-06-08 08:08:34 -03:00
|
|
|
}
|
2022-09-29 20:10:41 -03:00
|
|
|
if ((g.gcs_pid_mask & TUNING_BITS_LAND) && (plane.flight_stage == AP_FixedWing::FlightStage::LAND)) {
|
2020-05-18 09:11:34 -03:00
|
|
|
AP_AHRS &ahrs = AP::ahrs();
|
|
|
|
const Vector3f &gyro = ahrs.get_gyro();
|
2019-02-28 19:33:00 -04:00
|
|
|
send_pid_info(plane.landing.get_pid_info(), PID_TUNING_LANDING, degrees(gyro.z));
|
2017-02-14 15:20:47 -04:00
|
|
|
}
|
2021-09-10 03:28:21 -03:00
|
|
|
#if HAL_QUADPLANE_ENABLED
|
2019-02-28 19:33:00 -04:00
|
|
|
if (g.gcs_pid_mask & TUNING_BITS_ACCZ && plane.quadplane.in_vtol_mode()) {
|
|
|
|
pid_info = &plane.quadplane.pos_control->get_accel_z_pid().get_pid_info();
|
2020-05-18 09:11:34 -03:00
|
|
|
send_pid_info(pid_info, PID_TUNING_ACCZ, pid_info->actual);
|
2018-11-11 19:22:28 -04:00
|
|
|
}
|
2021-09-10 03:28:21 -03:00
|
|
|
#endif
|
2018-11-11 19:22:28 -04:00
|
|
|
}
|
2015-05-22 19:57:00 -03:00
|
|
|
|
2017-07-12 04:41:28 -03:00
|
|
|
uint8_t GCS_MAVLINK_Plane::sysid_my_gcs() const
|
|
|
|
{
|
|
|
|
return plane.g.sysid_my_gcs;
|
|
|
|
}
|
2018-12-13 19:12:52 -04:00
|
|
|
bool GCS_MAVLINK_Plane::sysid_enforce() const
|
|
|
|
{
|
|
|
|
return plane.g2.sysid_enforce;
|
|
|
|
}
|
2017-07-12 04:41:28 -03:00
|
|
|
|
2016-05-29 21:08:39 -03:00
|
|
|
uint32_t GCS_MAVLINK_Plane::telem_delay() const
|
2012-08-29 19:59:39 -03:00
|
|
|
{
|
2016-05-29 21:08:39 -03:00
|
|
|
return (uint32_t)(plane.g.telem_delay);
|
2012-08-29 19:59:39 -03:00
|
|
|
}
|
|
|
|
|
2011-09-18 03:39:09 -03:00
|
|
|
// try to send a message, return false if it won't fit in the serial tx buffer
|
2016-05-27 09:53:19 -03:00
|
|
|
bool GCS_MAVLINK_Plane::try_send_message(enum ap_message id)
|
2011-09-18 03:39:09 -03:00
|
|
|
{
|
|
|
|
switch (id) {
|
|
|
|
|
|
|
|
case MSG_SERVO_OUT:
|
2021-06-09 08:31:35 -03:00
|
|
|
// unused
|
2011-09-18 03:39:09 -03:00
|
|
|
break;
|
|
|
|
|
2014-07-21 19:24:00 -03:00
|
|
|
case MSG_TERRAIN:
|
2014-07-24 18:58:39 -03:00
|
|
|
#if AP_TERRAIN_AVAILABLE
|
2014-07-21 19:24:00 -03:00
|
|
|
CHECK_PAYLOAD_SIZE(TERRAIN_REQUEST);
|
2015-05-13 03:09:36 -03:00
|
|
|
plane.terrain.send_request(chan);
|
2014-07-21 19:24:00 -03:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
2012-08-11 02:57:13 -03:00
|
|
|
case MSG_WIND:
|
|
|
|
CHECK_PAYLOAD_SIZE(WIND);
|
2019-11-24 18:28:33 -04:00
|
|
|
send_wind();
|
2012-08-11 02:57:13 -03:00
|
|
|
break;
|
|
|
|
|
2016-06-15 17:57:48 -03:00
|
|
|
case MSG_ADSB_VEHICLE:
|
2020-09-19 05:38:20 -03:00
|
|
|
#if HAL_ADSB_ENABLED
|
2016-06-15 17:57:48 -03:00
|
|
|
CHECK_PAYLOAD_SIZE(ADSB_VEHICLE);
|
|
|
|
plane.adsb.send_adsb_vehicle(chan);
|
2020-09-19 05:38:20 -03:00
|
|
|
#endif
|
2016-06-15 17:57:48 -03:00
|
|
|
break;
|
2018-05-02 05:11:10 -03:00
|
|
|
|
2017-04-09 08:16:50 -03:00
|
|
|
case MSG_AOA_SSA:
|
|
|
|
CHECK_PAYLOAD_SIZE(AOA_SSA);
|
2019-11-24 18:24:02 -04:00
|
|
|
send_aoa_ssa();
|
2017-06-05 00:22:08 -03:00
|
|
|
break;
|
2017-04-13 03:58:05 -03:00
|
|
|
case MSG_LANDING:
|
|
|
|
plane.landing.send_landing_message(chan);
|
2017-04-09 08:16:50 -03:00
|
|
|
break;
|
2022-10-17 05:36:02 -03:00
|
|
|
|
|
|
|
case MSG_HYGROMETER:
|
|
|
|
#if AP_AIRSPEED_HYGROMETER_ENABLE
|
|
|
|
CHECK_PAYLOAD_SIZE(HYGROMETER_SENSOR);
|
|
|
|
send_hygrometer();
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
2017-07-17 22:01:57 -03:00
|
|
|
default:
|
|
|
|
return GCS_MAVLINK::try_send_message(id);
|
2012-08-21 23:19:51 -03:00
|
|
|
}
|
2011-09-18 03:39:09 -03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-10-17 05:36:02 -03:00
|
|
|
#if AP_AIRSPEED_HYGROMETER_ENABLE
|
|
|
|
void GCS_MAVLINK_Plane::send_hygrometer()
|
|
|
|
{
|
|
|
|
if (!HAVE_PAYLOAD_SPACE(chan, HYGROMETER_SENSOR)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto *airspeed = AP::airspeed();
|
|
|
|
if (airspeed == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const uint32_t now = AP_HAL::millis();
|
|
|
|
|
|
|
|
for (uint8_t i=0; i<AIRSPEED_MAX_SENSORS; i++) {
|
|
|
|
uint8_t idx = (i+last_hygrometer_send_idx+1) % AIRSPEED_MAX_SENSORS;
|
|
|
|
float temperature, humidity;
|
|
|
|
uint32_t last_sample_ms;
|
|
|
|
if (!airspeed->get_hygrometer(idx, last_sample_ms, temperature, humidity)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (now - last_sample_ms > 2000) {
|
|
|
|
// not updating, stop sending
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!HAVE_PAYLOAD_SPACE(chan, HYGROMETER_SENSOR)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mavlink_msg_hygrometer_sensor_send(
|
|
|
|
chan,
|
|
|
|
idx,
|
|
|
|
int16_t(temperature*100),
|
|
|
|
uint16_t(humidity*100));
|
|
|
|
last_hygrometer_send_idx = idx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // AP_AIRSPEED_HYGROMETER_ENABLE
|
|
|
|
|
2011-09-18 03:39:09 -03:00
|
|
|
|
2013-02-19 19:08:49 -04:00
|
|
|
/*
|
|
|
|
default stream rates to 1Hz
|
|
|
|
*/
|
2019-06-18 07:37:53 -03:00
|
|
|
const AP_Param::GroupInfo GCS_MAVLINK_Parameters::var_info[] = {
|
2013-04-03 10:58:25 -03:00
|
|
|
// @Param: RAW_SENS
|
|
|
|
// @DisplayName: Raw sensor stream rate
|
2022-10-16 20:00:46 -03:00
|
|
|
// @Description: MAVLink Stream rate of RAW_IMU, SCALED_IMU2, SCALED_IMU3, SCALED_PRESSURE, SCALED_PRESSURE2, and SCALED_PRESSURE3
|
2013-04-03 10:58:25 -03:00
|
|
|
// @Units: Hz
|
2021-02-19 11:33:24 -04:00
|
|
|
// @Range: 0 50
|
2013-04-03 10:58:25 -03:00
|
|
|
// @Increment: 1
|
2022-02-19 21:08:11 -04:00
|
|
|
// @RebootRequired: True
|
2013-04-03 10:58:25 -03:00
|
|
|
// @User: Advanced
|
2019-06-18 07:37:53 -03:00
|
|
|
AP_GROUPINFO("RAW_SENS", 0, GCS_MAVLINK_Parameters, streamRates[0], 1),
|
2013-04-03 10:58:25 -03:00
|
|
|
|
|
|
|
// @Param: EXT_STAT
|
2022-10-16 20:00:46 -03:00
|
|
|
// @DisplayName: Extended status stream rate
|
|
|
|
// @Description: MAVLink Stream rate of SYS_STATUS, POWER_STATUS, MCU_STATUS, MEMINFO, CURRENT_WAYPOINT, GPS_RAW_INT, GPS_RTK (if available), GPS2_RAW_INT (if available), GPS2_RTK (if available), NAV_CONTROLLER_OUTPUT, FENCE_STATUS, and GLOBAL_TARGET_POS_INT
|
2013-04-03 10:58:25 -03:00
|
|
|
// @Units: Hz
|
2021-02-19 11:33:24 -04:00
|
|
|
// @Range: 0 50
|
2013-04-03 10:58:25 -03:00
|
|
|
// @Increment: 1
|
2022-02-19 21:08:11 -04:00
|
|
|
// @RebootRequired: True
|
2013-04-03 10:58:25 -03:00
|
|
|
// @User: Advanced
|
2019-06-18 07:37:53 -03:00
|
|
|
AP_GROUPINFO("EXT_STAT", 1, GCS_MAVLINK_Parameters, streamRates[1], 1),
|
2013-04-03 10:58:25 -03:00
|
|
|
|
|
|
|
// @Param: RC_CHAN
|
2022-10-16 20:00:46 -03:00
|
|
|
// @DisplayName: RC Channel stream rate
|
|
|
|
// @Description: MAVLink Stream rate of SERVO_OUTPUT_RAW and RC_CHANNELS
|
2013-04-03 10:58:25 -03:00
|
|
|
// @Units: Hz
|
2021-02-19 11:33:24 -04:00
|
|
|
// @Range: 0 50
|
2013-04-03 10:58:25 -03:00
|
|
|
// @Increment: 1
|
2022-02-19 21:08:11 -04:00
|
|
|
// @RebootRequired: True
|
2013-04-03 10:58:25 -03:00
|
|
|
// @User: Advanced
|
2019-06-18 07:37:53 -03:00
|
|
|
AP_GROUPINFO("RC_CHAN", 2, GCS_MAVLINK_Parameters, streamRates[2], 1),
|
2013-04-03 10:58:25 -03:00
|
|
|
|
|
|
|
// @Param: RAW_CTRL
|
2022-10-16 20:00:46 -03:00
|
|
|
// @DisplayName: Raw Control stream rate
|
|
|
|
// @Description: MAVLink Raw Control stream rate of SERVO_OUT
|
2013-04-03 10:58:25 -03:00
|
|
|
// @Units: Hz
|
2021-02-19 11:33:24 -04:00
|
|
|
// @Range: 0 50
|
2013-04-03 10:58:25 -03:00
|
|
|
// @Increment: 1
|
2022-02-19 21:08:11 -04:00
|
|
|
// @RebootRequired: True
|
2013-04-03 10:58:25 -03:00
|
|
|
// @User: Advanced
|
2019-06-18 07:37:53 -03:00
|
|
|
AP_GROUPINFO("RAW_CTRL", 3, GCS_MAVLINK_Parameters, streamRates[3], 1),
|
2013-04-03 10:58:25 -03:00
|
|
|
|
|
|
|
// @Param: POSITION
|
2022-10-16 20:00:46 -03:00
|
|
|
// @DisplayName: Position stream rate
|
|
|
|
// @Description: MAVLink Stream rate of GLOBAL_POSITION_INT and LOCAL_POSITION_NED
|
2013-04-03 10:58:25 -03:00
|
|
|
// @Units: Hz
|
2021-02-19 11:33:24 -04:00
|
|
|
// @Range: 0 50
|
2013-04-03 10:58:25 -03:00
|
|
|
// @Increment: 1
|
2022-02-19 21:08:11 -04:00
|
|
|
// @RebootRequired: True
|
2013-04-03 10:58:25 -03:00
|
|
|
// @User: Advanced
|
2019-06-18 07:37:53 -03:00
|
|
|
AP_GROUPINFO("POSITION", 4, GCS_MAVLINK_Parameters, streamRates[4], 1),
|
2013-04-03 10:58:25 -03:00
|
|
|
|
|
|
|
// @Param: EXTRA1
|
2022-10-16 20:00:46 -03:00
|
|
|
// @DisplayName: Extra data type 1 stream rate
|
|
|
|
// @Description: MAVLink Stream rate of ATTITUDE, SIMSTATE (SIM only), AHRS2, RPM, AOA_SSA, LANDING,ESC_TELEMETRY,EFI_STATUS, and PID_TUNING
|
2013-04-03 10:58:25 -03:00
|
|
|
// @Units: Hz
|
2021-02-19 11:33:24 -04:00
|
|
|
// @Range: 0 50
|
2013-04-03 10:58:25 -03:00
|
|
|
// @Increment: 1
|
2022-02-19 21:08:11 -04:00
|
|
|
// @RebootRequired: True
|
2013-04-03 10:58:25 -03:00
|
|
|
// @User: Advanced
|
2019-06-18 07:37:53 -03:00
|
|
|
AP_GROUPINFO("EXTRA1", 5, GCS_MAVLINK_Parameters, streamRates[5], 1),
|
2013-04-03 10:58:25 -03:00
|
|
|
|
|
|
|
// @Param: EXTRA2
|
2022-10-16 20:00:46 -03:00
|
|
|
// @DisplayName: Extra data type 2 stream rate
|
|
|
|
// @Description: MAVLink Stream rate of VFR_HUD
|
2021-02-19 11:33:24 -04:00
|
|
|
// @Range: 0 50
|
2013-04-03 10:58:25 -03:00
|
|
|
// @Increment: 1
|
2022-02-19 21:08:11 -04:00
|
|
|
// @RebootRequired: True
|
2013-04-03 10:58:25 -03:00
|
|
|
// @User: Advanced
|
2019-06-18 07:37:53 -03:00
|
|
|
AP_GROUPINFO("EXTRA2", 6, GCS_MAVLINK_Parameters, streamRates[6], 1),
|
2013-04-03 10:58:25 -03:00
|
|
|
|
|
|
|
// @Param: EXTRA3
|
2022-10-16 20:00:46 -03:00
|
|
|
// @DisplayName: Extra data type 3 stream rate
|
|
|
|
// @Description: MAVLink Stream rate of AHRS, SYSTEM_TIME, WIND, RANGEFINDER, DISTANCE_SENSOR, TERRAIN_REQUEST, BATTERY2, GIMBAL_DEVICE_ATTITUDE_STATUS, OPTICAL_FLOW, MAG_CAL_REPORT, MAG_CAL_PROGRESS, EKF_STATUS_REPORT, VIBRATION, and BATTERY_STATUS
|
2013-04-03 10:58:25 -03:00
|
|
|
// @Units: Hz
|
2021-02-19 11:33:24 -04:00
|
|
|
// @Range: 0 50
|
2013-04-03 10:58:25 -03:00
|
|
|
// @Increment: 1
|
2022-02-19 21:08:11 -04:00
|
|
|
// @RebootRequired: True
|
2013-04-03 10:58:25 -03:00
|
|
|
// @User: Advanced
|
2019-06-18 07:37:53 -03:00
|
|
|
AP_GROUPINFO("EXTRA3", 7, GCS_MAVLINK_Parameters, streamRates[7], 1),
|
2013-04-03 10:58:25 -03:00
|
|
|
|
|
|
|
// @Param: PARAMS
|
2022-10-16 20:00:46 -03:00
|
|
|
// @DisplayName: Parameter stream rate
|
|
|
|
// @Description: MAVLink Stream rate of PARAM_VALUE
|
2013-04-03 10:58:25 -03:00
|
|
|
// @Units: Hz
|
2021-02-19 11:33:24 -04:00
|
|
|
// @Range: 0 50
|
2013-04-03 10:58:25 -03:00
|
|
|
// @Increment: 1
|
2022-02-19 21:08:11 -04:00
|
|
|
// @RebootRequired: True
|
2013-04-03 10:58:25 -03:00
|
|
|
// @User: Advanced
|
2019-06-18 07:37:53 -03:00
|
|
|
AP_GROUPINFO("PARAMS", 8, GCS_MAVLINK_Parameters, streamRates[8], 10),
|
2016-06-15 17:57:48 -03:00
|
|
|
|
|
|
|
// @Param: ADSB
|
2022-10-16 20:00:46 -03:00
|
|
|
// @DisplayName: ADSB stream rate
|
|
|
|
// @Description: MAVLink ADSB stream rate
|
2016-06-15 17:57:48 -03:00
|
|
|
// @Units: Hz
|
|
|
|
// @Range: 0 50
|
|
|
|
// @Increment: 1
|
2022-02-19 21:08:11 -04:00
|
|
|
// @RebootRequired: True
|
2016-06-15 17:57:48 -03:00
|
|
|
// @User: Advanced
|
2019-06-18 07:37:53 -03:00
|
|
|
AP_GROUPINFO("ADSB", 9, GCS_MAVLINK_Parameters, streamRates[9], 5),
|
2012-02-12 04:20:56 -04:00
|
|
|
AP_GROUPEND
|
|
|
|
};
|
|
|
|
|
2018-05-21 01:06:49 -03:00
|
|
|
static const ap_message STREAM_RAW_SENSORS_msgs[] = {
|
2018-12-06 17:59:34 -04:00
|
|
|
MSG_RAW_IMU,
|
|
|
|
MSG_SCALED_IMU2,
|
|
|
|
MSG_SCALED_IMU3,
|
2018-12-07 02:29:40 -04:00
|
|
|
MSG_SCALED_PRESSURE,
|
|
|
|
MSG_SCALED_PRESSURE2,
|
|
|
|
MSG_SCALED_PRESSURE3,
|
2017-08-21 02:53:45 -03:00
|
|
|
};
|
2018-05-21 01:06:49 -03:00
|
|
|
static const ap_message STREAM_EXTENDED_STATUS_msgs[] = {
|
2018-12-17 22:08:36 -04:00
|
|
|
MSG_SYS_STATUS,
|
|
|
|
MSG_POWER_STATUS,
|
2023-10-27 04:16:35 -03:00
|
|
|
#if HAL_WITH_MCU_MONITORING
|
2021-08-23 01:56:22 -03:00
|
|
|
MSG_MCU_STATUS,
|
2023-10-27 04:16:35 -03:00
|
|
|
#endif
|
2018-12-04 01:18:39 -04:00
|
|
|
MSG_MEMINFO,
|
2017-08-21 02:53:45 -03:00
|
|
|
MSG_CURRENT_WAYPOINT,
|
|
|
|
MSG_GPS_RAW,
|
|
|
|
MSG_GPS_RTK,
|
2023-10-25 01:23:59 -03:00
|
|
|
#if GPS_MAX_RECEIVERS > 1
|
2017-08-21 02:53:45 -03:00
|
|
|
MSG_GPS2_RAW,
|
|
|
|
MSG_GPS2_RTK,
|
2023-10-25 01:23:59 -03:00
|
|
|
#endif
|
2017-08-21 02:53:45 -03:00
|
|
|
MSG_NAV_CONTROLLER_OUTPUT,
|
2023-10-03 06:49:34 -03:00
|
|
|
#if AP_FENCE_ENABLED
|
2017-08-21 02:53:45 -03:00
|
|
|
MSG_FENCE_STATUS,
|
2023-10-03 06:49:34 -03:00
|
|
|
#endif
|
2017-08-21 02:53:45 -03:00
|
|
|
MSG_POSITION_TARGET_GLOBAL_INT,
|
|
|
|
};
|
2018-05-21 01:06:49 -03:00
|
|
|
static const ap_message STREAM_POSITION_msgs[] = {
|
2017-08-21 02:53:45 -03:00
|
|
|
MSG_LOCATION,
|
|
|
|
MSG_LOCAL_POSITION
|
|
|
|
};
|
2018-05-21 01:06:49 -03:00
|
|
|
static const ap_message STREAM_RAW_CONTROLLER_msgs[] = {
|
2017-08-21 02:53:45 -03:00
|
|
|
MSG_SERVO_OUT,
|
|
|
|
};
|
2018-05-21 01:06:49 -03:00
|
|
|
static const ap_message STREAM_RC_CHANNELS_msgs[] = {
|
2017-08-21 02:53:45 -03:00
|
|
|
MSG_SERVO_OUTPUT_RAW,
|
2019-07-06 20:02:40 -03:00
|
|
|
MSG_RC_CHANNELS,
|
2024-07-25 03:22:14 -03:00
|
|
|
#if AP_MAVLINK_MSG_RC_CHANNELS_RAW_ENABLED
|
2019-07-06 20:02:40 -03:00
|
|
|
MSG_RC_CHANNELS_RAW, // only sent on a mavlink1 connection
|
2024-07-25 03:22:14 -03:00
|
|
|
#endif
|
2017-08-21 02:53:45 -03:00
|
|
|
};
|
2018-05-21 01:06:49 -03:00
|
|
|
static const ap_message STREAM_EXTRA1_msgs[] = {
|
2017-08-21 02:53:45 -03:00
|
|
|
MSG_ATTITUDE,
|
2023-11-18 20:38:46 -04:00
|
|
|
#if AP_SIM_ENABLED
|
2018-12-18 16:23:19 -04:00
|
|
|
MSG_SIMSTATE,
|
2023-11-18 20:38:46 -04:00
|
|
|
#endif
|
2018-12-18 16:23:19 -04:00
|
|
|
MSG_AHRS2,
|
2022-09-27 22:37:45 -03:00
|
|
|
#if AP_RPM_ENABLED
|
2017-08-21 02:53:45 -03:00
|
|
|
MSG_RPM,
|
2022-09-27 22:37:45 -03:00
|
|
|
#endif
|
2017-08-21 02:53:45 -03:00
|
|
|
MSG_AOA_SSA,
|
|
|
|
MSG_PID_TUNING,
|
2018-06-20 20:51:06 -03:00
|
|
|
MSG_LANDING,
|
2023-10-27 04:24:38 -03:00
|
|
|
#if HAL_WITH_ESC_TELEM
|
2018-06-20 20:51:06 -03:00
|
|
|
MSG_ESC_TELEMETRY,
|
2023-10-27 04:24:38 -03:00
|
|
|
#endif
|
2022-10-21 17:46:05 -03:00
|
|
|
#if HAL_EFI_ENABLED
|
2019-11-09 04:55:05 -04:00
|
|
|
MSG_EFI_STATUS,
|
2022-10-21 17:46:05 -03:00
|
|
|
#endif
|
2022-10-17 05:36:02 -03:00
|
|
|
#if AP_AIRSPEED_HYGROMETER_ENABLE
|
|
|
|
MSG_HYGROMETER,
|
|
|
|
#endif
|
2017-08-21 02:53:45 -03:00
|
|
|
};
|
2018-05-21 01:06:49 -03:00
|
|
|
static const ap_message STREAM_EXTRA2_msgs[] = {
|
2017-08-21 02:53:45 -03:00
|
|
|
MSG_VFR_HUD
|
|
|
|
};
|
2018-05-21 01:06:49 -03:00
|
|
|
static const ap_message STREAM_EXTRA3_msgs[] = {
|
2017-08-21 02:53:45 -03:00
|
|
|
MSG_AHRS,
|
|
|
|
MSG_WIND,
|
2024-02-29 11:57:37 -04:00
|
|
|
#if AP_RANGEFINDER_ENABLED
|
2017-08-21 02:53:45 -03:00
|
|
|
MSG_RANGEFINDER,
|
2024-02-29 11:57:37 -04:00
|
|
|
#endif
|
2018-12-18 06:47:33 -04:00
|
|
|
MSG_DISTANCE_SENSOR,
|
2017-08-21 02:53:45 -03:00
|
|
|
MSG_SYSTEM_TIME,
|
2014-07-24 18:58:39 -03:00
|
|
|
#if AP_TERRAIN_AVAILABLE
|
2017-08-21 02:53:45 -03:00
|
|
|
MSG_TERRAIN,
|
2014-07-21 19:24:00 -03:00
|
|
|
#endif
|
2023-10-24 22:15:02 -03:00
|
|
|
#if AP_BATTERY_ENABLED
|
2017-08-21 02:53:45 -03:00
|
|
|
MSG_BATTERY_STATUS,
|
2023-10-24 22:15:02 -03:00
|
|
|
#endif
|
2023-10-27 04:10:36 -03:00
|
|
|
#if HAL_MOUNT_ENABLED
|
2022-07-11 05:08:20 -03:00
|
|
|
MSG_GIMBAL_DEVICE_ATTITUDE_STATUS,
|
2023-10-27 04:10:36 -03:00
|
|
|
#endif
|
2023-10-27 04:13:07 -03:00
|
|
|
#if AP_OPTICALFLOW_ENABLED
|
2017-08-21 02:53:45 -03:00
|
|
|
MSG_OPTICAL_FLOW,
|
2023-10-27 04:13:07 -03:00
|
|
|
#endif
|
2023-09-20 09:58:20 -03:00
|
|
|
#if COMPASS_CAL_ENABLED
|
2017-08-21 02:53:45 -03:00
|
|
|
MSG_MAG_CAL_REPORT,
|
|
|
|
MSG_MAG_CAL_PROGRESS,
|
2023-09-20 09:58:20 -03:00
|
|
|
#endif
|
2017-08-21 02:53:45 -03:00
|
|
|
MSG_EKF_STATUS_REPORT,
|
|
|
|
MSG_VIBRATION,
|
|
|
|
};
|
2018-05-22 22:23:42 -03:00
|
|
|
static const ap_message STREAM_PARAMS_msgs[] = {
|
|
|
|
MSG_NEXT_PARAM
|
|
|
|
};
|
2018-05-21 01:06:49 -03:00
|
|
|
static const ap_message STREAM_ADSB_msgs[] = {
|
2021-08-14 18:28:16 -03:00
|
|
|
MSG_ADSB_VEHICLE,
|
2023-10-24 22:42:16 -03:00
|
|
|
#if AP_AIS_ENABLED
|
2021-08-14 18:28:16 -03:00
|
|
|
MSG_AIS_VESSEL,
|
2023-10-24 22:42:16 -03:00
|
|
|
#endif
|
2017-08-21 02:53:45 -03:00
|
|
|
};
|
2016-06-15 17:57:48 -03:00
|
|
|
|
2017-08-21 02:53:45 -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_RAW_CONTROLLER),
|
|
|
|
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:42 -03:00
|
|
|
MAV_STREAM_ENTRY(STREAM_PARAMS),
|
2017-08-21 02:53:45 -03:00
|
|
|
MAV_STREAM_ENTRY(STREAM_ADSB),
|
|
|
|
MAV_STREAM_TERMINATOR // must have this at end of stream_entries
|
|
|
|
};
|
2016-06-15 17:57:48 -03:00
|
|
|
|
2014-03-18 19:59:51 -03:00
|
|
|
/*
|
|
|
|
handle a request to switch to guided mode. This happens via a
|
|
|
|
callback from handle_mission_item()
|
|
|
|
*/
|
2016-05-27 09:53:19 -03:00
|
|
|
bool GCS_MAVLINK_Plane::handle_guided_request(AP_Mission::Mission_Command &cmd)
|
2011-09-08 22:29:39 -03:00
|
|
|
{
|
2021-09-27 16:28:39 -03:00
|
|
|
return plane.control_mode->handle_guided_request(cmd.content.location);
|
2014-03-18 19:59:51 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
handle a request to change current WP altitude. This happens via a
|
|
|
|
callback from handle_mission_item()
|
|
|
|
*/
|
2016-05-27 09:53:19 -03:00
|
|
|
void GCS_MAVLINK_Plane::handle_change_alt_request(AP_Mission::Mission_Command &cmd)
|
2014-03-18 19:59:51 -03:00
|
|
|
{
|
2015-05-13 03:09:36 -03:00
|
|
|
plane.next_WP_loc.alt = cmd.content.location.alt;
|
2019-01-02 00:46:09 -04:00
|
|
|
if (cmd.content.location.relative_alt) {
|
2015-05-13 03:09:36 -03:00
|
|
|
plane.next_WP_loc.alt += plane.home.alt;
|
2014-03-18 19:59:51 -03:00
|
|
|
}
|
2019-01-02 00:46:09 -04:00
|
|
|
plane.next_WP_loc.relative_alt = false;
|
|
|
|
plane.next_WP_loc.terrain_alt = cmd.content.location.terrain_alt;
|
2015-05-13 03:09:36 -03:00
|
|
|
plane.reset_offset_altitude();
|
2014-03-18 19:59:51 -03:00
|
|
|
}
|
|
|
|
|
2018-03-17 06:26:03 -03:00
|
|
|
|
2024-03-04 18:32:24 -04:00
|
|
|
/*
|
|
|
|
handle a LANDING_TARGET command. The timestamp has been jitter corrected
|
|
|
|
*/
|
|
|
|
void GCS_MAVLINK_Plane::handle_landing_target(const mavlink_landing_target_t &packet, uint32_t timestamp_ms)
|
|
|
|
{
|
|
|
|
#if AC_PRECLAND_ENABLED
|
|
|
|
plane.g2.precland.handle_msg(packet, timestamp_ms);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-09-07 07:13:30 -03:00
|
|
|
MAV_RESULT GCS_MAVLINK_Plane::handle_command_preflight_calibration(const mavlink_command_int_t &packet, const mavlink_message_t &msg)
|
2018-03-17 06:26:03 -03:00
|
|
|
{
|
|
|
|
plane.in_calibration = true;
|
2022-12-08 02:47:13 -04:00
|
|
|
MAV_RESULT ret = GCS_MAVLINK::handle_command_preflight_calibration(packet, msg);
|
2018-03-17 06:26:03 -03:00
|
|
|
plane.in_calibration = false;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-08-12 16:15:04 -03:00
|
|
|
void GCS_MAVLINK_Plane::packetReceived(const mavlink_status_t &status,
|
2019-04-30 07:22:51 -03:00
|
|
|
const mavlink_message_t &msg)
|
2016-08-12 16:15:04 -03:00
|
|
|
{
|
2020-09-19 05:38:20 -03:00
|
|
|
#if HAL_ADSB_ENABLED
|
2016-08-12 16:15:04 -03:00
|
|
|
plane.avoidance_adsb.handle_msg(msg);
|
2022-01-04 00:53:18 -04:00
|
|
|
#endif
|
2023-08-11 09:27:55 -03:00
|
|
|
#if AP_SCRIPTING_ENABLED && AP_FOLLOW_ENABLED
|
2022-01-04 00:53:18 -04:00
|
|
|
// pass message to follow library
|
|
|
|
plane.g2.follow.handle_msg(msg);
|
2020-09-19 05:38:20 -03:00
|
|
|
#endif
|
2016-08-12 16:15:04 -03:00
|
|
|
GCS_MAVLINK::packetReceived(status, msg);
|
|
|
|
}
|
|
|
|
|
2018-07-04 00:08:22 -03:00
|
|
|
|
2024-04-03 07:40:30 -03:00
|
|
|
bool Plane::set_home_to_current_location(bool _lock)
|
2018-07-05 22:12:54 -03:00
|
|
|
{
|
2024-04-03 07:40:30 -03:00
|
|
|
if (!set_home_persistently(AP::gps().location())) {
|
2018-05-29 20:47:50 -03:00
|
|
|
return false;
|
|
|
|
}
|
2019-09-12 06:06:42 -03:00
|
|
|
if (_lock) {
|
2018-07-05 22:12:54 -03:00
|
|
|
AP::ahrs().lock_home();
|
|
|
|
}
|
2024-04-03 07:40:30 -03:00
|
|
|
if ((control_mode == &mode_rtl)
|
2022-10-15 13:51:17 -03:00
|
|
|
#if HAL_QUADPLANE_ENABLED
|
2024-04-03 07:40:30 -03:00
|
|
|
|| (control_mode == &mode_qrtl)
|
2022-10-15 13:51:17 -03:00
|
|
|
#endif
|
|
|
|
) {
|
|
|
|
// if in RTL head to the updated home location
|
2024-04-03 07:40:30 -03:00
|
|
|
control_mode->enter();
|
2022-10-15 13:51:17 -03:00
|
|
|
}
|
2018-07-05 22:12:54 -03:00
|
|
|
return true;
|
|
|
|
}
|
2024-04-03 07:40:30 -03:00
|
|
|
bool Plane::set_home(const Location& loc, bool _lock)
|
2018-07-05 22:12:54 -03:00
|
|
|
{
|
2018-05-29 20:47:50 -03:00
|
|
|
if (!AP::ahrs().set_home(loc)) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-09-12 06:06:42 -03:00
|
|
|
if (_lock) {
|
2018-07-05 22:12:54 -03:00
|
|
|
AP::ahrs().lock_home();
|
|
|
|
}
|
2024-04-03 07:40:30 -03:00
|
|
|
if ((control_mode == &mode_rtl)
|
2022-10-15 13:51:17 -03:00
|
|
|
#if HAL_QUADPLANE_ENABLED
|
2024-04-03 07:40:30 -03:00
|
|
|
|| (control_mode == &mode_qrtl)
|
2022-10-15 13:51:17 -03:00
|
|
|
#endif
|
|
|
|
) {
|
|
|
|
// if in RTL head to the updated home location
|
2024-04-03 07:40:30 -03:00
|
|
|
control_mode->enter();
|
2022-10-15 13:51:17 -03:00
|
|
|
}
|
2018-07-05 22:12:54 -03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-05 05:47:44 -03:00
|
|
|
MAV_RESULT GCS_MAVLINK_Plane::handle_command_int_do_reposition(const mavlink_command_int_t &packet)
|
2018-07-04 00:14:29 -03:00
|
|
|
{
|
2019-08-05 05:47:44 -03:00
|
|
|
// sanity check location
|
|
|
|
if (!check_latlng(packet.x, packet.y)) {
|
2020-06-30 20:12:04 -03:00
|
|
|
return MAV_RESULT_DENIED;
|
2019-08-05 05:47:44 -03:00
|
|
|
}
|
2018-07-04 00:14:29 -03:00
|
|
|
|
2022-02-02 22:52:29 -04:00
|
|
|
Location requested_position;
|
|
|
|
if (!location_from_command_t(packet, requested_position)) {
|
2020-06-30 20:12:04 -03:00
|
|
|
return MAV_RESULT_DENIED;
|
2019-08-05 05:47:44 -03:00
|
|
|
}
|
2018-07-04 00:14:29 -03:00
|
|
|
|
2023-10-25 22:47:12 -03:00
|
|
|
if (isnan(packet.param4) || is_zero(packet.param4)) {
|
2019-08-05 05:47:44 -03:00
|
|
|
requested_position.loiter_ccw = 0;
|
|
|
|
} else {
|
|
|
|
requested_position.loiter_ccw = 1;
|
|
|
|
}
|
2018-07-04 00:14:29 -03:00
|
|
|
|
2019-08-05 05:47:44 -03:00
|
|
|
if (requested_position.sanitize(plane.current_loc)) {
|
|
|
|
// if the location wasn't already sane don't load it
|
2020-06-30 20:12:04 -03:00
|
|
|
return MAV_RESULT_DENIED;
|
2019-08-05 05:47:44 -03:00
|
|
|
}
|
2018-07-04 00:14:29 -03:00
|
|
|
|
2024-07-16 13:41:09 -03:00
|
|
|
#if AP_FENCE_ENABLED
|
|
|
|
// reject destination if outside the fence
|
|
|
|
if (!plane.fence.check_destination_within_fence(requested_position)) {
|
|
|
|
LOGGER_WRITE_ERROR(LogErrorSubsystem::NAVIGATION, LogErrorCode::DEST_OUTSIDE_FENCE);
|
|
|
|
return MAV_RESULT_DENIED;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-08-05 05:47:44 -03:00
|
|
|
// location is valid load and set
|
|
|
|
if (((int32_t)packet.param2 & MAV_DO_REPOSITION_FLAGS_CHANGE_MODE) ||
|
|
|
|
(plane.control_mode == &plane.mode_guided)) {
|
2019-10-17 00:49:32 -03:00
|
|
|
plane.set_mode(plane.mode_guided, ModeReason::GCS_COMMAND);
|
2019-08-05 05:47:44 -03:00
|
|
|
|
|
|
|
// add home alt if needed
|
2022-02-09 19:44:58 -04:00
|
|
|
if (requested_position.relative_alt) {
|
|
|
|
requested_position.alt += plane.home.alt;
|
|
|
|
requested_position.relative_alt = 0;
|
2018-07-04 00:14:29 -03:00
|
|
|
}
|
|
|
|
|
2022-02-09 19:44:58 -04:00
|
|
|
plane.set_guided_WP(requested_position);
|
2018-07-04 00:14:29 -03:00
|
|
|
|
2022-10-10 18:58:30 -03:00
|
|
|
// Loiter radius for planes. Positive radius in meters, direction is controlled by Yaw (param4) value, parsed above
|
|
|
|
if (!isnan(packet.param3) && packet.param3 > 0) {
|
|
|
|
plane.mode_guided.set_radius_and_direction(packet.param3, requested_position.loiter_ccw);
|
|
|
|
}
|
|
|
|
|
2019-08-05 05:47:44 -03:00
|
|
|
return MAV_RESULT_ACCEPTED;
|
|
|
|
}
|
|
|
|
return MAV_RESULT_FAILED;
|
|
|
|
}
|
2018-07-04 00:14:29 -03:00
|
|
|
|
2020-05-16 01:02:01 -03:00
|
|
|
// these are GUIDED mode commands that are RATE or slew enabled, so you can have more powerful control than default controls.
|
|
|
|
MAV_RESULT GCS_MAVLINK_Plane::handle_command_int_guided_slew_commands(const mavlink_command_int_t &packet)
|
|
|
|
{
|
|
|
|
switch(packet.command) {
|
|
|
|
|
|
|
|
#if OFFBOARD_GUIDED == ENABLED
|
|
|
|
case MAV_CMD_GUIDED_CHANGE_SPEED: {
|
|
|
|
// command is only valid in guided mode
|
|
|
|
if (plane.control_mode != &plane.mode_guided) {
|
|
|
|
return MAV_RESULT_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// only airspeed commands are supported right now...
|
|
|
|
if (int(packet.param1) != SPEED_TYPE_AIRSPEED) { // since SPEED_TYPE is int in range 0-1 and packet.param1 is a *float* this works.
|
|
|
|
return MAV_RESULT_DENIED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// reject airspeeds that are outside of the tuning envelope
|
|
|
|
if (packet.param2 > plane.aparm.airspeed_max || packet.param2 < plane.aparm.airspeed_min) {
|
|
|
|
return MAV_RESULT_DENIED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// no need to process any new packet/s with the
|
|
|
|
// same airspeed any further, if we are already doing it.
|
|
|
|
float new_target_airspeed_cm = packet.param2 * 100;
|
|
|
|
if ( is_equal(new_target_airspeed_cm,plane.guided_state.target_airspeed_cm)) {
|
|
|
|
return MAV_RESULT_ACCEPTED;
|
|
|
|
}
|
|
|
|
plane.guided_state.target_airspeed_cm = new_target_airspeed_cm;
|
|
|
|
plane.guided_state.target_airspeed_time_ms = AP_HAL::millis();
|
|
|
|
|
|
|
|
if (is_zero(packet.param3)) {
|
|
|
|
// the user wanted /maximum acceleration, pick a large value as close enough
|
|
|
|
plane.guided_state.target_airspeed_accel = 1000.0f;
|
|
|
|
} else {
|
|
|
|
plane.guided_state.target_airspeed_accel = fabsf(packet.param3);
|
|
|
|
}
|
|
|
|
|
|
|
|
// assign an acceleration direction
|
|
|
|
if (plane.guided_state.target_airspeed_cm < plane.target_airspeed_cm) {
|
|
|
|
plane.guided_state.target_airspeed_accel *= -1.0f;
|
|
|
|
}
|
|
|
|
return MAV_RESULT_ACCEPTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
case MAV_CMD_GUIDED_CHANGE_ALTITUDE: {
|
|
|
|
// command is only valid in guided
|
|
|
|
if (plane.control_mode != &plane.mode_guided) {
|
|
|
|
return MAV_RESULT_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// disallow default value of -1 and dangerous value of zero
|
|
|
|
if (is_equal(packet.z, -1.0f) || is_equal(packet.z, 0.0f)){
|
|
|
|
return MAV_RESULT_DENIED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// the requested alt data might be relative or absolute
|
|
|
|
float new_target_alt = packet.z * 100;
|
|
|
|
float new_target_alt_rel = packet.z * 100 + plane.home.alt;
|
|
|
|
|
|
|
|
// only global/relative/terrain frames are supported
|
|
|
|
switch(packet.frame) {
|
|
|
|
case MAV_FRAME_GLOBAL_RELATIVE_ALT: {
|
|
|
|
if (is_equal(plane.guided_state.target_alt,new_target_alt_rel) ) { // compare two floats as near-enough
|
|
|
|
// no need to process any new packet/s with the same ALT any further, if we are already doing it.
|
|
|
|
return MAV_RESULT_ACCEPTED;
|
|
|
|
}
|
|
|
|
plane.guided_state.target_alt = new_target_alt_rel;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MAV_FRAME_GLOBAL: {
|
|
|
|
if (is_equal(plane.guided_state.target_alt,new_target_alt) ) { // compare two floats as near-enough
|
|
|
|
// no need to process any new packet/s with the same ALT any further, if we are already doing it.
|
|
|
|
return MAV_RESULT_ACCEPTED;
|
|
|
|
}
|
|
|
|
plane.guided_state.target_alt = new_target_alt;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
// MAV_RESULT_DENIED means Command is invalid (is supported but has invalid parameters).
|
|
|
|
return MAV_RESULT_DENIED;
|
|
|
|
}
|
|
|
|
|
|
|
|
plane.guided_state.target_alt_frame = packet.frame;
|
|
|
|
plane.guided_state.last_target_alt = plane.current_loc.alt; // FIXME: Reference frame is not corrected for here
|
|
|
|
plane.guided_state.target_alt_time_ms = AP_HAL::millis();
|
|
|
|
|
|
|
|
if (is_zero(packet.param3)) {
|
|
|
|
// the user wanted /maximum acceleration, pick a large value as close enough
|
|
|
|
plane.guided_state.target_alt_accel = 1000.0;
|
|
|
|
} else {
|
|
|
|
plane.guided_state.target_alt_accel = fabsf(packet.param3);
|
|
|
|
}
|
|
|
|
|
|
|
|
// assign an acceleration direction
|
|
|
|
if (plane.guided_state.target_alt < plane.current_loc.alt) {
|
|
|
|
plane.guided_state.target_alt_accel *= -1.0f;
|
|
|
|
}
|
|
|
|
return MAV_RESULT_ACCEPTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
case MAV_CMD_GUIDED_CHANGE_HEADING: {
|
|
|
|
|
|
|
|
// command is only valid in guided mode
|
|
|
|
if (plane.control_mode != &plane.mode_guided) {
|
|
|
|
return MAV_RESULT_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// don't accept packets outside of [0-360] degree range
|
|
|
|
if (packet.param2 < 0.0f || packet.param2 >= 360.0f) {
|
|
|
|
return MAV_RESULT_DENIED;
|
|
|
|
}
|
|
|
|
|
|
|
|
float new_target_heading = radians(wrap_180(packet.param2));
|
|
|
|
|
|
|
|
// course over ground
|
|
|
|
if ( int(packet.param1) == HEADING_TYPE_COURSE_OVER_GROUND) { // compare as nearest int
|
|
|
|
plane.guided_state.target_heading_type = GUIDED_HEADING_COG;
|
|
|
|
plane.prev_WP_loc = plane.current_loc;
|
|
|
|
// normal vehicle heading
|
|
|
|
} else if (int(packet.param1) == HEADING_TYPE_HEADING) { // compare as nearest int
|
|
|
|
plane.guided_state.target_heading_type = GUIDED_HEADING_HEADING;
|
|
|
|
} else {
|
|
|
|
// MAV_RESULT_DENIED means Command is invalid (is supported but has invalid parameters).
|
|
|
|
return MAV_RESULT_DENIED;
|
|
|
|
}
|
|
|
|
|
|
|
|
plane.g2.guidedHeading.reset_I();
|
|
|
|
|
|
|
|
plane.guided_state.target_heading = new_target_heading;
|
|
|
|
plane.guided_state.target_heading_accel_limit = MAX(packet.param3, 0.05f);
|
|
|
|
plane.guided_state.target_heading_time_ms = AP_HAL::millis();
|
|
|
|
return MAV_RESULT_ACCEPTED;
|
|
|
|
}
|
|
|
|
#endif // OFFBOARD_GUIDED == ENABLED
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
// anything else ...
|
|
|
|
return MAV_RESULT_UNSUPPORTED;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-08-17 04:53:02 -03:00
|
|
|
MAV_RESULT GCS_MAVLINK_Plane::handle_command_int_packet(const mavlink_command_int_t &packet, const mavlink_message_t &msg)
|
2019-08-05 05:47:44 -03:00
|
|
|
{
|
|
|
|
switch(packet.command) {
|
2018-07-04 00:14:29 -03:00
|
|
|
|
2023-09-20 06:04:24 -03:00
|
|
|
case MAV_CMD_DO_AUTOTUNE_ENABLE:
|
|
|
|
return handle_MAV_CMD_DO_AUTOTUNE_ENABLE(packet);
|
|
|
|
|
2019-08-05 05:47:44 -03:00
|
|
|
case MAV_CMD_DO_REPOSITION:
|
|
|
|
return handle_command_int_do_reposition(packet);
|
2018-07-04 00:14:29 -03:00
|
|
|
|
2020-05-16 01:02:01 -03:00
|
|
|
// special 'slew-enabled' guided commands here... for speed,alt, and direction commands
|
|
|
|
case MAV_CMD_GUIDED_CHANGE_SPEED:
|
|
|
|
case MAV_CMD_GUIDED_CHANGE_ALTITUDE:
|
|
|
|
case MAV_CMD_GUIDED_CHANGE_HEADING:
|
|
|
|
return handle_command_int_guided_slew_commands(packet);
|
|
|
|
|
2023-08-11 09:27:55 -03:00
|
|
|
#if AP_SCRIPTING_ENABLED && AP_FOLLOW_ENABLED
|
2023-07-27 20:53:47 -03:00
|
|
|
case MAV_CMD_DO_FOLLOW:
|
2022-01-04 00:53:18 -04:00
|
|
|
// param1: sysid of target to follow
|
|
|
|
if ((packet.param1 > 0) && (packet.param1 <= 255)) {
|
|
|
|
plane.g2.follow.set_target_sysid((uint8_t)packet.param1);
|
|
|
|
return MAV_RESULT_ACCEPTED;
|
|
|
|
}
|
2023-07-27 20:53:47 -03:00
|
|
|
return MAV_RESULT_DENIED;
|
2022-01-04 00:53:18 -04:00
|
|
|
#endif
|
2023-07-27 20:53:47 -03:00
|
|
|
|
2023-08-24 23:35:18 -03:00
|
|
|
#if AP_ICENGINE_ENABLED
|
|
|
|
case MAV_CMD_DO_ENGINE_CONTROL:
|
2021-07-19 20:54:33 -03:00
|
|
|
if (!plane.g2.ice_control.engine_control(packet.param1, packet.param2, packet.param3, (uint32_t)packet.param4)) {
|
2023-08-24 23:35:18 -03:00
|
|
|
return MAV_RESULT_FAILED;
|
|
|
|
}
|
|
|
|
return MAV_RESULT_ACCEPTED;
|
|
|
|
#endif
|
|
|
|
|
2023-08-29 18:41:10 -03:00
|
|
|
case MAV_CMD_DO_CHANGE_SPEED:
|
|
|
|
return handle_command_DO_CHANGE_SPEED(packet);
|
|
|
|
|
2023-09-19 05:37:08 -03:00
|
|
|
#if PARACHUTE == ENABLED
|
|
|
|
case MAV_CMD_DO_PARACHUTE:
|
|
|
|
return handle_MAV_CMD_DO_PARACHUTE(packet);
|
|
|
|
#endif
|
|
|
|
|
2023-09-11 23:46:10 -03:00
|
|
|
#if HAL_QUADPLANE_ENABLED
|
2023-09-13 20:53:58 -03:00
|
|
|
case MAV_CMD_DO_MOTOR_TEST:
|
|
|
|
return handle_MAV_CMD_DO_MOTOR_TEST(packet);
|
|
|
|
|
2023-09-11 23:46:10 -03:00
|
|
|
case MAV_CMD_DO_VTOL_TRANSITION:
|
|
|
|
return handle_command_DO_VTOL_TRANSITION(packet);
|
2023-10-18 03:30:32 -03:00
|
|
|
|
|
|
|
case MAV_CMD_NAV_TAKEOFF:
|
|
|
|
return handle_command_MAV_CMD_NAV_TAKEOFF(packet);
|
2023-09-11 23:46:10 -03:00
|
|
|
#endif
|
|
|
|
|
2023-09-26 02:56:43 -03:00
|
|
|
case MAV_CMD_DO_GO_AROUND:
|
|
|
|
return plane.trigger_land_abort(packet.param1) ? MAV_RESULT_ACCEPTED : MAV_RESULT_FAILED;
|
|
|
|
|
2023-09-27 20:27:26 -03:00
|
|
|
case MAV_CMD_DO_LAND_START:
|
|
|
|
// attempt to switch to next DO_LAND_START command in the mission
|
2024-03-27 14:58:24 -03:00
|
|
|
if (plane.have_position && plane.mission.jump_to_landing_sequence(plane.current_loc)) {
|
2023-09-27 20:27:26 -03:00
|
|
|
plane.set_mode(plane.mode_auto, ModeReason::GCS_COMMAND);
|
|
|
|
return MAV_RESULT_ACCEPTED;
|
|
|
|
}
|
|
|
|
return MAV_RESULT_FAILED;
|
|
|
|
|
2023-10-04 09:34:41 -03:00
|
|
|
case MAV_CMD_MISSION_START:
|
|
|
|
plane.set_mode(plane.mode_auto, ModeReason::GCS_COMMAND);
|
|
|
|
return MAV_RESULT_ACCEPTED;
|
|
|
|
|
2023-10-11 08:20:45 -03:00
|
|
|
case MAV_CMD_NAV_LOITER_UNLIM:
|
|
|
|
plane.set_mode(plane.mode_loiter, ModeReason::GCS_COMMAND);
|
|
|
|
return MAV_RESULT_ACCEPTED;
|
|
|
|
|
|
|
|
case MAV_CMD_NAV_RETURN_TO_LAUNCH:
|
|
|
|
plane.set_mode(plane.mode_rtl, ModeReason::GCS_COMMAND);
|
|
|
|
return MAV_RESULT_ACCEPTED;
|
|
|
|
|
2024-07-10 22:33:01 -03:00
|
|
|
#if AP_MAVLINK_MAV_CMD_SET_HAGL_ENABLED
|
|
|
|
case MAV_CMD_SET_HAGL:
|
|
|
|
plane.handle_external_hagl(packet);
|
|
|
|
return MAV_RESULT_ACCEPTED;
|
|
|
|
#endif
|
|
|
|
|
2018-07-04 00:14:29 -03:00
|
|
|
default:
|
2023-08-17 04:53:02 -03:00
|
|
|
return GCS_MAVLINK::handle_command_int_packet(packet, msg);
|
2018-07-04 00:14:29 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-29 18:41:10 -03:00
|
|
|
MAV_RESULT GCS_MAVLINK_Plane::handle_command_DO_CHANGE_SPEED(const mavlink_command_int_t &packet)
|
2018-07-04 00:08:22 -03:00
|
|
|
{
|
|
|
|
// if we're in failsafe modes (e.g., RTL, LOITER) or in pilot
|
|
|
|
// controlled modes (e.g., MANUAL, TRAINING)
|
|
|
|
// this command should be ignored since it comes in from GCS
|
|
|
|
// or a companion computer:
|
2020-09-22 14:00:39 -03:00
|
|
|
if ((!plane.control_mode->is_guided_mode()) &&
|
|
|
|
(plane.control_mode != &plane.mode_auto)) {
|
2018-07-04 00:08:22 -03:00
|
|
|
// failed
|
|
|
|
return MAV_RESULT_FAILED;
|
|
|
|
}
|
|
|
|
|
2023-08-29 18:41:10 -03:00
|
|
|
if (plane.do_change_speed(packet.param1, packet.param2, packet.param3)) {
|
2018-07-04 00:08:22 -03:00
|
|
|
return MAV_RESULT_ACCEPTED;
|
|
|
|
}
|
|
|
|
return MAV_RESULT_FAILED;
|
2023-08-29 18:41:10 -03:00
|
|
|
}
|
|
|
|
|
2023-10-18 03:30:32 -03:00
|
|
|
#if HAL_QUADPLANE_ENABLED
|
2023-11-26 17:08:23 -04:00
|
|
|
#if AP_MAVLINK_COMMAND_LONG_ENABLED
|
2023-10-18 03:30:32 -03:00
|
|
|
void GCS_MAVLINK_Plane::convert_MAV_CMD_NAV_TAKEOFF_to_COMMAND_INT(const mavlink_command_long_t &in, mavlink_command_int_t &out)
|
2023-08-29 18:41:10 -03:00
|
|
|
{
|
2023-10-18 03:30:32 -03:00
|
|
|
// convert to MAV_FRAME_LOCAL_OFFSET_NED, "NED local tangent frame
|
|
|
|
// with origin that travels with the vehicle"
|
|
|
|
out = {};
|
|
|
|
out.target_system = in.target_system;
|
|
|
|
out.target_component = in.target_component;
|
|
|
|
out.frame = MAV_FRAME_LOCAL_OFFSET_NED;
|
|
|
|
out.command = in.command;
|
|
|
|
// out.current = 0;
|
|
|
|
// out.autocontinue = 0;
|
|
|
|
// out.param1 = in.param1; // we only use the "z" parameter in this command:
|
|
|
|
// out.param2 = in.param2;
|
|
|
|
// out.param3 = in.param3;
|
|
|
|
// out.param4 = in.param4;
|
|
|
|
// out.x = 0; // we don't handle positioning when doing takeoffs
|
|
|
|
// out.y = 0;
|
|
|
|
out.z = -in.param7; // up -> down
|
|
|
|
}
|
2018-07-04 00:08:22 -03:00
|
|
|
|
2023-10-18 03:30:32 -03:00
|
|
|
void GCS_MAVLINK_Plane::convert_COMMAND_LONG_to_COMMAND_INT(const mavlink_command_long_t &in, mavlink_command_int_t &out, MAV_FRAME frame)
|
|
|
|
{
|
|
|
|
switch (in.command) {
|
|
|
|
case MAV_CMD_NAV_TAKEOFF:
|
|
|
|
convert_MAV_CMD_NAV_TAKEOFF_to_COMMAND_INT(in, out);
|
|
|
|
return;
|
2018-07-04 00:08:22 -03:00
|
|
|
}
|
2023-10-18 03:30:32 -03:00
|
|
|
return GCS_MAVLINK::convert_COMMAND_LONG_to_COMMAND_INT(in, out, frame);
|
|
|
|
}
|
2023-11-08 06:31:03 -04:00
|
|
|
#endif // AP_MAVLINK_COMMAND_LONG_ENABLED
|
2018-07-04 00:08:22 -03:00
|
|
|
|
2023-10-18 03:30:32 -03:00
|
|
|
MAV_RESULT GCS_MAVLINK_Plane::handle_command_MAV_CMD_NAV_TAKEOFF(const mavlink_command_int_t &packet)
|
|
|
|
{
|
|
|
|
float takeoff_alt = packet.z;
|
|
|
|
switch (packet.frame) {
|
|
|
|
case MAV_FRAME_LOCAL_OFFSET_NED: // "NED local tangent frame with origin that travels with the vehicle"
|
|
|
|
takeoff_alt = -takeoff_alt; // down -> up
|
|
|
|
break;
|
2023-09-19 05:37:08 -03:00
|
|
|
default:
|
2023-10-18 03:30:32 -03:00
|
|
|
return MAV_RESULT_DENIED; // "is supported but has invalid parameters"
|
2023-09-19 05:37:08 -03:00
|
|
|
}
|
2023-10-18 03:30:32 -03:00
|
|
|
if (!plane.quadplane.available()) {
|
|
|
|
return MAV_RESULT_FAILED;
|
|
|
|
}
|
|
|
|
if (!plane.quadplane.do_user_takeoff(takeoff_alt)) {
|
|
|
|
return MAV_RESULT_FAILED;
|
|
|
|
}
|
|
|
|
return MAV_RESULT_ACCEPTED;
|
2023-09-19 05:37:08 -03:00
|
|
|
}
|
2023-10-18 03:30:32 -03:00
|
|
|
#endif
|
2023-09-19 05:37:08 -03:00
|
|
|
|
2023-09-20 06:04:24 -03:00
|
|
|
MAV_RESULT GCS_MAVLINK_Plane::handle_MAV_CMD_DO_AUTOTUNE_ENABLE(const mavlink_command_int_t &packet)
|
|
|
|
{
|
|
|
|
// param1 : enable/disable
|
|
|
|
plane.autotune_enable(!is_zero(packet.param1));
|
|
|
|
return MAV_RESULT_ACCEPTED;
|
|
|
|
}
|
|
|
|
|
2018-07-04 00:08:22 -03:00
|
|
|
#if PARACHUTE == ENABLED
|
2023-09-19 05:37:08 -03:00
|
|
|
MAV_RESULT GCS_MAVLINK_Plane::handle_MAV_CMD_DO_PARACHUTE(const mavlink_command_int_t &packet)
|
|
|
|
{
|
2018-07-04 00:08:22 -03:00
|
|
|
// configure or release parachute
|
|
|
|
switch ((uint16_t)packet.param1) {
|
|
|
|
case PARACHUTE_DISABLE:
|
|
|
|
plane.parachute.enabled(false);
|
|
|
|
return MAV_RESULT_ACCEPTED;
|
|
|
|
case PARACHUTE_ENABLE:
|
|
|
|
plane.parachute.enabled(true);
|
|
|
|
return MAV_RESULT_ACCEPTED;
|
|
|
|
case PARACHUTE_RELEASE:
|
|
|
|
// treat as a manual release which performs some additional check of altitude
|
|
|
|
if (plane.parachute.released()) {
|
|
|
|
gcs().send_text(MAV_SEVERITY_NOTICE, "Parachute already released");
|
|
|
|
return MAV_RESULT_FAILED;
|
|
|
|
}
|
|
|
|
if (!plane.parachute.enabled()) {
|
|
|
|
gcs().send_text(MAV_SEVERITY_NOTICE, "Parachute not enabled");
|
|
|
|
return MAV_RESULT_FAILED;
|
|
|
|
}
|
|
|
|
if (!plane.parachute_manual_release()) {
|
|
|
|
return MAV_RESULT_FAILED;
|
|
|
|
}
|
|
|
|
return MAV_RESULT_ACCEPTED;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return MAV_RESULT_FAILED;
|
2023-09-19 05:37:08 -03:00
|
|
|
}
|
2018-07-04 00:08:22 -03:00
|
|
|
#endif
|
|
|
|
|
2023-09-13 20:53:58 -03:00
|
|
|
|
2021-09-10 03:28:21 -03:00
|
|
|
#if HAL_QUADPLANE_ENABLED
|
2023-09-13 20:53:58 -03:00
|
|
|
MAV_RESULT GCS_MAVLINK_Plane::handle_MAV_CMD_DO_MOTOR_TEST(const mavlink_command_int_t &packet)
|
|
|
|
{
|
2018-07-04 00:08:22 -03:00
|
|
|
// 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)
|
|
|
|
// param5 : motor count (number of motors to test in sequence)
|
|
|
|
return plane.quadplane.mavlink_motor_test_start(chan,
|
|
|
|
(uint8_t)packet.param1,
|
|
|
|
(uint8_t)packet.param2,
|
|
|
|
(uint16_t)packet.param3,
|
|
|
|
packet.param4,
|
2023-09-13 20:53:58 -03:00
|
|
|
(uint8_t)packet.x);
|
2018-07-04 00:08:22 -03:00
|
|
|
}
|
|
|
|
|
2023-09-11 23:46:10 -03:00
|
|
|
MAV_RESULT GCS_MAVLINK_Plane::handle_command_DO_VTOL_TRANSITION(const mavlink_command_int_t &packet)
|
|
|
|
{
|
|
|
|
if (!plane.quadplane.handle_do_vtol_transition((enum MAV_VTOL_STATE)packet.param1)) {
|
|
|
|
return MAV_RESULT_FAILED;
|
|
|
|
}
|
|
|
|
return MAV_RESULT_ACCEPTED;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-11-21 23:35:46 -04:00
|
|
|
// this is called on receipt of a MANUAL_CONTROL packet and is
|
|
|
|
// expected to call manual_override to override RC input on desired
|
|
|
|
// axes.
|
|
|
|
void GCS_MAVLINK_Plane::handle_manual_control_axes(const mavlink_manual_control_t &packet, const uint32_t tnow)
|
|
|
|
{
|
|
|
|
manual_override(plane.channel_roll, packet.y, 1000, 2000, tnow);
|
|
|
|
manual_override(plane.channel_pitch, packet.x, 1000, 2000, tnow, true);
|
|
|
|
manual_override(plane.channel_throttle, packet.z, 0, 1000, tnow);
|
|
|
|
manual_override(plane.channel_rudder, packet.r, 1000, 2000, tnow);
|
|
|
|
}
|
|
|
|
|
2024-01-23 02:41:49 -04:00
|
|
|
void GCS_MAVLINK_Plane::handle_message(const mavlink_message_t &msg)
|
2014-03-18 19:59:51 -03:00
|
|
|
{
|
2019-04-30 07:22:51 -03:00
|
|
|
switch (msg.msgid) {
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2014-07-21 19:24:00 -03:00
|
|
|
case MAVLINK_MSG_ID_TERRAIN_DATA:
|
2014-07-22 05:08:03 -03:00
|
|
|
case MAVLINK_MSG_ID_TERRAIN_CHECK:
|
2014-07-24 18:58:39 -03:00
|
|
|
#if AP_TERRAIN_AVAILABLE
|
2015-05-13 03:09:36 -03:00
|
|
|
plane.terrain.handle_data(chan, msg);
|
2014-07-21 19:24:00 -03:00
|
|
|
#endif
|
|
|
|
break;
|
2015-02-11 04:52:50 -04:00
|
|
|
|
2016-05-09 11:34:11 -03:00
|
|
|
case MAVLINK_MSG_ID_SET_ATTITUDE_TARGET:
|
2024-01-23 19:09:23 -04:00
|
|
|
handle_set_attitude_target(msg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAVLINK_MSG_ID_SET_POSITION_TARGET_LOCAL_NED:
|
|
|
|
handle_set_position_target_local_ned(msg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAVLINK_MSG_ID_SET_POSITION_TARGET_GLOBAL_INT:
|
|
|
|
handle_set_position_target_global_int(msg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
GCS_MAVLINK::handle_message(msg);
|
|
|
|
break;
|
|
|
|
} // end switch
|
|
|
|
} // end handle mavlink
|
|
|
|
|
|
|
|
void GCS_MAVLINK_Plane::handle_set_attitude_target(const mavlink_message_t &msg)
|
2016-05-09 11:34:11 -03:00
|
|
|
{
|
2016-06-30 11:48:37 -03:00
|
|
|
// Only allow companion computer (or other external controller) to
|
|
|
|
// control attitude in GUIDED mode. We DON'T want external control
|
|
|
|
// in e.g., RTL, CICLE. Specifying a single mode for companion
|
|
|
|
// computer control is more safe (even more so when using
|
|
|
|
// FENCE_ACTION = 4 for geofence failures).
|
2020-04-30 03:12:49 -03:00
|
|
|
if (plane.control_mode != &plane.mode_guided) { // don't screw up failsafes
|
2024-01-23 19:09:23 -04:00
|
|
|
return;
|
2016-05-09 11:34:11 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
mavlink_set_attitude_target_t att_target;
|
2019-04-30 07:22:51 -03:00
|
|
|
mavlink_msg_set_attitude_target_decode(&msg, &att_target);
|
2016-05-09 11:34:11 -03:00
|
|
|
|
2016-06-30 12:50:17 -03:00
|
|
|
// Mappings: If any of these bits are set, the corresponding input should be ignored.
|
|
|
|
// NOTE, when parsing the bits we invert them for easier interpretation but transport has them inverted
|
|
|
|
// bit 1: body roll rate
|
|
|
|
// bit 2: body pitch rate
|
|
|
|
// bit 3: body yaw rate
|
|
|
|
// bit 4: unknown
|
|
|
|
// bit 5: unknown
|
|
|
|
// bit 6: reserved
|
|
|
|
// bit 7: throttle
|
|
|
|
// bit 8: attitude
|
2016-05-09 11:34:11 -03:00
|
|
|
|
2016-06-30 12:50:17 -03:00
|
|
|
// if not setting all Quaternion values, use _rate flags to indicate which fields.
|
|
|
|
|
|
|
|
// Extract the Euler roll angle from the Quaternion.
|
|
|
|
Quaternion q(att_target.q[0], att_target.q[1],
|
|
|
|
att_target.q[2], att_target.q[3]);
|
|
|
|
|
|
|
|
// NOTE: att_target.type_mask is inverted for easier interpretation
|
|
|
|
att_target.type_mask = att_target.type_mask ^ 0xFF;
|
|
|
|
|
|
|
|
uint8_t attitude_mask = att_target.type_mask & 0b10000111; // q plus rpy
|
|
|
|
|
|
|
|
uint32_t now = AP_HAL::millis();
|
|
|
|
if ((attitude_mask & 0b10000001) || // partial, including roll
|
|
|
|
(attitude_mask == 0b10000000)) { // all angles
|
|
|
|
plane.guided_state.forced_rpy_cd.x = degrees(q.get_euler_roll()) * 100.0f;
|
2016-05-09 11:34:11 -03:00
|
|
|
|
2016-06-30 11:48:37 -03:00
|
|
|
// Update timer for external roll to the nav control
|
2016-06-30 12:50:17 -03:00
|
|
|
plane.guided_state.last_forced_rpy_ms.x = now;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((attitude_mask & 0b10000010) || // partial, including pitch
|
|
|
|
(attitude_mask == 0b10000000)) { // all angles
|
|
|
|
plane.guided_state.forced_rpy_cd.y = degrees(q.get_euler_pitch()) * 100.0f;
|
|
|
|
|
|
|
|
// Update timer for external pitch to the nav control
|
|
|
|
plane.guided_state.last_forced_rpy_ms.y = now;
|
2016-05-09 11:34:11 -03:00
|
|
|
}
|
2016-06-30 12:50:17 -03:00
|
|
|
|
|
|
|
if ((attitude_mask & 0b10000100) || // partial, including yaw
|
|
|
|
(attitude_mask == 0b10000000)) { // all angles
|
|
|
|
plane.guided_state.forced_rpy_cd.z = degrees(q.get_euler_yaw()) * 100.0f;
|
|
|
|
|
|
|
|
// Update timer for external yaw to the nav control
|
|
|
|
plane.guided_state.last_forced_rpy_ms.z = now;
|
|
|
|
}
|
|
|
|
if (att_target.type_mask & 0b01000000) { // throttle
|
|
|
|
plane.guided_state.forced_throttle = att_target.thrust * 100.0f;
|
|
|
|
|
|
|
|
// Update timer for external throttle
|
|
|
|
plane.guided_state.last_forced_throttle_ms = now;
|
|
|
|
}
|
2016-05-09 11:34:11 -03:00
|
|
|
}
|
|
|
|
|
2024-01-23 19:07:19 -04:00
|
|
|
void GCS_MAVLINK_Plane::handle_set_position_target_local_ned(const mavlink_message_t &msg)
|
2017-09-11 00:22:18 -03: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);
|
2017-09-11 00:22:18 -03:00
|
|
|
|
|
|
|
// exit if vehicle is not in Guided mode
|
2019-01-15 13:46:13 -04:00
|
|
|
if (plane.control_mode != &plane.mode_guided) {
|
2024-01-23 19:07:19 -04:00
|
|
|
return;
|
2017-09-11 00:22:18 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// only local moves for now
|
|
|
|
if (packet.coordinate_frame != MAV_FRAME_LOCAL_OFFSET_NED) {
|
2024-01-23 19:07:19 -04:00
|
|
|
return;
|
2017-09-11 00:22:18 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// just do altitude for now
|
|
|
|
plane.next_WP_loc.alt += -packet.z*100.0;
|
|
|
|
gcs().send_text(MAV_SEVERITY_INFO, "Change alt to %.1f",
|
2017-09-19 22:02:58 -03:00
|
|
|
(double)((plane.next_WP_loc.alt - plane.home.alt)*0.01));
|
2017-09-11 00:22:18 -03:00
|
|
|
}
|
|
|
|
|
2024-01-23 18:58:17 -04:00
|
|
|
void GCS_MAVLINK_Plane::handle_set_position_target_global_int(const mavlink_message_t &msg)
|
2016-05-09 11:08:21 -03:00
|
|
|
{
|
2016-06-07 12:27:40 -03:00
|
|
|
// Only want to allow companion computer position control when
|
2016-05-09 11:08:21 -03:00
|
|
|
// in a certain mode to avoid inadvertently sending these
|
|
|
|
// kinds of commands when the autopilot is responding to problems
|
|
|
|
// in modes such as RTL, CIRCLE, etc. Specifying ONLY one mode
|
|
|
|
// for companion computer control is more safe (provided
|
|
|
|
// one uses the FENCE_ACTION = 4 (RTL) for geofence failures).
|
2020-04-30 03:12:49 -03:00
|
|
|
if (plane.control_mode != &plane.mode_guided) {
|
2016-06-07 12:27:40 -03:00
|
|
|
//don't screw up failsafes
|
2024-01-23 18:58:17 -04:00
|
|
|
return;
|
2016-05-09 11:08:21 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
mavlink_set_position_target_global_int_t pos_target;
|
2019-04-30 07:22:51 -03:00
|
|
|
mavlink_msg_set_position_target_global_int_decode(&msg, &pos_target);
|
2016-06-07 12:27:40 -03:00
|
|
|
// Unexpectedly, the mask is expecting "ones" for dimensions that should
|
|
|
|
// be IGNORNED rather than INCLUDED. See mavlink documentation of the
|
|
|
|
// SET_POSITION_TARGET_GLOBAL_INT message, type_mask field.
|
2016-05-09 11:08:21 -03:00
|
|
|
const uint16_t alt_mask = 0b1111111111111011; // (z mask at bit 3)
|
|
|
|
|
|
|
|
bool msg_valid = true;
|
|
|
|
AP_Mission::Mission_Command cmd = {0};
|
|
|
|
|
|
|
|
if (pos_target.type_mask & alt_mask)
|
|
|
|
{
|
|
|
|
cmd.content.location.alt = pos_target.alt * 100;
|
2019-01-02 00:46:09 -04:00
|
|
|
cmd.content.location.relative_alt = false;
|
|
|
|
cmd.content.location.terrain_alt = false;
|
2016-05-09 11:08:21 -03:00
|
|
|
switch (pos_target.coordinate_frame)
|
|
|
|
{
|
2019-07-26 22:34:46 -03:00
|
|
|
case MAV_FRAME_GLOBAL:
|
2016-05-09 11:08:21 -03:00
|
|
|
case MAV_FRAME_GLOBAL_INT:
|
|
|
|
break; //default to MSL altitude
|
2024-03-07 06:31:27 -04:00
|
|
|
case MAV_FRAME_GLOBAL_RELATIVE_ALT:
|
2016-05-09 11:08:21 -03:00
|
|
|
case MAV_FRAME_GLOBAL_RELATIVE_ALT_INT:
|
2019-01-01 23:25:29 -04:00
|
|
|
cmd.content.location.relative_alt = true;
|
2016-05-09 11:08:21 -03:00
|
|
|
break;
|
2024-03-07 06:31:27 -04:00
|
|
|
case MAV_FRAME_GLOBAL_TERRAIN_ALT:
|
2016-05-09 11:08:21 -03:00
|
|
|
case MAV_FRAME_GLOBAL_TERRAIN_ALT_INT:
|
2019-01-01 23:25:29 -04:00
|
|
|
cmd.content.location.relative_alt = true;
|
2019-01-02 00:46:09 -04:00
|
|
|
cmd.content.location.terrain_alt = true;
|
2016-05-09 11:08:21 -03:00
|
|
|
break;
|
|
|
|
default:
|
2017-07-08 22:15:58 -03:00
|
|
|
gcs().send_text(MAV_SEVERITY_WARNING, "Invalid coord frame in SET_POSTION_TARGET_GLOBAL_INT");
|
2016-05-09 11:08:21 -03:00
|
|
|
msg_valid = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msg_valid) {
|
|
|
|
handle_change_alt_request(cmd);
|
|
|
|
}
|
|
|
|
} // end if alt_mask
|
|
|
|
}
|
|
|
|
|
2023-11-14 04:22:14 -04:00
|
|
|
MAV_RESULT GCS_MAVLINK_Plane::handle_command_do_set_mission_current(const mavlink_command_int_t &packet)
|
2021-02-23 00:05:09 -04:00
|
|
|
{
|
|
|
|
const MAV_RESULT result = GCS_MAVLINK::handle_command_do_set_mission_current(packet);
|
|
|
|
if (result != MAV_RESULT_ACCEPTED) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if you change this you must change handle_mission_set_current
|
|
|
|
plane.auto_state.next_wp_crosstrack = false;
|
|
|
|
if (plane.control_mode == &plane.mode_auto && plane.mission.state() == AP_Mission::MISSION_STOPPED) {
|
|
|
|
plane.mission.resume();
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-03-16 03:14:28 -03:00
|
|
|
#if AP_MAVLINK_MISSION_SET_CURRENT_ENABLED
|
2019-04-30 07:22:51 -03:00
|
|
|
void GCS_MAVLINK_Plane::handle_mission_set_current(AP_Mission &mission, const mavlink_message_t &msg)
|
2017-07-08 00:12:52 -03:00
|
|
|
{
|
2021-02-23 00:05:09 -04:00
|
|
|
// if you change this you must change handle_command_do_set_mission_current
|
2017-11-21 15:41:45 -04:00
|
|
|
plane.auto_state.next_wp_crosstrack = false;
|
2017-07-08 00:12:52 -03:00
|
|
|
GCS_MAVLINK::handle_mission_set_current(mission, msg);
|
2019-01-15 13:46:13 -04:00
|
|
|
if (plane.control_mode == &plane.mode_auto && plane.mission.state() == AP_Mission::MISSION_STOPPED) {
|
2017-07-08 00:12:52 -03:00
|
|
|
plane.mission.resume();
|
|
|
|
}
|
|
|
|
}
|
2023-03-16 03:14:28 -03:00
|
|
|
#endif
|
2017-07-12 21:48:41 -03:00
|
|
|
|
2018-03-28 22:03:57 -03:00
|
|
|
uint64_t GCS_MAVLINK_Plane::capabilities() const
|
|
|
|
{
|
|
|
|
return (MAV_PROTOCOL_CAPABILITY_MISSION_FLOAT |
|
|
|
|
MAV_PROTOCOL_CAPABILITY_COMMAND_INT |
|
|
|
|
MAV_PROTOCOL_CAPABILITY_MISSION_INT |
|
|
|
|
MAV_PROTOCOL_CAPABILITY_SET_POSITION_TARGET_GLOBAL_INT |
|
|
|
|
MAV_PROTOCOL_CAPABILITY_SET_ATTITUDE_TARGET |
|
|
|
|
#if AP_TERRAIN_AVAILABLE
|
|
|
|
(plane.terrain.enabled() ? MAV_PROTOCOL_CAPABILITY_TERRAIN : 0) |
|
|
|
|
#endif
|
|
|
|
GCS_MAVLINK::capabilities());
|
|
|
|
}
|
2021-07-06 07:30:59 -03:00
|
|
|
|
|
|
|
#if HAL_HIGH_LATENCY2_ENABLED
|
|
|
|
int16_t GCS_MAVLINK_Plane::high_latency_target_altitude() const
|
|
|
|
{
|
|
|
|
AP_AHRS &ahrs = AP::ahrs();
|
2023-02-02 18:58:40 -04:00
|
|
|
Location global_position_current;
|
2022-01-20 19:42:41 -04:00
|
|
|
UNUSED_RESULT(ahrs.get_location(global_position_current));
|
2021-07-06 07:30:59 -03:00
|
|
|
|
2021-09-10 03:28:21 -03:00
|
|
|
#if HAL_QUADPLANE_ENABLED
|
2021-07-06 07:30:59 -03:00
|
|
|
const QuadPlane &quadplane = plane.quadplane;
|
|
|
|
//return units are m
|
|
|
|
if (quadplane.show_vtol_view()) {
|
|
|
|
return (plane.control_mode != &plane.mode_qstabilize) ? 0.01 * (global_position_current.alt + quadplane.pos_control->get_pos_error_z_cm()) : 0;
|
|
|
|
}
|
2021-09-10 03:28:21 -03:00
|
|
|
#endif
|
2024-05-06 04:01:08 -03:00
|
|
|
return 0.01 * (global_position_current.alt + plane.calc_altitude_error_cm());
|
2021-07-06 07:30:59 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t GCS_MAVLINK_Plane::high_latency_tgt_heading() const
|
|
|
|
{
|
|
|
|
// return units are deg/2
|
2021-09-10 03:28:21 -03:00
|
|
|
#if HAL_QUADPLANE_ENABLED
|
2021-07-06 07:30:59 -03:00
|
|
|
const QuadPlane &quadplane = plane.quadplane;
|
|
|
|
if (quadplane.show_vtol_view()) {
|
|
|
|
const Vector3f &targets = quadplane.attitude_control->get_att_target_euler_cd();
|
|
|
|
return ((uint16_t)(targets.z * 0.01)) / 2;
|
2021-09-10 03:28:21 -03:00
|
|
|
}
|
|
|
|
#endif
|
2021-07-06 07:30:59 -03:00
|
|
|
const AP_Navigation *nav_controller = plane.nav_controller;
|
|
|
|
// need to convert -18000->18000 to 0->360/2
|
|
|
|
return wrap_360_cd(nav_controller->target_bearing_cd() ) / 200;
|
|
|
|
}
|
2021-09-10 03:28:21 -03:00
|
|
|
|
|
|
|
// return units are dm
|
2021-07-06 07:30:59 -03:00
|
|
|
uint16_t GCS_MAVLINK_Plane::high_latency_tgt_dist() const
|
|
|
|
{
|
2021-09-10 03:28:21 -03:00
|
|
|
#if HAL_QUADPLANE_ENABLED
|
2021-07-06 07:30:59 -03:00
|
|
|
const QuadPlane &quadplane = plane.quadplane;
|
|
|
|
if (quadplane.show_vtol_view()) {
|
|
|
|
bool wp_nav_valid = quadplane.using_wp_nav();
|
|
|
|
return (wp_nav_valid ? MIN(quadplane.wp_nav->get_wp_distance_to_destination(), UINT16_MAX) : 0) / 10;
|
|
|
|
}
|
2021-09-10 03:28:21 -03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return MIN(plane.auto_state.wp_distance, UINT16_MAX) / 10;
|
2021-07-06 07:30:59 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t GCS_MAVLINK_Plane::high_latency_tgt_airspeed() const
|
|
|
|
{
|
|
|
|
// return units are m/s*5
|
|
|
|
return plane.target_airspeed_cm * 0.05;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t GCS_MAVLINK_Plane::high_latency_wind_speed() const
|
|
|
|
{
|
|
|
|
Vector3f wind;
|
|
|
|
wind = AP::ahrs().wind_estimate();
|
|
|
|
|
|
|
|
// return units are m/s*5
|
|
|
|
return MIN(wind.length() * 5, UINT8_MAX);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t GCS_MAVLINK_Plane::high_latency_wind_direction() const
|
|
|
|
{
|
|
|
|
const Vector3f wind = AP::ahrs().wind_estimate();
|
|
|
|
|
|
|
|
// return units are deg/2
|
|
|
|
// need to convert -180->180 to 0->360/2
|
|
|
|
return wrap_360(degrees(atan2f(-wind.y, -wind.x))) / 2;
|
|
|
|
}
|
2021-08-06 01:34:29 -03:00
|
|
|
#endif // HAL_HIGH_LATENCY2_ENABLED
|
2018-05-23 06:32:35 -03:00
|
|
|
|
|
|
|
MAV_VTOL_STATE GCS_MAVLINK_Plane::vtol_state() const
|
|
|
|
{
|
|
|
|
#if !HAL_QUADPLANE_ENABLED
|
|
|
|
return MAV_VTOL_STATE_UNDEFINED;
|
|
|
|
#else
|
|
|
|
if (!plane.quadplane.available()) {
|
|
|
|
return MAV_VTOL_STATE_UNDEFINED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return plane.quadplane.transition->get_mav_vtol_state();
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
MAV_LANDED_STATE GCS_MAVLINK_Plane::landed_state() const
|
|
|
|
{
|
|
|
|
if (plane.is_flying()) {
|
|
|
|
// note that Q-modes almost always consider themselves as flying
|
|
|
|
return MAV_LANDED_STATE_IN_AIR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return MAV_LANDED_STATE_ON_GROUND;
|
|
|
|
}
|
|
|
|
|