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

navigator: fix triplet resetting/publication logic #13534

Merged
merged 4 commits into from Nov 23, 2019
Merged

Conversation

julianoes
Copy link
Contributor

The navigator has a notion of resetting the triplets which means the triplet setpoints are set to invalid and therefore not to be used by downstream modules such as flight tasks.

However, before this patch, the triplets were not published if invalid meaning that a valid triplet would stay the truth until a new valid triplet would get published.

E.g. this lead to the corner case case where we publish a valid triplet with an IDLE setpoint on ground in HOLD and then don't update the triplet while flying in POSCTL mode. Later, when RTL is engaged, the flight task will use IDLE until navigator (which runs slower) has published the next triplet.

The fix involves two main changes:

  • Publish invalid triplets to avoid stale triplets.
  • Avoid publishing the triplet on every iteration in manual modes by not setting _pos_sp_triplet_published_invalid_once = false.

When testing this I realized that a mission upload during RTL would stop RTL. This is because the mission is updated while the mission navigation mode is not active and reset_triplets() is called from there. This is now only done for the case where we are actually in mission navigation
mode. The fact that a mission is updated when not active also seems wrong and is something to fix another time.

Fixes #13533.

The navigator has a notion of resetting the triplets which means the
triplet setpoints are set to invalid and therefore not to be used by
downstream modules such as flight tasks.

However, before this patch, the triplets were not published if invalid
meaning that a valid triplet would stay the truth until a new valid
triplet would get published.

E.g. this lead to the corner case case where we publish a valid triplet
with an IDLE setpoint on ground in HOLD and then don't update the
triplet while flying in POSCTL mode. Later, when RTL is engaged, the
flight task will use IDLE until navigator (which runs slower) has
published the next triplet.

The fix involves two main changes:
- Publish invalid triplets to avoid stale triplets.
- Avoid publishing the triplet on every iteration in manual modes by not
  setting `_pos_sp_triplet_published_invalid_once = false`.

When testing this I realized that a mission upload during RTL would stop
RTL. This is because the mission is updated while the mission navigation
mode is not active and reset_triplets() is called from there. This is
now only done for the case where we are actually in mission navigation
mode. The fact that a mission is updated when not active also seems
wrong and is something to fix another time.
@julianoes
Copy link
Contributor Author

@PX4/testflights please test this. In particular test the following scenarious:

  1. Fly a mission, then halfway during the mission, change the mission plan, upload it and fly that.
  2. Fly a mission, switch to HOLD, back to mission, then RTL.
  3. Fly a mission, switch to POSCTL, back into mission, then RTL.
  4. Set vehicle to HOLD mode on ground, then arm, don't takeoff, disarm again. Then do a flight in POSCTL and trigger RTL after a while.

Thx!

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.

Looking through the changes it's much more logical now. Also I did some SITL testing of the original cases we had when finding the issue and it always published exactly as expected. Thanks for looking into it @julianoes 👍

@julianoes
Copy link
Contributor Author

@Tony3dr see test instructions above! Would be great if you could test this. And make sure to use a stock slow SD card.

@Tony3dr Tony3dr added this to Ready for testing in Test Flights Nov 22, 2019
@jorge789
Copy link

Tested on PixRacer V4:

  1. Fly a mission, then halfway during the mission, change the mission plan, upload it and fly that.
    Log: https://review.px4.io/plot_app?log=e64b7ac4-a54e-45d3-9a83-842c78832982

  2. Fly a mission, switch to HOLD, back to mission, then RTL.
    Log: https://review.px4.io/plot_app?log=e1571b56-48d4-4601-b5be-45ca9d87499c

  3. Fly a mission, switch to POSCTL, back into mission, then RTL.
    Log: https://review.px4.io/plot_app?log=aecfe690-38ef-4e94-b594-9b0658219e6f

  4. Set vehicle to HOLD mode on ground, then arm, don't takeoff, disarm again. Then do a flight in POSCTL and trigger RTL after a while.
    Log: https://review.px4.io/plot_app?log=4c17b779-c560-43d4-9d4e-4c6a1df989b8

@Junkim3DR
Copy link

Tested on NXP FMUK66 v3:

  1. Fly a mission, then halfway during the mission, change the mission plan, upload it and fly that.
    Log: https://review.px4.io/plot_app?log=ff65c808-5c56-44c9-8b9b-188148c3008a

  2. Fly a mission, switch to HOLD, back to mission, then RTL.
    Log: https://review.px4.io/plot_app?log=21146eb9-1624-4f64-a0e8-0e38b4f16757

  3. Fly a mission, switch to POSCTL, back into mission, then RTL.
    Log: https://review.px4.io/plot_app?log=04ea854a-447e-4895-941a-610e90c15358

  4. Set vehicle to HOLD mode on ground, then arm, don't takeoff, disarm again. Then do a flight in POSCTL and trigger RTL after a while.
    Log: https://review.px4.io/plot_app?log=265b550e-e926-41ae-847b-0b0fa4d9da73

@dagar
Copy link
Member

dagar commented Nov 23, 2019

For reference here's dataman postflight perf counters after flying a mission on an fmu-v4. https://review.px4.io/plot_app?log=e64b7ac4-a54e-45d3-9a83-842c78832982

