2016-08-25 04:48:27 -03:00
|
|
|
#include "GCS_Plane.h"
|
|
|
|
#include "Plane.h"
|
|
|
|
|
2020-02-11 21:01:17 -04:00
|
|
|
uint8_t GCS_Plane::sysid_this_mav() const
|
|
|
|
{
|
|
|
|
return plane.g.sysid_this_mav;
|
|
|
|
}
|
|
|
|
|
2019-02-19 21:17:46 -04:00
|
|
|
void GCS_Plane::update_vehicle_sensor_status_flags(void)
|
2019-02-19 17:29:54 -04:00
|
|
|
{
|
2021-04-13 00:55:53 -03:00
|
|
|
// airspeed
|
2019-02-19 17:29:54 -04:00
|
|
|
const AP_Airspeed *airspeed = AP_Airspeed::get_singleton();
|
|
|
|
if (airspeed && airspeed->enabled()) {
|
|
|
|
control_sensors_present |= MAV_SYS_STATUS_SENSOR_DIFFERENTIAL_PRESSURE;
|
|
|
|
}
|
2021-04-13 00:55:53 -03:00
|
|
|
if (airspeed && airspeed->enabled() && airspeed->use()) {
|
|
|
|
control_sensors_enabled |= MAV_SYS_STATUS_SENSOR_DIFFERENTIAL_PRESSURE;
|
|
|
|
}
|
|
|
|
if (airspeed && airspeed->all_healthy()) {
|
|
|
|
control_sensors_health |= MAV_SYS_STATUS_SENSOR_DIFFERENTIAL_PRESSURE;
|
2019-02-19 17:29:54 -04:00
|
|
|
}
|
2020-09-10 03:31:18 -03:00
|
|
|
|
2021-04-13 00:55:53 -03:00
|
|
|
// reverse thrust
|
2019-02-19 17:29:54 -04:00
|
|
|
if (plane.have_reverse_thrust()) {
|
|
|
|
control_sensors_present |= MAV_SYS_STATUS_REVERSE_MOTOR;
|
|
|
|
}
|
2021-04-13 00:55:53 -03:00
|
|
|
if (plane.have_reverse_thrust() && SRV_Channels::get_output_scaled(SRV_Channel::k_throttle) < 0) {
|
|
|
|
control_sensors_enabled |= MAV_SYS_STATUS_REVERSE_MOTOR;
|
|
|
|
control_sensors_health |= MAV_SYS_STATUS_REVERSE_MOTOR;
|
2019-02-19 17:29:54 -04:00
|
|
|
}
|
|
|
|
|
2021-04-13 00:55:53 -03:00
|
|
|
// flightmode-specific
|
2019-02-19 21:17:46 -04:00
|
|
|
control_sensors_present |=
|
|
|
|
MAV_SYS_STATUS_SENSOR_ANGULAR_RATE_CONTROL |
|
|
|
|
MAV_SYS_STATUS_SENSOR_ATTITUDE_STABILIZATION |
|
|
|
|
MAV_SYS_STATUS_SENSOR_YAW_POSITION |
|
|
|
|
MAV_SYS_STATUS_SENSOR_Z_ALTITUDE_CONTROL |
|
|
|
|
MAV_SYS_STATUS_SENSOR_XY_POSITION_CONTROL;
|
2019-02-19 17:29:54 -04:00
|
|
|
|
2019-02-19 21:17:46 -04:00
|
|
|
bool rate_controlled = false;
|
|
|
|
bool attitude_stabilized = false;
|
2019-01-15 13:46:13 -04:00
|
|
|
switch (plane.control_mode->mode_number()) {
|
|
|
|
case Mode::Number::MANUAL:
|
2019-02-19 17:29:54 -04:00
|
|
|
break;
|
|
|
|
|
2019-01-15 13:46:13 -04:00
|
|
|
case Mode::Number::ACRO:
|
|
|
|
case Mode::Number::QACRO:
|
2019-02-19 21:17:46 -04:00
|
|
|
rate_controlled = true;
|
2019-02-19 17:29:54 -04:00
|
|
|
break;
|
|
|
|
|
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::QSTABILIZE:
|
|
|
|
case Mode::Number::QHOVER:
|
|
|
|
case Mode::Number::QLAND:
|
|
|
|
case Mode::Number::QLOITER:
|
|
|
|
case Mode::Number::QAUTOTUNE:
|
|
|
|
case Mode::Number::FLY_BY_WIRE_B:
|
|
|
|
case Mode::Number::CRUISE:
|
2019-02-19 21:17:46 -04:00
|
|
|
rate_controlled = true;
|
|
|
|
attitude_stabilized = true;
|
2019-02-19 17:29:54 -04:00
|
|
|
break;
|
|
|
|
|
2019-01-15 13:46:13 -04:00
|
|
|
case Mode::Number::TRAINING:
|
2019-02-19 17:29:54 -04:00
|
|
|
if (!plane.training_manual_roll || !plane.training_manual_pitch) {
|
2019-02-19 21:17:46 -04:00
|
|
|
rate_controlled = true;
|
|
|
|
attitude_stabilized = true;
|
2019-02-19 17:29:54 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-01-15 13:46:13 -04:00
|
|
|
case Mode::Number::AUTO:
|
|
|
|
case Mode::Number::RTL:
|
|
|
|
case Mode::Number::LOITER:
|
|
|
|
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:
|
2019-01-15 13:46:13 -04:00
|
|
|
case Mode::Number::QRTL:
|
2020-09-16 04:46:56 -03:00
|
|
|
case Mode::Number::THERMAL:
|
2019-02-19 21:17:46 -04:00
|
|
|
rate_controlled = true;
|
|
|
|
attitude_stabilized = true;
|
|
|
|
control_sensors_enabled |= MAV_SYS_STATUS_SENSOR_YAW_POSITION;
|
|
|
|
control_sensors_health |= MAV_SYS_STATUS_SENSOR_YAW_POSITION;
|
|
|
|
control_sensors_enabled |= MAV_SYS_STATUS_SENSOR_Z_ALTITUDE_CONTROL;
|
|
|
|
control_sensors_health |= MAV_SYS_STATUS_SENSOR_Z_ALTITUDE_CONTROL;
|
|
|
|
control_sensors_enabled |= MAV_SYS_STATUS_SENSOR_XY_POSITION_CONTROL;
|
|
|
|
control_sensors_health |= MAV_SYS_STATUS_SENSOR_XY_POSITION_CONTROL;
|
2019-02-19 17:29:54 -04:00
|
|
|
break;
|
|
|
|
|
2019-01-15 13:46:13 -04:00
|
|
|
case Mode::Number::INITIALISING:
|
2019-02-19 17:29:54 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-02-19 21:17:46 -04:00
|
|
|
if (rate_controlled) {
|
|
|
|
control_sensors_enabled |= MAV_SYS_STATUS_SENSOR_ANGULAR_RATE_CONTROL; // 3D angular rate control
|
|
|
|
control_sensors_health |= MAV_SYS_STATUS_SENSOR_ANGULAR_RATE_CONTROL; // 3D angular rate control
|
|
|
|
}
|
|
|
|
if (attitude_stabilized) {
|
|
|
|
control_sensors_enabled |= MAV_SYS_STATUS_SENSOR_ATTITUDE_STABILIZATION;
|
|
|
|
control_sensors_health |= MAV_SYS_STATUS_SENSOR_ATTITUDE_STABILIZATION;
|
2019-02-19 17:29:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if OPTFLOW == ENABLED
|
2021-04-13 00:55:53 -03:00
|
|
|
const OpticalFlow *optflow = AP::opticalflow();
|
|
|
|
if (optflow && optflow->enabled()) {
|
|
|
|
control_sensors_present |= MAV_SYS_STATUS_SENSOR_OPTICAL_FLOW;
|
|
|
|
control_sensors_enabled |= MAV_SYS_STATUS_SENSOR_OPTICAL_FLOW;
|
|
|
|
}
|
2019-02-19 17:29:54 -04:00
|
|
|
if (optflow && optflow->healthy()) {
|
|
|
|
control_sensors_health |= MAV_SYS_STATUS_SENSOR_OPTICAL_FLOW;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-02-19 21:17:46 -04:00
|
|
|
control_sensors_present |= MAV_SYS_STATUS_SENSOR_RC_RECEIVER;
|
|
|
|
control_sensors_enabled |= MAV_SYS_STATUS_SENSOR_RC_RECEIVER;
|
2021-06-19 05:58:18 -03:00
|
|
|
uint32_t last_valid = plane.failsafe.last_valid_rc_ms;
|
|
|
|
if (millis() - last_valid < 200) {
|
2019-02-19 17:29:54 -04:00
|
|
|
control_sensors_health |= MAV_SYS_STATUS_SENSOR_RC_RECEIVER;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if AP_TERRAIN_AVAILABLE
|
|
|
|
switch (plane.terrain.status()) {
|
|
|
|
case AP_Terrain::TerrainStatusDisabled:
|
|
|
|
break;
|
|
|
|
case AP_Terrain::TerrainStatusUnhealthy:
|
|
|
|
control_sensors_present |= MAV_SYS_STATUS_TERRAIN;
|
|
|
|
control_sensors_enabled |= MAV_SYS_STATUS_TERRAIN;
|
|
|
|
break;
|
|
|
|
case AP_Terrain::TerrainStatusOK:
|
|
|
|
control_sensors_present |= MAV_SYS_STATUS_TERRAIN;
|
|
|
|
control_sensors_enabled |= MAV_SYS_STATUS_TERRAIN;
|
|
|
|
control_sensors_health |= MAV_SYS_STATUS_TERRAIN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
const RangeFinder *rangefinder = RangeFinder::get_singleton();
|
|
|
|
if (rangefinder && rangefinder->has_orientation(ROTATION_PITCH_270)) {
|
|
|
|
control_sensors_present |= MAV_SYS_STATUS_SENSOR_LASER_POSITION;
|
|
|
|
if (plane.g.rangefinder_landing) {
|
|
|
|
control_sensors_enabled |= MAV_SYS_STATUS_SENSOR_LASER_POSITION;
|
|
|
|
}
|
|
|
|
if (rangefinder->has_data_orient(ROTATION_PITCH_270)) {
|
|
|
|
control_sensors_health |= MAV_SYS_STATUS_SENSOR_LASER_POSITION;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|