ManualControl: fix case where mode switches unintentionally in air

Case: A vehicle is already operating but has no stick input or another
source than RC. When RC stick input is switched to either because it gets
first time available or as a fallback to joystick then the mode was
immediately changed to the switch position. This can lead to loss of
control e.g. when the vehicle is flying far away and the
mode switch of the RC is in some fully manual piloted mode.

I added tests to cover the cases where RC mode initialization is expected
and also unexpceted because the vehicle is already armed.
This commit is contained in:
Matthias Grob
2023-05-17 16:52:30 +02:00
parent 2235c40e28
commit 83b832fdce
4 changed files with 51 additions and 3 deletions
+3 -2
View File
@@ -81,6 +81,7 @@ void ManualControl::processInput(hrt_abstime now)
vehicle_status_s vehicle_status;
if (_vehicle_status_sub.copy(&vehicle_status)) {
_armed = (vehicle_status.arming_state == vehicle_status_s::ARMING_STATE_ARMED);
_system_id = vehicle_status.system_id;
_rotary_wing = (vehicle_status.vehicle_type == vehicle_status_s::VEHICLE_TYPE_ROTARY_WING);
_vtol = vehicle_status.is_vtol;
@@ -269,8 +270,8 @@ void ManualControl::processSwitches(hrt_abstime &now)
}
}
} else {
// Send an initial request to switch to the mode requested by RC
} else if (!_armed) {
// Directly initialize mode using RC switch but only before arming
evaluateModeSlot(switches.mode_slot);
}