From 8a7919bcb68082ff7ff6681c787dfe371ba93c0e Mon Sep 17 00:00:00 2001 From: Thomas Stastny Date: Sun, 8 Jul 2018 23:15:01 +0200 Subject: [PATCH] fw att+pos ctrl: use enum for flaps configs --- msg/vehicle_attitude_setpoint.msg | 5 ++++- .../fw_att_control/FixedwingAttitudeControl.cpp | 10 ++++++---- .../fw_pos_control_l1/FixedwingPositionControl.cpp | 6 +++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/msg/vehicle_attitude_setpoint.msg b/msg/vehicle_attitude_setpoint.msg index 65a2227604..5cb14b3855 100644 --- a/msg/vehicle_attitude_setpoint.msg +++ b/msg/vehicle_attitude_setpoint.msg @@ -20,7 +20,10 @@ bool yaw_reset_integral # Reset yaw integral part (navigation logic change) bool fw_control_yaw # control heading with rudder (used for auto takeoff on runway) bool disable_mc_yaw_control # control yaw for mc (used for vtol weather-vane mode) -int8 apply_flaps # 0 = no flaps, 1 = landing flaps setting, 2 = take-off flaps setting +uint8 apply_flaps # flap config specifier +uint8 FLAPS_OFF = 0 # no flaps +uint8 FLAPS_LAND = 1 # landing config flaps +uint8 FLAPS_TAKEOFF = 2 # take-off config flaps float32 landing_gear diff --git a/src/modules/fw_att_control/FixedwingAttitudeControl.cpp b/src/modules/fw_att_control/FixedwingAttitudeControl.cpp index 9247a8a1cd..352ea501ce 100644 --- a/src/modules/fw_att_control/FixedwingAttitudeControl.cpp +++ b/src/modules/fw_att_control/FixedwingAttitudeControl.cpp @@ -878,13 +878,14 @@ void FixedwingAttitudeControl::control_flaps(const float dt) } else if (_vcontrol_mode.flag_control_auto_enabled && fabsf(_parameters.flaps_scale) > 0.01f) { switch (_att_sp.apply_flaps) { - case 0 : flap_control = 0.0f; // no flaps + case vehicle_attitude_setpoint_s::FLAPS_OFF : flap_control = 0.0f; // no flaps break; - case 1 : flap_control = 1.0f * _parameters.flaps_scale; // landing flaps + case vehicle_attitude_setpoint_s::FLAPS_LAND : flap_control = 1.0f * _parameters.flaps_scale; // landing flaps break; - case 2 : flap_control = 1.0f * _parameters.flaps_scale * _parameters.flaps_takeoff_scale; // take-off flaps + case vehicle_attitude_setpoint_s::FLAPS_TAKEOFF : flap_control = 1.0f * _parameters.flaps_scale * + _parameters.flaps_takeoff_scale; // take-off flaps break; } } @@ -907,7 +908,8 @@ void FixedwingAttitudeControl::control_flaps(const float dt) } else if (_vcontrol_mode.flag_control_auto_enabled && fabsf(_parameters.flaperon_scale) > 0.01f) { - flaperon_control = (_att_sp.apply_flaps == 1) ? 1.0f * _parameters.flaperon_scale : 0.0f; + flaperon_control = (_att_sp.apply_flaps == vehicle_attitude_setpoint_s::FLAPS_LAND) ? 1.0f * + _parameters.flaperon_scale : 0.0f; } // move the actual control value continuous with time, full flap travel in 1sec diff --git a/src/modules/fw_pos_control_l1/FixedwingPositionControl.cpp b/src/modules/fw_pos_control_l1/FixedwingPositionControl.cpp index 038f87b0cd..4aeace4805 100644 --- a/src/modules/fw_pos_control_l1/FixedwingPositionControl.cpp +++ b/src/modules/fw_pos_control_l1/FixedwingPositionControl.cpp @@ -704,7 +704,7 @@ FixedwingPositionControl::control_position(const Vector2f &curr_pos, const Vecto bool setpoint = true; _att_sp.fw_control_yaw = false; // by default we don't want yaw to be contoller directly with rudder - _att_sp.apply_flaps = 0; // by default we don't use flaps + _att_sp.apply_flaps = vehicle_attitude_setpoint_s::FLAPS_OFF; // by default we don't use flaps calculate_gndspeed_undershoot(curr_pos, ground_speed, pos_sp_prev, pos_sp_curr); @@ -1139,7 +1139,7 @@ FixedwingPositionControl::control_takeoff(const Vector2f &curr_pos, const Vector // apply flaps for takeoff according to the corresponding scale factor set // via FW_FLAPS_TO_SCL - _att_sp.apply_flaps = 2; + _att_sp.apply_flaps = vehicle_attitude_setpoint_s::FLAPS_TAKEOFF; // continuously reset launch detection and runway takeoff until armed if (!_control_mode.flag_armed) { @@ -1309,7 +1309,7 @@ FixedwingPositionControl::control_landing(const Vector2f &curr_pos, const Vector // apply full flaps for landings. this flag will also trigger the use of flaperons // if they have been enabled using the corresponding parameter - _att_sp.apply_flaps = 1; + _att_sp.apply_flaps = vehicle_attitude_setpoint_s::FLAPS_LAND; // save time at which we started landing and reset abort_landing if (_time_started_landing == 0) {