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: fix battery failsafe without GPS #13294

Merged
merged 2 commits into from
Nov 5, 2019

Conversation

julianoes
Copy link
Contributor

@julianoes julianoes commented Oct 28, 2019

This fixes the battery failsafe for the following corner cases:

  • Battery failsafe set to Return but we can't do RTL because we don't have a global position or home position. In this case we now switch to Land. Land might end up in Descend in the failsafe state machine later.
  • Battery failsafe set to Land but we can't land because we don't have a local position. In this case we switch to land anyway and then fall back to descend in the failsafe state machine later.

The "fix" involves ignoring using the main_state_transition and implementing the guards in place. This is a hack for now but should cover the corner case until a more thorough refactor.

The different failsafe state machines have involved over time from requirements and learnings based on developed solutions and products. The implementations in various places will need to get consolidated in the future.

Tested in SITL for Return and Land with and without GPS.

Fixes #13291.

@julianoes
Copy link
Contributor Author

@PX4/testflights please test this on the cheapest frame as follows:

For these tests I suggest to set the battery failsafe thresholds higher in QGC -> Settings -> Safety. (e.g. warning at 60%, failsafe at 50%, emergency at 20%. That way you don't need to risk damaging batteries.

Selection_062

Test 1: Land with GPS

  1. Set the battery failsafe action to "Land" Mode.
  2. Fly in POSCTL 2m above a possible landing spot.
  3. Wait for the critical battery warning to appear. It should then nicely land.

Test 2: Land without GPS -> only when no wind!

  1. Set the battery failsafe action to "Land" Mode.
  2. Disable GPS by doing gps stop in mavlink_shell.
  3. Fly in ALTCL 2m above a possible landing spot (and some space for drift with wind).
  4. Wait for the critical battery warning to appear. It should then descend (but drift with the wind).

Test 3: RTL with GPS

  1. Set the battery failsafe action to "Return mode at critically low level, Land mode at ..." Mode.
  2. Fly in POSCTL maybe at 5m maybe about 10m from the takeoff position.
  3. Wait for the critical battery warning to appear. It should then do RTL as usual. If the emergency battery level is also triggered it will switch to Land which would happen if the battery estimate goes down quickly.

Test 4: RTL without GPS -> only when no wind!

  1. Set the battery failsafe action to "Return mode at critically low level, Land mode at ..." Mode.
  2. Disable GPS by doing gps stop in mavlink_shell.
  3. Fly in ALTCL 2m above a possible landing spot (and some space for drift with wind).
  4. Wait for the critical battery warning to appear. It should then descend (but drift with the wind).

Thanks and let me know if you have any questions!

@LorenzMeier
Copy link
Member

@julianoes Thanks for providing a really good test plan. You're setting a very good example with that and a lot of PRs are lacking that.

This fixes the battery failsafe for the following corner cases:
- Battery failsafe set to Return but we can't do RTL because we don't
  have a global position or home position. In this case we now switch to
  Land. Land might end up in Descend in the failsafe state machine
  later.
- Battery failsafe set to Land but we can't land because we don't have a
  local position. In this case we switch to land anyway and then fall
  back to descend in the failsafe state machine later.

The "fix" involves ignoring using the main_state_transition and
implementing the guards in place. This is a hack for now but should
cover the corner case until a more thorough refactor.

The different failsafe state machines have involved over time from
requirements and learnings based on developed solutions and products.
The implementations in various places will need to get consolidated in
the future.

Tested in SITL for Return and Land with and without GPS.
Copy link
Contributor

@potaito potaito left a comment

Choose a reason for hiding this comment

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

To me it is now clearer what happens when RTL or similar are executing without GPS.

Commander / Safety automation moved this from In progress to Reviewer approved Oct 28, 2019
@Tony3dr Tony3dr added this to Ready for testing in Test Flights Oct 28, 2019
@dagar dagar added this to the Release v1.10.0 milestone Oct 28, 2019
@dannyfpv
Copy link

dannyfpv commented Oct 29, 2019

Tested on Pixhawk v4pro f-450

Test 1: Land with GPS
Note:
Waited for the critical battery to appear the vehicle landed smoothly only issue is that the vehicle did not disarm after landing.
Log:
https://review.px4.io/plot_app?log=4633646c-e55e-4c54-8c6f-a8df6c1502bf

Test 2: Land without GPS
Note:
Waited for the critical battery warning to appear. The vehicle descends, drifted with the wind. Only issue is that the vehicle did not disarm after landing.
Log:
https://review.px4.io/plot_app?log=056f0e27-9da1-4c55-8c99-196ad6f7620b

Test 3: RTL with GPS
Notes:
Set the battery failsafe action to "Return mode at critically low level, Land mode at ..." Mode.
Waited for the critical battery warning to appear. The vehicle triggered RTL. The only issue noted is that the vehicle did not disarm after landing.
Logs:
https://review.px4.io/plot_app?log=399723f5-89dc-4a6b-8b3e-957c3d5117f3

Test 4: RTL without GPS
Notes:
Set the battery failsafe action to "Return mode at critically low level, Land mode at ..." Mode.
Waited for the critical battery warning to appear. The vehicle descends, drifted with the wind. The only issue noted is that the vehicle did not disarm after landing.
Logs:
https://review.px4.io/plot_app?log=0051d897-b88e-44ae-9c0c-376e6eacc30c
@julianoes the test was completed, everything seemed to work as expected, except in all the tests the vehicle did not disarm upon touching the ground.

@julianoes
Copy link
Contributor Author

@dannyfpv Thanks a lot for testing and the logs. I'm investigating the problem where it does not auto-disarm on landing. From the log I can see that landing is detected but then disarm does not happen. I can't reproduce this behaviour in SITL, so I'm wondering what might be different.

One thing that caught my eye is the weird noise/spikes in the mag values. It's something we need to investigate. I don't know if this has something to do with the fact that auto-disarm does not work.

@dagar dagar moved this from To Do to In progress in Release 1.11 Blockers Oct 30, 2019
@Tony3dr
Copy link

Tony3dr commented Oct 30, 2019

FC: PixhawkPro
Frame: DJI F450
GPS: CUAV U-Blox NEO-M8N High Precision GPS
ESC: 20A
Motors: Tmotors 2212-920kv
log A log with logging set from boot
https://review.px4.io/plot_app?log=49829594-e88e-4f85-8740-6b2f7bf87c47&fbclid=IwAR1vs4sYoGntIlDX6kiA_58IYzI2y26o6n-Zo_7NfdaaunZl9lXonkU9zls
74163540_262094918040779_245516866263449600_n
@julianoes

@julianoes
Copy link
Contributor Author

@dannyfpv @Tony3dr I'm trying to figure out if auto disarm did not work or if landing was not detected (and therefore auto disarm did not work). Do you remember?

From the logfiles, I'm not entirely sure. In some logfiles you switch to manual, in others you seem to use the kill switch.

@Tony3dr
Copy link

Tony3dr commented Oct 31, 2019

@dannyfpv @Tony3dr I'm trying to figure out if auto disarm did not work or if landing was not detected (and therefore auto disarm did not work). Do you remember?

From the logfiles, I'm not entirely sure. In some logfiles you switch to manual, in others you seem to use the kill switch.

@julianoes the landing was detected, once the vehicle triggered the failsafe landing was detected. The reason why we switched to manual is to disarm the vehicle by using the kill switch. We can give it another go on Monday. Get more data to see if we can figure out what could be the issue.

@@ -1194,13 +1195,9 @@ void battery_failsafe(orb_advert_t *mavlink_log_pub, const vehicle_status_s &sta

// FALLTHROUGH
case LOW_BAT_ACTION::LAND:
if (TRANSITION_DENIED != main_state_transition(status, commander_state_s::MAIN_STATE_AUTO_LAND, status_flags,
Copy link
Contributor

Choose a reason for hiding this comment

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

@julianoes Sorry, I can't comment on a line which you did not change but don't you need to put the LOW_BAT_ACTION::RETURN_OR_LAND case before the LOW_BAT_ACTION::RETURN case, as you have done for the critical battery level section? As I understand it will otherwise fall through to landing and never RTL.

Copy link
Contributor Author

@julianoes julianoes Nov 1, 2019

Choose a reason for hiding this comment

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

I think this is correct because in the emergency case we want to land, so we fallthrough to land.

In the critical (non-emergency) case we still do RTL.

Commander / Safety automation moved this from Reviewer approved to Review in progress Nov 1, 2019
@dannyfpv
Copy link

dannyfpv commented Nov 2, 2019

Tested on Pixhawk4 v5 f-450

Test 1: Land with GPS
Note:
Waited for the critical battery to appear the vehicle landed smoothly only issue is that the vehicle did not disarm after landing.
Log:
https://review.px4.io/plot_app?log=242b4d47-50f1-4975-9000-a5df63b92175

Test 2: Land without GPS
Note:
Waited for the critical battery warning to appear. The vehicle descends, drifted with the wind. The only issue is that the vehicle did not disarm after landing.
Log:
https://review.px4.io/plot_app?log=f34aeffd-50e4-48a3-a23d-69cadc351a12

Test 3: RTL with GPS
Notes:
Set the battery failsafe action to "Return mode at a critically low level, Land mode at ..." Mode.
Waited for the critical battery warning to appear. The vehicle triggered RTL. The only issue noted is that the vehicle did not disarm after landing.
Logs:
https://review.px4.io/plot_app?log=c6e55aaa-f026-407a-bcad-29b7a73ee04c

Test 4: RTL without GPS
Notes:
Set the battery failsafe action to "Return mode at a critically low level, Land mode at ..." Mode.
Waited for the critical battery warning to appear. The vehicle descends, drifted with the wind. The only issue noted is that the vehicle did not disarm after landing.
Logs:
https://review.px4.io/plot_app?log=e5602465-fc8e-4c44-a351-2a39ea96e114

@julianoes the same behavior in all the tests the vehicle did not disarm upon touching the ground.

@julianoes
Copy link
Contributor Author

@dannyfpv when you do a normal RTL with the same vehicle on master: does auto-disarm work?

@julianoes
Copy link
Contributor Author

@dannyfpv I think your logs got a bit messed up above. The first two both seem to have GPS.

@julianoes
Copy link
Contributor Author

@Tony3dr:

@julianoes the landing was detected, once the vehicle triggered the failsafe landing was detected.

Does that mean that the failsafe was done or that landing was actually detected and the props were spinning slower (but not disarmed)?

@julianoes
Copy link
Contributor Author

From the logs I can tell that the problem seems to be the land estimator not triggering, rather than auto-disarm not working.

@bresch I'm looking at this log and I can't figure out why the land detector doesn't trigger:
https://review.px4.io/plot_app?log=f34aeffd-50e4-48a3-a23d-69cadc351a12

@Tony3dr
Copy link

Tony3dr commented Nov 4, 2019

@dannyfpv I think your logs got a bit messed up above. The first two both seem to have GPS.
@julianoes sorry about that it looks like the order of the logs is off, see below.
Test 1: Land with GPS
https://review.px4.io/plot_app?log=242b4d47-50f1-4975-9000-a5df63b92175
https://review.px4.io/plot_app?log=f34aeffd-50e4-48a3-a23d-69cadc351a12

Test 2: Land without GPS
https://review.px4.io/plot_app?log=c6e55aaa-f026-407a-bcad-29b7a73ee04c

Test 3: RTL with GPS
https://review.px4.io/plot_app?log=f34aeffd-50e4-48a3-a23d-69cadc351a12

@Tony3dr
Copy link

Tony3dr commented Nov 4, 2019

@dannyfpv when you do a normal RTL with the same vehicle on master: does auto-disarm work?
@julianoes we will post a couple of logs of the Master branch, later on, today we posted a couple in #13321, The landing problem is apparently an issue on current Master that is been worked on.

@dannyfpv
Copy link

dannyfpv commented Nov 4, 2019

tested on pixhawk4 v4 f-450
master firmware
mission mode: no issue
rtl: not disarm on land mode
log:
https://review.px4.io/plot_app?log=2f5469ab-ab04-4d7e-896e-11808f94a2df

tested on pixhawk v4pro f-450
master firmware
mission mode: no issue
rtl: not disarm on land mode
log:
https://review.px4.io/plot_app?log=2f440dd7-657f-4d11-aa3c-54474af3e352

@julianoes
Copy link
Contributor Author

Ok, I'll merge this given the land detection issues are unrelated.

@julianoes julianoes merged commit 4ff4f5c into master Nov 5, 2019
Release 1.11 Blockers automation moved this from In progress to Done Nov 5, 2019
Test Flights automation moved this from Ready for testing to Done Nov 5, 2019
Commander / Safety automation moved this from Review in progress to Done Nov 5, 2019
@julianoes julianoes deleted the fix-battery-failsafe-nogps branch November 5, 2019 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Battery failsafe does not cause DESCEND if local position not available
7 participants