mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-25 00:30:50 +08:00
fix(commander): acknowledge DO_REPOSITION by mode, not UNSUPPORTED (#27563)
DO_REPOSITION with the CHANGE_MODE flag clear (param2=0) is valid per the
MAVLink spec -- "reposition without forcing a mode change" -- but Commander
acked UNSUPPORTED for it while the navigator still applied the setpoint
whenever armed, so an armed vehicle in Hold moved despite the UNSUPPORTED ack.
Commander now acks by mode: CHANGE_MODE set switches to Hold (or stays in
Course) and acks ACCEPTED/TEMPORARILY_REJECTED; param2=0 in Hold acks ACCEPTED;
otherwise DENIED. It never returns UNSUPPORTED.
The navigator now only applies the reposition setpoint when armed and either
CHANGE_MODE was requested or it is already in Hold, so it no longer leaves a
stale setpoint that a later switch into Hold could execute -- realizing the
intent of the 2023 change (bec0d83), which only ever touched the ack.
QGC and MAVSDK always set CHANGE_MODE, so their behavior is unchanged.
Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>
This commit is contained in:
1 parent
d04ea48a53
commit
3dc17ff455
2 files changed
+16
-10
No files matched your search
@@ -868,14 +868,9 @@ Commander::handle_command(const vehicle_command_s &cmd)
|
||||
// to not require navigator and command to receive / process
|
||||
// the data at the exact same time.
|
||||
|
||||
const uint32_t change_mode_flags = uint32_t(cmd.param2);
|
||||
const bool mode_switch_not_requested = (change_mode_flags & 1) == 0;
|
||||
const bool unsupported_bits_set = (change_mode_flags & ~1) != 0;
|
||||
const bool change_mode_requested = (uint32_t(cmd.param2) & 1) != 0;
|
||||
|
||||
if (mode_switch_not_requested || unsupported_bits_set) {
|
||||
answer_command(cmd, vehicle_command_ack_s::VEHICLE_CMD_RESULT_UNSUPPORTED);
|
||||
|
||||
} else {
|
||||
if (change_mode_requested) {
|
||||
// If already in course mode, stay in course mode (navigator handles any altitude update)
|
||||
// Only switch to loiter if a specific lat/lon target is given, or we are not in course mode.
|
||||
const bool has_position_target = PX4_ISFINITE(cmd.param5) && PX4_ISFINITE(cmd.param6);
|
||||
@@ -891,6 +886,14 @@ Commander::handle_command(const vehicle_command_s &cmd)
|
||||
printRejectMode(target_state);
|
||||
cmd_result = vehicle_command_ack_s::VEHICLE_CMD_RESULT_TEMPORARILY_REJECTED;
|
||||
}
|
||||
|
||||
} else if (_vehicle_status.nav_state == vehicle_status_s::NAVIGATION_STATE_AUTO_LOITER) {
|
||||
// No mode switch requested: reposition the current hold setpoint in place.
|
||||
cmd_result = vehicle_command_ack_s::VEHICLE_CMD_RESULT_ACCEPTED;
|
||||
|
||||
} else {
|
||||
// Supported, but no mode switch requested and not in hold: nothing to act on.
|
||||
cmd_result = vehicle_command_ack_s::VEHICLE_CMD_RESULT_DENIED;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -276,9 +276,12 @@ void Navigator::run()
|
||||
publish_vehicle_command_ack(cmd, vehicle_command_ack_s::VEHICLE_CMD_RESULT_ACCEPTED);
|
||||
|
||||
} else if (cmd.command == vehicle_command_s::VEHICLE_CMD_DO_REPOSITION
|
||||
&& _vstatus.arming_state == vehicle_status_s::ARMING_STATE_ARMED) {
|
||||
// only update the reposition setpoint if armed, as it otherwise won't get executed until the vehicle switches to loiter,
|
||||
// which can lead to dangerous and unexpected behaviors (see loiter.cpp, there is an if(armed) in there too)
|
||||
&& _vstatus.arming_state == vehicle_status_s::ARMING_STATE_ARMED
|
||||
&& (((uint32_t)cmd.param2 & 1) != 0
|
||||
|| _vstatus.nav_state == vehicle_status_s::NAVIGATION_STATE_AUTO_LOITER)) {
|
||||
// Only apply the reposition setpoint when armed and either a mode switch into Hold was requested
|
||||
// (CHANGE_MODE flag) or we're already in Hold. Otherwise a later switch into Hold could execute a
|
||||
// stale setpoint (loiter.cpp applies it within a 500ms window).
|
||||
|
||||
// Wait for vehicle_status before handling the next command, otherwise the setpoint could be overwritten
|
||||
_wait_for_vehicle_status_timestamp = hrt_absolute_time();
|
||||
|
||||
Reference in new issue
Block a user