From 8c42c38650b8717d0df799fb35a1fbdc0fc02bc5 Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Sat, 8 Aug 2020 12:48:48 -0400 Subject: [PATCH] mc_att_control: don't store full vehicle_land_detected copy --- src/modules/mc_att_control/mc_att_control.hpp | 2 +- .../mc_att_control/mc_att_control_main.cpp | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/modules/mc_att_control/mc_att_control.hpp b/src/modules/mc_att_control/mc_att_control.hpp index fe86d29a60..9ac1736e87 100644 --- a/src/modules/mc_att_control/mc_att_control.hpp +++ b/src/modules/mc_att_control/mc_att_control.hpp @@ -114,7 +114,6 @@ private: struct manual_control_setpoint_s _manual_control_setpoint {}; /**< manual control setpoint */ struct vehicle_control_mode_s _v_control_mode {}; /**< vehicle control mode */ struct vehicle_status_s _vehicle_status {}; /**< vehicle status */ - struct vehicle_land_detected_s _vehicle_land_detected {}; perf_counter_t _loop_perf; /**< loop duration performance counter */ @@ -127,6 +126,7 @@ private: hrt_abstime _last_run{0}; + bool _landed{true}; bool _reset_yaw_sp{true}; uint8_t _quat_reset_counter{0}; diff --git a/src/modules/mc_att_control/mc_att_control_main.cpp b/src/modules/mc_att_control/mc_att_control_main.cpp index 6b9ce11005..43c2c9a643 100644 --- a/src/modules/mc_att_control/mc_att_control_main.cpp +++ b/src/modules/mc_att_control/mc_att_control_main.cpp @@ -104,7 +104,7 @@ MulticopterAttitudeControl::parameters_updated() float MulticopterAttitudeControl::throttle_curve(float throttle_stick_input) { - const float throttle_min = _vehicle_land_detected.landed ? 0.0f : _param_mpc_manthr_min.get(); + const float throttle_min = _landed ? 0.0f : _param_mpc_manthr_min.get(); // throttle_stick_input is in range [0, 1] switch (_param_mpc_thr_curve.get()) { @@ -268,7 +268,15 @@ MulticopterAttitudeControl::Run() /* check for updates in other topics */ _manual_control_setpoint_sub.update(&_manual_control_setpoint); _v_control_mode_sub.update(&_v_control_mode); - _vehicle_land_detected_sub.update(&_vehicle_land_detected); + + if (_vehicle_land_detected_sub.updated()) { + vehicle_land_detected_s vehicle_land_detected; + + if (_vehicle_land_detected_sub.copy(&vehicle_land_detected)) { + _landed = vehicle_land_detected.landed; + } + } + _vehicle_status_sub.update(&_vehicle_status); /* Check if we are in rattitude mode and the pilot is above the threshold on pitch @@ -334,8 +342,7 @@ MulticopterAttitudeControl::Run() // reset yaw setpoint during transitions, tailsitter.cpp generates // attitude setpoint for the transition _reset_yaw_sp = (!attitude_setpoint_generated && !_v_control_mode.flag_control_rattitude_enabled) || - _vehicle_land_detected.landed || - (_vehicle_status.is_vtol && _vehicle_status.in_transition_mode); + _landed || (_vehicle_status.is_vtol && _vehicle_status.in_transition_mode); }