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

commander: collapse ArmStateMachine and simplify #21129

Merged
merged 6 commits into from
Jul 28, 2023

Conversation

dagar
Copy link
Member

@dagar dagar commented Feb 15, 2023

  • simplify vehicle_status.arming_state down to just armed and disarmed
    • ARMING_STATE_INIT doesn't matter
    • ARMING_STATE_STANDBY is effectively pre_flight_checks_pass
    • ARMING_STATE_STANDBY_ERROR not needed
    • ARMING_STATE_SHUTDOWN effectively not used (all the poweroff/shutdown calls loop forever in place)
    • ARMING_STATE_IN_AIR_RESTORE doesn't exist anymore
  • collapse ArmStateMachine into commander
    • all requests already go through Commander::arm() and Commander::dismarm()
  • other minor changes
    • VEHICLE_CMD_DO_FLIGHTTERMINATION undocumented (unused?) test command (param1 > 1.5f) removed
    • switching to NAVIGATION_STATE_TERMINATION triggers parachute command centrally (only if armed)

There's still some overlap and duplication between actuator_armed and vehicle_status that we can consolidate.

I don't particularly like all the scattered HIL_STATE_ON checks, these should really be nearly entirely eliminated.

@dagar dagar force-pushed the pr-commander_arming_state_machine_collapse branch from 69a6b14 to edf4388 Compare February 15, 2023 03:13
@dagar dagar requested a review from MaEtUgR February 15, 2023 03:16
@dagar dagar force-pushed the pr-commander_arming_state_machine_collapse branch 6 times, most recently from 33ba4a0 to dd21af4 Compare February 15, 2023 05:47
Copy link
Member

@MaEtUgR MaEtUgR left a comment

Choose a reason for hiding this comment

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

In my eyes this is a very valuable simplification. There is a lot of distributed, glanced-over, unnecessary complexity in this logic and after going through I'm reasonably sure you captured all important bits. The cases for which I'm not so sure I made a comment. We have to test these through if it didn't happen already but it's certainly worth it because things get much more deterministic.

Some small suggestions I'll add in a commit.

@@ -2368,7 +2324,7 @@ void Commander::control_status_leds(bool changed, const uint8_t battery_warning)
BOARD_ARMED_LED_ON();
}

} else if (_arm_state_machine.isStandby()) {
} else if (_vehicle_status.pre_flight_checks_pass) {
Copy link
Member

Choose a reason for hiding this comment

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

pre_flight_checks_pass should not pass if we are currently calibrating then.

src/modules/commander/Commander.cpp Outdated Show resolved Hide resolved

// reject if armed or shutting down
answer_command(cmd, vehicle_command_ack_s::VEHICLE_CMD_RESULT_TEMPORARILY_REJECTED);

} else {

/* try to go to INIT/PREFLIGHT arming state */
Copy link
Member

Choose a reason for hiding this comment

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

Temperature calibration is the only case that sets neither calibration_enabled nor rc_calibration_in_progress. Are we sure we can't arm in temperature calibration?

|| (!actuator_armed_prev.manual_lockdown && _actuator_armed.manual_lockdown)
) {
if (isArmed()) {
send_parachute_command();
Copy link
Member

Choose a reason for hiding this comment

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

There was previously a guard that did not allow triggering the parachute multiple times except for when resetting for test purposes with the undocumented unterminate command. I don't see why this should be an issue but wanted to note that it's a change in behaviour.

} else {
_actuator_armed.force_failsafe = false;
_actuator_armed.lockdown = false;
if (!isArmed()) {
Copy link
Member

@MaEtUgR MaEtUgR Mar 9, 2023

Choose a reason for hiding this comment

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

Shouldn't there be a way to terminate before arming for testing? I'm asking because the DRS parachute mechanism to my knowledge can/should be tested before arming.

Copy link
Contributor

Choose a reason for hiding this comment

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

Terminate before arming? Doesn't sound intuitive to me, to be honest.


_lockdown_triggered = false;
_flight_termination_triggered = false;
} else if (_user_mode_intention.change(vehicle_status_s::NAVIGATION_STATE_TERMINATION)) {
Copy link
Member

Choose a reason for hiding this comment

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

Are there additional conditions to enter termination then? Can we then unterminate by switching mode? Could that happen unintentionally? We could chop up the parachute in that case no?

return TRANSITION_NOT_CHANGED;
}

if (_vehicle_status.calibration_enabled
Copy link
Member

Choose a reason for hiding this comment

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

Best we move all of these additional

  • calibration
  • Throttle too high
  • armed by RC

checks into the _health_and_arming_checks next. Probably it needs to know calling reason if that's not the case already.

if (valid_transition
&& (new_arming_state == vehicle_status_s::ARMING_STATE_ARMED)
&& fRunPreArmChecks
&& !(status.hil_state == vehicle_status_s::HIL_STATE_ON)
Copy link
Member

Choose a reason for hiding this comment

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

It could be that HIL now fails certain preflight checks that were skipped in an obfuscated way before. We need to test it and go through these if that didn't happen already.

}

// system_status overrides
if (actuator_armed.force_failsafe || actuator_armed.lockdown || actuator_armed.manual_lockdown
|| vehicle_status.nav_state == vehicle_status_s::NAVIGATION_STATE_TERMINATION) {

system_status = MAV_STATE_FLIGHT_TERMINATION;

} else if (vehicle_status.calibration_enabled) {
Copy link
Member

Choose a reason for hiding this comment

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

Since we can't calibrate while being armed this "override" doesn't make sense. The valid case is already handled above.

@MaEtUgR MaEtUgR force-pushed the pr-commander_arming_state_machine_collapse branch from dd21af4 to 09f41da Compare March 10, 2023 10:12
@MaEtUgR
Copy link
Member

MaEtUgR commented Mar 10, 2023

I rebased the pr without conflict and added my suggestions in additional commits.
The points to take special care of sorted by subjective severty are:

  1. Do HIL, HITL, SIH pass preflight checks?
    commander: collapse ArmStateMachine and simplify #21129 (comment)
  2. Can terminate be denied? _user_mode_intention.change(vehicle_status_s::NAVIGATION_STATE_TERMINATION)
    commander: collapse ArmStateMachine and simplify #21129 (comment)
  3. Parachute triggerable multiple times, unterminate with (accidental) mode change?
    commander: collapse ArmStateMachine and simplify #21129 (comment)
  4. While calibrating pre-flight checks should not pass for consistent reporting to work.
    commander: collapse ArmStateMachine and simplify #21129 (comment)
  5. No way to test trigger parachute on the ground, should probably not be easy but somehow possible
    commander: collapse ArmStateMachine and simplify #21129 (comment)
  6. Is it possible to arm in temperature calibration because none of the calibration flags are set?
    commander: collapse ArmStateMachine and simplify #21129 (comment)

@DronecodeBot
Copy link

This pull request has been mentioned on Discussion Forum for PX4, Pixhawk, QGroundControl, MAVSDK, MAVLink. There might be relevant details there:

https://discuss.px4.io/t/px4-maintainers-call-may-16-2023/32137/1

Copy link
Contributor

@julianoes julianoes left a comment

Choose a reason for hiding this comment

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

Nice! I couldn't spot anything obviously wrong.

} else {
_actuator_armed.force_failsafe = false;
_actuator_armed.lockdown = false;
if (!isArmed()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Terminate before arming? Doesn't sound intuitive to me, to be honest.

@dagar dagar merged commit 88e7452 into main Jul 28, 2023
83 of 84 checks passed
@dagar dagar deleted the pr-commander_arming_state_machine_collapse branch July 28, 2023 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants