FlightModeManager/FixedwingPositionControl: robustify vehicle command parameter casting

This commit is contained in:
Matthias Grob 2022-04-12 16:35:02 +02:00 committed by Roman Bapst
parent 6ce3e88f9d
commit f892a624b7
3 changed files with 7 additions and 5 deletions

View File

@ -444,8 +444,9 @@ void FlightModeManager::handleCommand()
} else if (_current_task.task) {
// check for other commands not related to task switching
if (command.command == vehicle_command_s::VEHICLE_CMD_DO_CHANGE_SPEED && command.param2 >= 0
&& (uint8_t)command.param1 == vehicle_command_s::SPEED_TYPE_GROUNDSPEED) {
if ((command.command == vehicle_command_s::VEHICLE_CMD_DO_CHANGE_SPEED)
&& (static_cast<uint8_t>(command.param1 + .5f) == vehicle_command_s::SPEED_TYPE_GROUNDSPEED)
&& (command.param2 > 0.f)) {
_current_task.task->setCruisingSpeed(command.param2);
}
}

View File

@ -258,8 +258,9 @@ FixedwingPositionControl::vehicle_command_poll()
abort_landing(true);
}
} else if (vehicle_command.command == vehicle_command_s::VEHICLE_CMD_DO_CHANGE_SPEED
&& (uint8_t)vehicle_command.param1 == vehicle_command_s::SPEED_TYPE_AIRSPEED && vehicle_command.param2 > 0) {
} else if ((vehicle_command.command == vehicle_command_s::VEHICLE_CMD_DO_CHANGE_SPEED)
&& (static_cast<uint8_t>(vehicle_command.param1 + .5f) == vehicle_command_s::SPEED_TYPE_AIRSPEED)
&& (vehicle_command.param2 > 0.f)) {
if (_control_mode_current == FW_POSCTRL_MODE_AUTO) {
_pos_sp_triplet.current.cruising_speed = vehicle_command.param2;

View File

@ -266,7 +266,7 @@ private:
float _manual_control_setpoint_altitude{0.0f};
float _manual_control_setpoint_airspeed{0.0f};
float _commanded_airspeed_setpoint{(float)NAN}; ///< airspeed setpoint for manual modes commanded via MAV_CMD_DO_CHANGE_SPEED
float _commanded_airspeed_setpoint{NAN}; ///< airspeed setpoint for manual modes commanded via MAV_CMD_DO_CHANGE_SPEED
hrt_abstime _time_in_fixed_bank_loiter{0};