diff --git a/src/modules/commander/Commander.cpp b/src/modules/commander/Commander.cpp index 0aece4d0b2e..2b4a97257dc 100644 --- a/src/modules/commander/Commander.cpp +++ b/src/modules/commander/Commander.cpp @@ -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; diff --git a/src/modules/commander/commander_params.yaml b/src/modules/commander/commander_params.yaml index f61427ef05a..7ff0cbf87af 100644 --- a/src/modules/commander/commander_params.yaml +++ b/src/modules/commander/commander_params.yaml @@ -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. diff --git a/src/modules/mavlink/mavlink_receiver.cpp b/src/modules/mavlink/mavlink_receiver.cpp index 31421ce0d90..8a939c31ebc 100644 --- a/src/modules/mavlink/mavlink_receiver.cpp +++ b/src/modules/mavlink/mavlink_receiver.cpp @@ -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); }