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

Extend Failure Detector functionalities #14766

Merged
merged 3 commits into from
Jul 1, 2020
Merged

Extend Failure Detector functionalities #14766

merged 3 commits into from
Jul 1, 2020

Conversation

cmic0
Copy link
Contributor

@cmic0 cmic0 commented Apr 26, 2020

Describe problem solved by this pull request
Main goal of this PR is to extend Failure Detector logic to handle ESC arming state.

Some types of ESC require that you send them an arm command before they can actually spin.
If they succeed transitioning to the armed state, they will send back an acknowledgment to PX4.

This PR extends Failure Detector logic to handle this kind of information:
after the vehicle is armed Failure Detector will wait 300_ms to get an answer from the ESCs.
If within this time window all the ESCs do not report to be armed Failure Detector will auto disarm the vehicle.

Checks are performed using esc_status.esc_armed_flags .

During the development of this PR i've also addressed the following points:

  • Added autodisarm if system is in lockdown. Having the vehicle in lockdown but still armed can be really misleading from a UX standpoint.

  • Avoid triggering flight termination if vehicle is already in a lockdown state

  • Introduced a parameter COM_LKDOWN_TKO to extend/disable the "lockdown window".
    In some development cases it might be super useful having this logic disabled.

bresch
bresch previously approved these changes May 26, 2020
Copy link
Member

@bresch bresch left a comment

Choose a reason for hiding this comment

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

Ok, we tested that internally for quite some time so it should be safe to merge. However, if we start to put all kinds of failure detection in this class, we might need to review the architecture (and also replace the bitmask with booleans).

@bresch bresch force-pushed the pr-failure-detector branch from 1913a23 to b3c10ea Compare May 26, 2020 07:04
@bresch
Copy link
Member

bresch commented May 26, 2020

I rebased on top of master to re-run the CI checks

@bresch bresch self-requested a review May 26, 2020 07:04
bresch
bresch previously approved these changes May 26, 2020
mavlink_log_critical(&mavlink_log_pub, "ESCs did not respond to arm request");
}

} else if (hrt_elapsed_time(&_time_at_takeoff) < (1_s * _param_com_lkdown_tko.get())) {
Copy link
Member

Choose a reason for hiding this comment

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

Why is this an else? It means during the first 500ms you don't check this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I originally made it like this because if you use PWM outputs in the first 500ms the signal is still in the spoolup phase, thus the vehicle has not yet taken off.

This probably does not hold if you use UAVCAN, right?

Copy link
Member

Choose a reason for hiding this comment

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

No, and I'd like to avoid these kind of dependencies and implicit assumptions.

src/modules/commander/commander_params.c Show resolved Hide resolved
* Time-out for detecting a failure after takeoff
*
* A non-zero, positive value specifies the timeframe in seconds within Failure Detector is allowed to put the vehicle into
* a lockdown state if attitude exceeds the defined limits.
Copy link
Member

Choose a reason for hiding this comment

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

This does not hold for all flight modes. Can you either clarify or better reference where it is clearly described?

bool status_changed = _status != FAILURE_NONE;
_status = FAILURE_NONE;

int attitude_fields_bitmask = _status & (FAILURE_ARM_ESCS - 1);
Copy link
Member

Choose a reason for hiding this comment

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

This is not very robust. I'd rather enumerate all attitude bits.

updated |= resetAttitudeStatus();
}

if (areEscSmart()) {
Copy link
Member

Choose a reason for hiding this comment

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

This does not do what I would expect from the method name.
Rather use _sub_esc_status.updated() directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed


/**
* Enable checks on ESCs that report their 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.

Might be worth describing which checks and the consequences of a failed check

@hamishwillee
Copy link
Contributor

Would I be correct in thinking that this has no docs implication? - current failure detector docs are here: http://docs.px4.io/master/en/config/safety.html#failure_detector

@bresch
Copy link
Member

bresch commented Jun 25, 2020

@cmic0 Could you please address Beat's comments please?

bool status_changed = _status != FAILURE_NONE;
_status = FAILURE_NONE;

int attitude_fields_bitmask = _status & (FAILURE_ROLL | FAILURE_PITCH | FAILURE_ALT | FAILURE_EXT);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bresch / @bkueng I could not come up with a better naming for this variable.. given that contains FAILURE_ALT and FAILURE_EXT is not really an attitude_fields_bitmask .. any suggestion?

Copy link
Member

Choose a reason for hiding this comment

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

non_esc_bitmask? Otherwise this is fine.

@cmic0
Copy link
Contributor Author

cmic0 commented Jun 29, 2020

Would I be correct in thinking that this has no docs implication? - current failure detector docs are here: http://docs.px4.io/master/en/config/safety.html#failure_detector

@hamishwillee I'd say we would need to add something to this sentence:
The failure detector is active in all vehicle types and modes, except for those where the vehicle is expected to do flips (i.e. Acro mode (MC), Acro mode (FW), Rattitude and Manual (FW)).

as now can be disabled with COM_LKDOWN_TKO

src/modules/commander/commander_params.c Outdated Show resolved Hide resolved
bool status_changed = _status != FAILURE_NONE;
_status = FAILURE_NONE;

int attitude_fields_bitmask = _status & (FAILURE_ROLL | FAILURE_PITCH | FAILURE_ALT | FAILURE_EXT);
Copy link
Member

Choose a reason for hiding this comment

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

non_esc_bitmask? Otherwise this is fine.

@cmic0
Copy link
Contributor Author

cmic0 commented Jun 30, 2020

@bkueng addressed the final comments. Let me know if you want me to clean the commit history up or if this is already good to go

Copy link
Member

@bkueng bkueng left a comment

Choose a reason for hiding this comment

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

Yes please clean up the history.
And one more detail, otherwise this looks good.

_esc_failure_hysteresis.set_state_and_update(false, time_now);
_status &= ~FAILURE_ARM_ESCS;
updated = true;
Copy link
Member

Choose a reason for hiding this comment

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

This should not always return true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cmic0 added 3 commits June 30, 2020 13:35
    - Introduced COM_LKDOWN_TKO parameter
    - Introduced auto disarm for lockdown state
    - Do not trigger flight termiantion if system is in lockdown

Signed-off-by: Claudio Micheli <[email protected]>
@cmic0 cmic0 force-pushed the pr-failure-detector branch from 2f7e5cf to 0fab8ff Compare June 30, 2020 11:45
// reset ESC bitfield
_esc_failure_hysteresis.set_state_and_update(false, time_now);

if (_status & FAILURE_ARM_ESCS) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bkueng this should guarantee that the status is updated only if the bit is reset.

dagar added a commit that referenced this pull request Sep 6, 2020
 - auto disarm when locked down was added in #14766 to prevent user
confusion in regular usage, but also breaks HITL where lockdown is
enabled for safety
 - fixes #15686
dagar added a commit that referenced this pull request Sep 6, 2020
 - auto disarm when locked down was added in #14766 to prevent user confusion in regular usage, but also breaks HITL where lockdown is enabled for safety
 - fixes #15686
dagar added a commit that referenced this pull request Sep 6, 2020
 - auto disarm when locked down was added in #14766 to prevent user confusion in regular usage, but also breaks HITL where lockdown is enabled for safety
 - fixes #15686
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