Skip to content

Commit

Permalink
commander: COM_MODE_ARM_CHK parameter to allow mode registration whil…
Browse files Browse the repository at this point in the history
…e armed (#24249)
  • Loading branch information
bdilman authored Jan 28, 2025
1 parent 58d3e1e commit a0a2bda
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
3 changes: 3 additions & 0 deletions ROMFS/px4fmu_common/init.d-posix/px4-rc.simulator
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
# Simulator IMU data provided at 250 Hz
param set-default IMU_INTEG_RATE 250

# For simulation, allow registering modes while armed for developer convenience
param set-default COM_MODE_ARM_CHK 1

if [ "$PX4_SIMULATOR" = "sihsim" ] || [ "$(param show -q SYS_AUTOSTART)" -eq "0" ]; then

echo "INFO [init] SIH simulator"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <uORB/topics/arming_check_reply.h>
#include <uORB/Subscription.hpp>
#include <uORB/Publication.hpp>
#include <px4_platform_common/module_params.h>

static_assert((1ull << arming_check_reply_s::HEALTH_COMPONENT_INDEX_AVOIDANCE) == (uint64_t)
health_component_t::avoidance, "enum definition missmatch");
Expand Down Expand Up @@ -66,7 +67,7 @@ class ExternalChecks : public HealthAndArmingCheckBase
void update();

bool isUnresponsive(int registration_id);

bool allowUpdateWhileArmed() const { return _param_com_mode_arm_chk.get(); }
private:
static constexpr hrt_abstime REQUEST_TIMEOUT = 50_ms;
static constexpr hrt_abstime UPDATE_INTERVAL = 300_ms;
Expand Down Expand Up @@ -109,4 +110,7 @@ class ExternalChecks : public HealthAndArmingCheckBase
uORB::Subscription _arming_check_reply_sub{ORB_ID(arming_check_reply)};

uORB::Publication<arming_check_request_s> _arming_check_request_pub{ORB_ID(arming_check_request)};
DEFINE_PARAMETERS_CUSTOM_PARENT(HealthAndArmingCheckBase,
(ParamBool<px4::params::COM_MODE_ARM_CHK>) _param_com_mode_arm_chk
);
};
9 changes: 3 additions & 6 deletions src/modules/commander/ModeManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,7 @@ void ModeManagement::update(bool armed, uint8_t user_intended_nav_state, bool fa
_failsafe_action_active = failsafe_action_active;
_external_checks.update();

bool allow_update_while_armed = false;
#if defined(CONFIG_ARCH_BOARD_PX4_SITL)
// For simulation, allow registering modes while armed for developer convenience
allow_update_while_armed = true;
#endif
bool allow_update_while_armed = _external_checks.allowUpdateWhileArmed();

if (armed && !allow_update_while_armed) {
// Reject registration requests
Expand Down Expand Up @@ -408,7 +404,8 @@ void ModeManagement::update(bool armed, uint8_t user_intended_nav_state, bool fa
}
}

// As we're disarmed we can use the user intended mode, as no failsafe will be active
// As we're disarmed we can use the user intended mode, as no failsafe will be active.
// Note that this might not be true if COM_MODE_ARM_CHK is set
checkNewRegistrations(update_request);
checkUnregistrations(user_intended_nav_state, update_request);
}
Expand Down
11 changes: 11 additions & 0 deletions src/modules/commander/commander_params.c
Original file line number Diff line number Diff line change
Expand Up @@ -1018,3 +1018,14 @@ PARAM_DEFINE_FLOAT(COM_THROW_SPEED, 5);
* @increment 1
*/
PARAM_DEFINE_INT32(COM_FLTT_LOW_ACT, 3);

/**
* Allow external mode registration while armed.
*
* By default disabled for safety reasons
*
* @group Commander
* @boolean
*
*/
PARAM_DEFINE_INT32(COM_MODE_ARM_CHK, 0);

0 comments on commit a0a2bda

Please sign in to comment.