mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-29 11:40:28 +08:00
fix(commander/mavlink): DO_SET_HOME improvements (#29786)
* fix(commander): accept only 0 or 1 as DO_SET_HOME param1 MAV_CMD_DO_SET_HOME param1 is a MAV_BOOL: 1 uses the current position, 0 the specified location, and any other value is invalid. Any value above 0.5 was taken as "use current", so an invalid value silently set home to the current position instead of being denied. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Julian Oes <julian@oes.ch> * fix(mavlink): honour the COMMAND_INT frame for DO_SET_HOME The frame of a COMMAND_INT was only used to scale x/y and then dropped, and Commander takes the DO_SET_HOME altitude as AMSL. A relative altitude, as sent by MAVProxy, therefore set home to that many metres above mean sea level, and local frames gave meaningless coordinates. A global altitude is passed on as before, a relative altitude is converted to AMSL using the current home altitude, and other frames are rejected with MAV_RESULT_COMMAND_UNSUPPORTED_MAV_FRAME. The frame does not matter when the current position is used. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Julian Oes <julian@oes.ch> * fix(commander): allow DO_SET_HOME with COM_HOME_EN disabled COM_HOME_EN is documented as setting home automatically, but disabling it also denied MAV_CMD_DO_SET_HOME, leaving the vehicle without any way to get a home. Disabling it now only stops home from being set automatically, and home can still be set manually. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Julian Oes <julian@oes.ch> --------- Signed-off-by: Julian Oes <julian@oes.ch>
This commit is contained in:
1 parent
8638fa397e
commit
d995af2184
3 files changed
+38
-6
No files matched your search
@@ -1155,8 +1155,13 @@ Commander::handle_command(const vehicle_command_s &cmd)
|
||||
break;
|
||||
|
||||
case vehicle_command_s::VEHICLE_CMD_DO_SET_HOME: {
|
||||
if (_param_com_home_en.get()) {
|
||||
bool use_current = cmd.param1 > 0.5f;
|
||||
// COM_HOME_EN only disables setting home automatically, it can still be set manually
|
||||
if (!(fabsf(cmd.param1) < FLT_EPSILON) && !(fabsf(cmd.param1 - 1.f) < FLT_EPSILON)) {
|
||||
// param1 is a MAV_BOOL: 1 uses the current position, 0 the specified location
|
||||
cmd_result = vehicle_command_ack_s::VEHICLE_CMD_RESULT_DENIED;
|
||||
|
||||
} else {
|
||||
const bool use_current = fabsf(cmd.param1 - 1.f) < FLT_EPSILON;
|
||||
|
||||
if (use_current) {
|
||||
/* use current position */
|
||||
@@ -1192,10 +1197,6 @@ Commander::handle_command(const vehicle_command_s &cmd)
|
||||
cmd_result = vehicle_command_ack_s::VEHICLE_CMD_RESULT_DENIED;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// COM_HOME_EN disabled
|
||||
cmd_result = vehicle_command_ack_s::VEHICLE_CMD_RESULT_DENIED;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -44,6 +44,8 @@ parameters:
|
||||
long: |-
|
||||
Set home position automatically if possible.
|
||||
|
||||
If disabled, home is only set manually with MAV_CMD_DO_SET_HOME.
|
||||
|
||||
During missions, the latitude/longitude of the home position is locked and will not reset during intermediate landings.
|
||||
It will only update once the mission is complete or landed outside of a mission.
|
||||
However, the altitude is still being adjusted to correct for GNSS vertical drift in the first 2 minutes after takeoff.
|
||||
|
||||
@@ -717,6 +717,35 @@ MavlinkReceiver::handle_message_command_int(mavlink_message_t *msg)
|
||||
vcmd.confirmation = false;
|
||||
vcmd.from_external = true;
|
||||
|
||||
// The frame is not passed on to Commander, which takes the DO_SET_HOME altitude as AMSL.
|
||||
// The frame only matters if the location is given (param1 MAV_BOOL_FALSE), not when the
|
||||
// current position is used (MAV_BOOL_TRUE). Other param1 values are denied by Commander.
|
||||
if (cmd_mavlink.command == MAV_CMD_DO_SET_HOME && fabsf(cmd_mavlink.param1) < FLT_EPSILON
|
||||
&& evaluate_target_ok(vcmd.command, vcmd.target_system, vcmd.target_component)) {
|
||||
if (cmd_mavlink.frame == MAV_FRAME_GLOBAL || cmd_mavlink.frame == MAV_FRAME_GLOBAL_INT) {
|
||||
// already AMSL
|
||||
|
||||
} else if (cmd_mavlink.frame == MAV_FRAME_GLOBAL_RELATIVE_ALT
|
||||
|| cmd_mavlink.frame == MAV_FRAME_GLOBAL_RELATIVE_ALT_INT) {
|
||||
home_position_s home_position{};
|
||||
_home_position_sub.copy(&home_position);
|
||||
|
||||
if (!home_position.valid_alt) {
|
||||
// the altitude is relative to a home that is not set yet
|
||||
acknowledge(msg->sysid, msg->compid, cmd_mavlink.command,
|
||||
vehicle_command_ack_s::VEHICLE_CMD_RESULT_TEMPORARILY_REJECTED);
|
||||
return;
|
||||
}
|
||||
|
||||
vcmd.param7 = home_position.alt + cmd_mavlink.z;
|
||||
|
||||
} else {
|
||||
acknowledge(msg->sysid, msg->compid, cmd_mavlink.command,
|
||||
vehicle_command_ack_s::VEHICLE_CMD_RESULT_UNSUPPORTED_MAV_FRAME);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
handle_message_command_both(msg, vcmd);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user