image

Which helps explain navigator total cycle time.
image

@dagar dagar merged commit cbea76f into master Nov 23, 2019
Test Flights automation moved this from Ready for testing to Done Nov 23, 2019
@dagar dagar deleted the pr-fix-triplet-reset branch November 23, 2019 15:29
@Tony3dr
Copy link

Tony3dr commented Nov 24, 2019

Tested on Pixhawk 4 V5:

Followed the instructions and all 4 flights we noticed no issues.

Fly a mission, then halfway during the mission, change the mission plan, upload it and fly that.
Log: https://review.px4.io/plot_app?log=6790330c-a8eb-4bf4-acfe-2556c50a2670&fbclid=IwAR0YsgIrOYZmihVAMUvhTLQnaPvqdJFFMgHfOXwP8zFE78kRDSeO6oi_d_E

Fly a mission, switch to HOLD, back to mission, then RTL.
Log: https://review.px4.io/plot_app?log=e4aed8de-8140-4cba-b7af-0e90cb953a21&fbclid=IwAR3fy8Zcpy9yxeo36b73aUDMpEKH9Gg0-sXpeJlG4joSjBmBwykEh3S7Klg

Fly a mission, switch to POSCTL, back into mission, then RTL.
Log: https://review.px4.io/plot_app?log=3a5dee3b-28c4-49dc-b4d7-120c36b76b01&fbclid=IwAR2I9lZS8QdBawjA9l56bjAIcZeFU1CCLewTh41UBZ3PZmVzsD5pOIUoezs

Set vehicle to HOLD mode on ground, then arm, don't takeoff, disarm again. Then do a flight in POSCTL and trigger RTL after a while.
Log: https://review.px4.io/plot_app?log=823eba28-ff7d-4e02-a8d3-6cc68f3f28ca&fbclid=IwAR2-dGXhj4tVPXvda_jH8J9MuVq1dj5URRZLswPBUB_HNipfDWGcBf5-xg0

@julianoes
Copy link
Contributor Author

@jorge789 @Junkim3DR @Tony3dr thanks a lot for the test flights!

I've looked through all the logs mainly looking for throttle spikes to 0, as well as checking the warning messages logged at the bottom in flight review.

I've found two flights with throttle spikes to:

  1. https://review.px4.io/plot_app?log=823eba28-ff7d-4e02-a8d3-6cc68f3f28ca
    Here it looks like the spike to a minimum thrust happened when the flight mode was accidentally switched to Stabilized for a quick moment. That's probably expected.
    bokeh_plot

  2. https://review.px4.io/plot_app?log=e1571b56-48d4-4601-b5be-45ca9d87499c
    Here there are two thrust spikes to 0 during loiter.
    bokeh_plot(1)
    The reason seems to be accidental ground contact detected by the land detector:
    ground_contact

Note:
Given this data I think the fix is good. One thing that we have not tested with this change is VTOL and fixedwing.

@Tony3dr
Copy link

Tony3dr commented Nov 25, 2019

@Tony3dr see test instructions above! Would be great if you could test this. And make sure to use a stock slow SD card.

@julianoes I realized I missed your message. We missed to use a stock SD card.

@julianoes
Copy link
Contributor Author

@Tony3dr see test instructions above! Would be great if you could test this. And make sure to use a stock slow SD card.

The testing is still valuable and ok. But if you could run through these 4 tests on just one vehicle (with a slow SD card) again that would be great, e.g. on the Pixracer.

@jorge789
Copy link

jorge789 commented Nov 28, 2019

Tested on Master on PixRacer V4:

Followed the instructions and all 4 flights we noticed no issues.

Fly a mission, then halfway during the mission, change the mission plan, upload it and fly that.
Log: https://review.px4.io/plot_app?log=9eeed1a7-1f10-46d0-8e55-79271db33919

Fly a mission, switch to HOLD, back to mission, then RTL.
Log: https://review.px4.io/plot_app?log=5e95df9a-a14a-44d5-b4c5-e5b8f9300d22

Fly a mission, switch to POSCTL, back into mission, then RTL.
Log: https://review.px4.io/plot_app?log=ef505093-f861-48e4-8f61-50689e6aad02

Set vehicle to HOLD mode on ground, then arm, don't take off, disarm again. Then performed a flight in POSCTL and trigger RTL after a while. Note: When I was going to switch to RTL by mistake activate kill switch luckily nothing happened, nothing to worry about.
Log: https://review.px4.io/plot_app?log=ae334621-2841-4fe2-90d5-f083afe2bee0

SD Card 4 gig/Class 4 @julianoes, the previous test performed were on a Class 10/8gig

@julianoes
Copy link
Contributor Author

@jorge789 thanks for testing this again. It looks fine for this PR.

However, in two flights there are some thrust spikes to 0 where the land_detector found ground_dedected:
https://review.px4.io/plot_app?log=ef505093-f861-48e4-8f61-50689e6aad02
https://review.px4.io/plot_app?log=9eeed1a7-1f10-46d0-8e55-79271db33919

FYI @bresch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Test Flights
  
Done
Development

Successfully merging this pull request may close these issues.

Throttle quickly goes to 0 on RTL init after idle HOLD/RTL on ground
6 participants