Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add param COM_PREARM_MODE #12806

Merged
merged 6 commits into from
Sep 2, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/drivers/px4io/px4io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,13 @@ PX4IO::io_set_arming_state()

_armed = armed.armed;

if (armed.prearmed) {
set |= PX4IO_P_SETUP_ARMING_FMU_PREARMED;

} else {
clear |= PX4IO_P_SETUP_ARMING_FMU_PREARMED;
}

if ((armed.lockdown || armed.manual_lockdown) && !_lockdown_override) {
set |= PX4IO_P_SETUP_ARMING_LOCKDOWN;
_lockdown_override = true;
Expand Down Expand Up @@ -2284,6 +2291,7 @@ PX4IO::print_status(bool extended_status)
printf("arming 0x%04hx%s%s%s%s%s%s%s%s%s%s\n",
arming,
((arming & PX4IO_P_SETUP_ARMING_FMU_ARMED) ? " FMU_ARMED" : " FMU_DISARMED"),
((arming & PX4IO_P_SETUP_ARMING_FMU_PREARMED) ? " FMU_PREARMED" : " FMU_NOT_PREARMED"),
((arming & PX4IO_P_SETUP_ARMING_IO_ARM_OK) ? " IO_ARM_OK" : " IO_ARM_DENIED"),
((arming & PX4IO_P_SETUP_ARMING_MANUAL_OVERRIDE_OK) ? " MANUAL_OVERRIDE_OK" : ""),
((arming & PX4IO_P_SETUP_ARMING_FAILSAFE_CUSTOM) ? " FAILSAFE_CUSTOM" : ""),
Expand Down
34 changes: 25 additions & 9 deletions src/modules/commander/Commander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2333,18 +2333,34 @@ Commander::run()
status.timestamp = hrt_absolute_time();
_status_pub.publish(status);

/* set prearmed state if safety is off, or safety is not present and 5 seconds passed */
if (safety.safety_switch_available) {

/* safety is off, go into prearmed */
armed.prearmed = safety.safety_off;
switch ((PrearmedMode)_param_com_prearm_mode.get()) {
case PrearmedMode::DISABLED:
/* skip prearmed state */
armed.prearmed = false;
break;

} else {
case PrearmedMode::ALWAYS:
/* safety is not present, go into prearmed
* (all output drivers should be started / unlocked last in the boot process
* when the rest of the system is fully initialized)
*/
* (all output drivers should be started / unlocked last in the boot process
* when the rest of the system is fully initialized)
*/
armed.prearmed = (hrt_elapsed_time(&commander_boot_timestamp) > 5_s);
break;

case PrearmedMode::SAFETY_BUTTON:
if (safety.safety_switch_available) {
/* safety switch is present, go into prearmed if safety is off */
armed.prearmed = safety.safety_off;

} else {
/* safety switch is not present, do not go into prearmed */
armed.prearmed = false;
}
break;

default:
armed.prearmed = false;
break;
}

armed.timestamp = hrt_absolute_time();
Expand Down
10 changes: 9 additions & 1 deletion src/modules/commander/Commander.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,18 @@ class Commander : public ModuleBase<Commander>, public ModuleParams

(ParamFloat<px4::params::COM_OF_LOSS_T>) _param_com_of_loss_t,
(ParamInt<px4::params::COM_OBL_ACT>) _param_com_obl_act,
(ParamInt<px4::params::COM_OBL_RC_ACT>) _param_com_obl_rc_act
(ParamInt<px4::params::COM_OBL_RC_ACT>) _param_com_obl_rc_act,

(ParamInt<px4::params::COM_PREARM_MODE>) _param_com_prearm_mode

)

enum class PrearmedMode {
DISABLED = 0,
SAFETY_BUTTON = 1,
ALWAYS = 2
};

const int64_t POSVEL_PROBATION_MIN = 1_s; /**< minimum probation duration (usec) */
const int64_t POSVEL_PROBATION_MAX = 100_s; /**< maximum probation duration (usec) */

Expand Down
14 changes: 14 additions & 0 deletions src/modules/commander/commander_params.c
Original file line number Diff line number Diff line change
Expand Up @@ -953,3 +953,17 @@ PARAM_DEFINE_INT32(COM_FLT_PROFILE, 0);
* @boolean
*/
PARAM_DEFINE_INT32(COM_ARM_CHK_ESCS, 1);

/**
* Condition to enter prearmed mode
*
* Condition to enter the prearmed state, an intermediate state between disarmed and armed
* in which non-throttling actuators are active.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is a non-throttling activator?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A non throttling actuator is an actuator that does not drive a motor/engine. The underlying assumption is that throttling actuator is dangerous and should not move until the system is armed, while non-throttling actuators (ailerons, flaps, camera gimbal, etc) are safer and can move before the system is armed.

Right now, throttling actuator is defined here (NaN means the actuator will stay in disarmed position) https://github.com/PX4/Firmware/blob/a20b508d7e60a1332e3c9ff18d69df4d5e04eb5d/src/drivers/px4fmu/fmu.cpp#L1062-L1070. But I would not bother documenting that too precisely as this is likely to change when we introduce metadata at the mixer level to indicate which output is safe to prearm.

*
* @value 0 Disabled
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So would I be correct in saying

  • Disabled means that this mode doesn't exist - if you try and arm you just go from disarmed to armed.
  • Safety button means that you enter this mode when you press the safety button. How then do you move forward to armed?
  • Always means that you just go to this mode.

Does this require any docs/mention other than in the param? Frankly I don't understand what it is for, how you move to armed from this state, what an end user needs to do, or when they would set it.

Copy link
Contributor Author

@jlecoeur jlecoeur Aug 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct.

How then do you move forward to armed?

As usual: arm switch, or arm stick motion, or MAVLink command

Does this require any docs/mention other than in the param?

Frankly I think some doc is needed here.
In fact, I was not aware of this state before I loaded a custom mixer on an airframe with the safety switch disabled (CBRK_IO_SAFETY), and the actuators started moving right after plugging the battery! This is now fixed with this PR: if you disable the safety switch the system will not prearm on its own by default.

From the user perspective, "prearmed" means "my ailerons move but my propellers do not spin".

In the default case of a system with safety button (COM_PREARM_MODE=Safety button and CBRK_IO_SAFETY=0), the behaviour is

  • power up
  • all actuators are locked into disarmed position, it is not possible to arm
  • safety switch is pressed. The system is now prearmed: non-throttling actuators start moving. System safety is off: it is now possible to arm
  • arm command is issued: The system is armed: all actuators move

Now the non default cases:
COM_PREARM_MODE=Disabled:

  • power up
  • all actuators are locked into disarmed position, it is not possible to arm
  • safety switch is pressed. All actuators stay locked into disarmed position. System safety is off: it is now possible to arm
  • arm command is issued: The system is armed: all actuators move

COM_PREARM_MODE=Always:

  • power up
  • The system is now prearmed: non-throttling actuators start moving. Safety is on: it is not possible to arm
  • safety switch is pressed. System safety is off: it is now possible to arm
  • arm command is issued: The system is armed: all actuators move

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And now for systems without safety button.

COM_PREARM_MODE=Safety button and CBRK_IO_SAFETY is engaged:

  • power up
  • all actuators are locked into disarmed position. System safety is off: it is possible to arm.
  • arm command is issued: The system is armed: all actuators move

COM_PREARM_MODE=Disabled and CBRK_IO_SAFETY is engaged:
Same as above

COM_PREARM_MODE=Always and CBRK_IO_SAFETY is engaged:

  • power up
  • The system is now prearmed: non-throttling actuators start moving. Safety is off: it is possible to arm.
  • arm command is issued: The system is armed: all actuators move

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I have created PX4/PX4-user_guide#567 to track this. I won't have time for it this week - feel free to find a place where you think docs should go if you need it in earlier.

* @value 1 Safety button
* @value 2 Always
*
* @group Commander
*/
PARAM_DEFINE_INT32(COM_PREARM_MODE, 1);
9 changes: 6 additions & 3 deletions src/modules/px4iofirmware/mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,12 @@ mixer_tick(void)
);

should_arm_nothrottle = (
(r_status_flags & PX4IO_P_STATUS_FLAGS_INIT_OK) /* IO initialised without error */
&& (r_status_flags & PX4IO_P_STATUS_FLAGS_SAFETY_OFF) /* and IO is armed */
&& (r_status_flags & PX4IO_P_STATUS_FLAGS_MIXER_OK) /* and there is valid input via or mixer */
(r_status_flags & PX4IO_P_STATUS_FLAGS_INIT_OK) /* IO initialised without error */
&& (r_status_flags & PX4IO_P_STATUS_FLAGS_SAFETY_OFF) /* and IO is armed */
&& (((r_setup_arming & PX4IO_P_SETUP_ARMING_FMU_PREARMED) /* and FMU is prearmed */
&& (r_status_flags & PX4IO_P_STATUS_FLAGS_MIXER_OK)) /* and there is valid input via or mixer */
|| (r_status_flags & PX4IO_P_STATUS_FLAGS_RAW_PWM) /* or direct PWM is set */
)
);

should_always_enable_pwm = (
Expand Down
19 changes: 10 additions & 9 deletions src/modules/px4iofirmware/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,16 @@
#define PX4IO_P_SETUP_ARMING 1 /* arming controls */
#define PX4IO_P_SETUP_ARMING_IO_ARM_OK (1 << 0) /* OK to arm the IO side */
#define PX4IO_P_SETUP_ARMING_FMU_ARMED (1 << 1) /* FMU is already armed */
#define PX4IO_P_SETUP_ARMING_MANUAL_OVERRIDE_OK (1 << 2) /* OK to switch to manual override via override RC channel */
#define PX4IO_P_SETUP_ARMING_FAILSAFE_CUSTOM (1 << 3) /* use custom failsafe values, not 0 values of mixer */
#define PX4IO_P_SETUP_ARMING_INAIR_RESTART_OK (1 << 4) /* OK to try in-air restart */
#define PX4IO_P_SETUP_ARMING_ALWAYS_PWM_ENABLE (1 << 5) /* Output of PWM right after startup enabled to help ESCs initialize and prevent them from beeping */
#define PX4IO_P_SETUP_ARMING_RC_HANDLING_DISABLED (1 << 6) /* Disable the IO-internal evaluation of the RC */
#define PX4IO_P_SETUP_ARMING_LOCKDOWN (1 << 7) /* If set, the system operates normally, but won't actuate any servos */
#define PX4IO_P_SETUP_ARMING_FORCE_FAILSAFE (1 << 8) /* If set, the system will always output the failsafe values */
#define PX4IO_P_SETUP_ARMING_TERMINATION_FAILSAFE (1 << 9) /* If set, the system will never return from a failsafe, but remain in failsafe once triggered. */
#define PX4IO_P_SETUP_ARMING_OVERRIDE_IMMEDIATE (1 << 10) /* If set then on FMU failure override is immediate. Othewise it waits for the mode switch to go past the override thrshold */
#define PX4IO_P_SETUP_ARMING_FMU_PREARMED (1 << 2) /* FMU is already prearmed */
jlecoeur marked this conversation as resolved.
Show resolved Hide resolved
#define PX4IO_P_SETUP_ARMING_MANUAL_OVERRIDE_OK (1 << 3) /* OK to switch to manual override via override RC channel */
#define PX4IO_P_SETUP_ARMING_FAILSAFE_CUSTOM (1 << 4) /* use custom failsafe values, not 0 values of mixer */
#define PX4IO_P_SETUP_ARMING_INAIR_RESTART_OK (1 << 5) /* OK to try in-air restart */
#define PX4IO_P_SETUP_ARMING_ALWAYS_PWM_ENABLE (1 << 6) /* Output of PWM right after startup enabled to help ESCs initialize and prevent them from beeping */
#define PX4IO_P_SETUP_ARMING_RC_HANDLING_DISABLED (1 << 7) /* Disable the IO-internal evaluation of the RC */
#define PX4IO_P_SETUP_ARMING_LOCKDOWN (1 << 8) /* If set, the system operates normally, but won't actuate any servos */
#define PX4IO_P_SETUP_ARMING_FORCE_FAILSAFE (1 << 9) /* If set, the system will always output the failsafe values */
#define PX4IO_P_SETUP_ARMING_TERMINATION_FAILSAFE (1 << 10) /* If set, the system will never return from a failsafe, but remain in failsafe once triggered. */
#define PX4IO_P_SETUP_ARMING_OVERRIDE_IMMEDIATE (1 << 11) /* If set then on FMU failure override is immediate. Othewise it waits for the mode switch to go past the override thrshold */

#define PX4IO_P_SETUP_PWM_RATES 2 /* bitmask, 0 = low rate, 1 = high rate */
#define PX4IO_P_SETUP_PWM_DEFAULTRATE 3 /* 'low' PWM frame output rate in Hz */
Expand Down
1 change: 1 addition & 0 deletions src/modules/px4iofirmware/registers.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ volatile uint16_t r_page_setup[] = {
PX4IO_P_SETUP_FEATURES_PWM_RSSI)

#define PX4IO_P_SETUP_ARMING_VALID (PX4IO_P_SETUP_ARMING_FMU_ARMED | \
PX4IO_P_SETUP_ARMING_FMU_PREARMED | \
PX4IO_P_SETUP_ARMING_MANUAL_OVERRIDE_OK | \
PX4IO_P_SETUP_ARMING_INAIR_RESTART_OK | \
PX4IO_P_SETUP_ARMING_IO_ARM_OK | \
Expand Down