mode: control auto set home from an external mode

The mode executor can run land mode which updates the home position to the landing location. This
can be not the desirable behavior and the home position should stay at the original location.

A flag is added to the configuration overrides to control if the home position is updated or not.
This commit is contained in:
Michael Schaeuble 2025-11-24 10:29:47 +01:00 committed by Beat Küng
parent a2299b02c8
commit d97a8d7d3b
6 changed files with 73 additions and 5 deletions

View File

@ -0,0 +1,21 @@
# Configurable overrides by (external) modes or mode executors
uint32 MESSAGE_VERSION = 0
uint64 timestamp # time since system start (microseconds)
bool disable_auto_disarm # Prevent the drone from automatically disarming after landing (if configured)
bool defer_failsafes # Defer all failsafes that can be deferred (until the flag is cleared)
int16 defer_failsafes_timeout_s # Maximum time a failsafe can be deferred. 0 = system default, -1 = no timeout
int8 SOURCE_TYPE_MODE = 0
int8 SOURCE_TYPE_MODE_EXECUTOR = 1
int8 source_type
uint8 source_id # ID depending on source_type
uint8 ORB_QUEUE_LENGTH = 4
# TOPICS config_overrides config_overrides_request

View File

@ -10,6 +10,7 @@
#include "translation_arming_check_reply_v1.h"
#include "translation_arming_check_request_v1.h"
#include "translation_battery_status_v1.h"
#include "translation_config_overrides_v1.h"
#include "translation_event_v1.h"
#include "translation_home_position_v1.h"
#include "translation_register_ext_component_reply_v1.h"

View File

@ -0,0 +1,41 @@
/****************************************************************************
* Copyright (c) 2025 PX4 Development Team.
* SPDX-License-Identifier: BSD-3-Clause
****************************************************************************/
#pragma once
// Translate ConfigOverrides v0 <--> v1
#include <px4_msgs_old/msg/config_overrides_v0.hpp>
#include <px4_msgs/msg/config_overrides.hpp>
class ConfigOverridesV1Translation {
public:
using MessageOlder = px4_msgs_old::msg::ConfigOverridesV0;
static_assert(MessageOlder::MESSAGE_VERSION == 0);
using MessageNewer = px4_msgs::msg::ConfigOverrides;
static_assert(MessageNewer::MESSAGE_VERSION == 1);
static constexpr const char* kTopic = "fmu/in/config_overrides_request";
static void fromOlder(const MessageOlder &msg_older, MessageNewer &msg_newer) {
msg_newer.timestamp = msg_older.timestamp;
msg_newer.disable_auto_disarm = msg_older.disable_auto_disarm;
msg_newer.defer_failsafes = msg_older.defer_failsafes;
msg_newer.defer_failsafes_timeout_s = msg_older.defer_failsafes_timeout_s;
msg_newer.disable_auto_set_home = false;
msg_newer.source_type = msg_older.source_type;
msg_newer.source_id = msg_older.source_id;
}
static void toOlder(const MessageNewer &msg_newer, MessageOlder &msg_older) {
msg_older.timestamp = msg_newer.timestamp;
msg_older.disable_auto_disarm = msg_newer.disable_auto_disarm;
msg_older.defer_failsafes = msg_newer.defer_failsafes;
msg_older.defer_failsafes_timeout_s = msg_newer.defer_failsafes_timeout_s;
msg_older.source_type = msg_newer.source_type;
msg_older.source_id = msg_newer.source_id;
}
};
REGISTER_TOPIC_TRANSLATION_DIRECT(ConfigOverridesV1Translation);

View File

@ -1,6 +1,6 @@
# Configurable overrides by (external) modes or mode executors
uint32 MESSAGE_VERSION = 0
uint32 MESSAGE_VERSION = 1
uint64 timestamp # time since system start (microseconds)
@ -8,7 +8,7 @@ bool disable_auto_disarm # Prevent the drone from automatically disarmin
bool defer_failsafes # Defer all failsafes that can be deferred (until the flag is cleared)
int16 defer_failsafes_timeout_s # Maximum time a failsafe can be deferred. 0 = system default, -1 = no timeout
bool disable_auto_set_home # Prevent the drone from automatically setting the home position on arm or takeoff
int8 SOURCE_TYPE_MODE = 0
int8 SOURCE_TYPE_MODE_EXECUTOR = 1

View File

@ -638,7 +638,7 @@ transition_result_t Commander::arm(arm_disarm_reason_t calling_reason, bool run_
events::send<events::px4::enums::arm_disarm_reason_t>(events::ID("commander_armed_by"), events::Log::Info,
"Armed by {1}", calling_reason);
if (_param_com_home_en.get() && !_mission_in_progress) {
if (_param_com_home_en.get() && !_mission_in_progress && !_config_overrides.disable_auto_set_home) {
_home_position.setHomePosition();
}
@ -1850,7 +1850,8 @@ void Commander::run()
_mission_in_progress = (_vehicle_status.nav_state == vehicle_status_s::NAVIGATION_STATE_AUTO_MISSION)
&& !_mission_result_sub.get().finished;
_home_position.update(_param_com_home_en.get(), !isArmed() && _vehicle_land_detected.landed && !_mission_in_progress);
_home_position.update(_param_com_home_en.get(), !isArmed() && _vehicle_land_detected.landed && !_mission_in_progress
&& !_config_overrides.disable_auto_set_home);
handleAutoDisarm();
@ -2140,7 +2141,7 @@ void Commander::landDetectorUpdate()
}
// automatically set or update home position
if (_param_com_home_en.get() && !_mission_in_progress) {
if (_param_com_home_en.get() && !_mission_in_progress && !_config_overrides.disable_auto_set_home) {
// set the home position when taking off
if (!_vehicle_land_detected.landed) {
if (was_landed) {

View File

@ -563,6 +563,10 @@ void ModeManagement::updateActiveConfigOverrides(uint8_t nav_state, config_overr
current_overrides.disable_auto_disarm = true;
}
if (executor_overrides.disable_auto_set_home) {
current_overrides.disable_auto_set_home = true;
}
if (executor_overrides.defer_failsafes) {
current_overrides.defer_failsafes = true;
current_overrides.defer_failsafes_timeout_s = executor_overrides.defer_failsafes_timeout_s;