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

Fix Smooth Takeoff #12001

Closed
wants to merge 6 commits into from
Closed

Fix Smooth Takeoff #12001

wants to merge 6 commits into from

Conversation

MaEtUgR
Copy link
Member

@MaEtUgR MaEtUgR commented May 11, 2019

Describe problem solved by the proposed pull request
No takeoff in no flight task is smooth anymore.
fixes #12000 when it's finished

Describe your preferred solution
All tasks need to be able to take off with the smooth takeoff ramp.
The important changes besides some refactoring are:

  • Start from a velocity setpoint pushing into the ground to ramp from idle thrust up.
  • Trigger takeoff with a bit higher velocity setpoint threshold to make sure the vehicle has a chance to really get off the ground during the ramp.
  • Calculate ramp slope from initialization setpoint to the desired one instead from zero to the desired. This ramps up correctly/quicker when you demand a very small upwards velocity like the AutoLineSmoothVel and ManualPositionSmoothVel tasks do at the beginning.
  • Don't stay in the takeoff ramp depending on the land detector, this is unnecessary and can result in problems.

Additional context
#11399

There were two rather confusing function calls one to check
if smooth takeoff needs to be ran and one that updates it.
I combined them and documented the interface correctly
making the parameters non-reference const floats.
@MaEtUgR MaEtUgR added the bug label May 11, 2019
@MaEtUgR MaEtUgR self-assigned this May 11, 2019
@MaEtUgR MaEtUgR changed the title mc_pos_control: refactor smooth takeoff call [WIP] Fix Smooth Takeoff May 11, 2019
@MaEtUgR MaEtUgR mentioned this pull request May 11, 2019
@RomanBapst
Copy link
Contributor

@MaEtUgR Cool, thanks for looking into this. Let me know when you want a review.

The comments and variable names were partly misleading.
I grouped all members, hopefully gave them more
understandable names and adjusted the comments.
@MaEtUgR MaEtUgR force-pushed the fix-smooth-takeoff branch from 17f0e70 to 824d07a Compare May 11, 2019 11:59
- start from a velocity setpoint pushing into the ground
to ramp from idle thrust up.
- start with a bit higher velocity setpoint threshold to make
sure the vehicle has a chance to really get off the ground.
- calculate ramp slope from initialization setpoint to the desired one
instead from zero to the desired. this ramps up quicker when you demand
a very small upwards velocity like the AutoLineSmoothVel and
ManualPositionSmoothVel tasks do at the beginning.
- don't stay in the takeoff ramp depending on the land detector, this
is unnecessary.
@MaEtUgR MaEtUgR force-pushed the fix-smooth-takeoff branch from 2533e97 to 7f2da66 Compare May 11, 2019 18:34
@MaEtUgR MaEtUgR force-pushed the fix-smooth-takeoff branch from d231926 to 866f2be Compare May 11, 2019 18:46
@MaEtUgR MaEtUgR requested a review from RomanBapst May 11, 2019 18:56
@MaEtUgR
Copy link
Member Author

MaEtUgR commented May 11, 2019

@RomanBapst Thanks for the offer. I brought the basic functionality back and corrected some details such that it also works with the ...SmoothVel tasks. The important changes are in the third commit and the explanation in the commit message. Feel free to ask back.

I tested in SITL which shows me that it does what it should but not how the real world takeoff user experience is:
https://logs.px4.io/plot_app?log=7bef31f8-0d8e-433e-93d4-134355e5d1a8
https://logs.px4.io/plot_app?log=af0a7e32-ee41-4623-bf70-8345cdecc833

@MaEtUgR
Copy link
Member Author

MaEtUgR commented May 11, 2019

Only mildly related: What I actually spent most time debugging is a probably in reality very rare corner case where smooth takeoff is skipped:

  • you are in manual mode (e.g. after boot)
  • you have RC but no mode switch configured
  • you have your throttle stick high
  • you trigger an auto takeoff from QGC

In this case the smooth takeoff is completely skipped because:

  • the attitude controller publishes a high thrust from your stick even while disarmed
  • the position controller does not publish any thrust setpoint because no task is running while in manual (because it doesn't want to interfere attitude setpoints) and while disarmed (such that the task gets initialized in the right moment)
  • the land detector sees high thrust shortly after arming
  • when the task starts running after arming the position controller never saw landed so it skips the smooth takeoff

Possible not so nice hotfix for this here: https://github.com/PX4/Firmware/compare/hotfix-manual-high-thrust-on-takeoff (EDIT: now contained in this pr)

@MaEtUgR MaEtUgR marked this pull request as ready for review May 12, 2019 07:13
@MaEtUgR
Copy link
Member Author

MaEtUgR commented May 12, 2019

@PX4/testflights The goal of this PR is to have a good user experience when taking off from the ground in all possible position and altitude controlled modes.

  • Position/Altitude: Having the throttle stick in the middle or below it should stay on the ground in idle. When raising the throttle above half it should not instantly jump but ramp up at the beginning. In position mode it should work with all possible MPC_POS_MODE options (especially "smooth" and "smooth velocity").
  • Auto takeoff from tablet: should not jump up at the beginning with MPC_AUTO_MODE on "default line tracking" or "jerk-limited trajectory"

@LorenzMeier LorenzMeier requested a review from a team May 12, 2019 09:00
@LorenzMeier LorenzMeier changed the title [WIP] Fix Smooth Takeoff Fix Smooth Takeoff May 12, 2019
@dagar dagar added this to the Release v1.9.0 milestone May 12, 2019
@MaEtUgR MaEtUgR requested a review from bresch May 13, 2019 06:11
bresch
bresch previously approved these changes May 13, 2019
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.

Thanks a lot for that, the fixes make sense to me. I tested it in SITL with the SmoothVel manual position controlled mode and it looks fine.

Normal takeoff:
2019-05-13_10-35-30_01_plot

Takeoff and abort:
2019-05-13_10-37-56_01_plot

Let's do some real flights and we can merge that.

@MaEtUgR MaEtUgR mentioned this pull request May 13, 2019
@MaEtUgR
Copy link
Member Author

MaEtUgR commented May 13, 2019

@bresch Thanks for your analysis!
As a side note: There are always two sample points very close together in your log plot, same was true during my log analysis on the weekend and I realized today that when I printf the takeoff ramp there are always two values very close to each other and if something triggers it's always an even number of loop cycles later. Is that a scheduling problem? FYI @julianoes

@jorge789
Copy link

jorge789 commented May 13, 2019

Tested on PixRacer V4:

Modes Tested:
Position Mode: Good.
Altitude Mode: Good.
Stabilized Mode: Good.

Procedure:
Arm in position mode, check take-off behavior (Vehicle should stay on the ground as long as the throttle stick is at the middle or below, and start to ascend smoothly as long as throttle stick as above the middle.), the land and disarm.
The same procedure was repeated with Altitude and Stabilized mode.

Notes:
No issues were noted on position and altitude, but while testing stabilized mode, the vehicle started to ascend slowly before reaching middle position, good flight in general.

Flight log on Position:
https://review.px4.io/plot_app?log=de7cbb9d-03e6-4294-8f63-d6395f0551a3

Flight log Altitude:
https://review.px4.io/plot_app?log=834e6b0c-eb12-4dba-9f3a-715bc1d05c9b

Flight log Stabilized:
https://review.px4.io/plot_app?log=47a7b939-f9e5-4622-af18-3e90700fe7d6

Tested on PixRacer V4

Modes Tested

Takeoff: Good
Position Mode: Good.
Altitude Mode: Good.
Stabilized Mode: Good.
Mission Plan Mode (Automated): Good.
RTL (Return To Land): Good.

Pre-flight Procedure:

Flash firmware through QGC.OK
Arm vehicle. OK
Calibrations. OK
Parameter check. OK

Flight Test:
Arm and Take off in position mode. OK
Throttle Test. OK
Pitch, Roll, Yaw. OK
Mode Switch. OK
RTL. OK

Notes:

Took off in Position mode, after flying for approximately one minute, switched to Altitude Mode, then stabilized mode proceeds to switch to mission plan mode then make sure that vehicle follows all waypoints as shown in QGC, once completed all waypoints activate RTL and see landing behavior.No issues noted good flight in general. The vehicle behaved as expected.

Flight log FULL Flight test:
https://review.px4.io/plot_app?log=7adce484-e6ce-4537-804f-0b386092032b

@Junkim3DR
Copy link

Tested on Pixhawk Pro v4Pro

Modes Tested:

  • Position Mode: Good.
  • Altitude Mode: Good.
  • Stabilized Mode: Good.

Procedure:
Arm in position mode, check take off behavior (Vehicle should stay on the ground as long as the throttle stick is at the middle or below, and start to ascend smoothly as long as throttle stick as above the middle.), the land and disarm.
Same procedure was repeated with Altitude and Stabilized mode.

Notes:
No issues were noted on position and altitude, but while testing stabilized mode, vehicle started to ascend slowly before reaching middle position, good flight in general.

Logs:

Tested on Pixhawk 4Mini v5

Modes Tested:

  • Position Mode: Good.
  • Altitude Mode: Good.
  • Stabilized Mode: Good.

Procedure:
Arm in position mode, check take off behavior (Vehicle should stay on the ground as long as the throttle stick is at the middle or below, and start to ascend smoothly as long as throttle stick as above the middle.), the land and disarm.
Same procedure was repeated with Altitude and Stabilized mode.

Notes:
No issues were noted on position and altitude, but while testing stabilized mode, vehicle started to ascend slowly before reaching middle position, good flight in general.

Logs:

@dannyfpv
Copy link

dannyfpv commented May 13, 2019

Tested on Pixhawk 4 v5
Modes Tested:

Position Mode: no issue
Altitude Mode: no issue
Stabilized Mode: no issue

Procedure:
Arm in position mode, check take off behavior (Vehicle should stay on the ground as long as the throttle stick is at the middle or below, and start to ascend smoothly as long as throttle stick as above the middle.), the land and disarm.
Same procedure was repeated with Altitude and Stabilized mode.

Notes:
No issues were noted on position and altitude, but while testing stabilized mode, vehicle started to ascend slowly before reaching middle position, good flight in general.

Logs:

Stabilized: https://review.px4.io/plot_app?log=c624835e-4141-4564-a706-72b75749af5c

Altitude: https://review.px4.io/plot_app?log=18b11371-0ef8-4f68-bd23-e44a9caf7f4c

Position: https://review.px4.io/plot_app?log=01c85f31-82a4-4e88-a710-e4d399b6ea0f

Full flight test: https://review.px4.io/plot_app?log=7386dd11-f307-4ad2-b614-93e477695c91

Copy link

@Tony3dr Tony3dr left a comment

Choose a reason for hiding this comment

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

Tested on PixRacer V4, Pixhawk Pro v4Pro, Pixhawk 4 Mini v5, Pixhawk 4 v5. No noticeable issues during takeoff. On all the platforms the vehicle behaved as expected.

// smooth takeoff vertical velocity ramp state
bool _in_takeoff_ramp = false; /**< true while takeoff ramp is applied */
bool _position_triggered_takeoff = false; /**< true if takeoff was triggered by a position setpoint */
float _takeoff_ramp_velocity = -1.f; /**< current value of the smooth takeoff ramp */
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a note and not more: to me velocity agrees with the coordinate convention (vs speed, which is always positive). Hence, with that convention in mind, _takeoff_ramp_velocity of -1 means that it would start with 1m/s upward.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, I should have switched to the proper coordinate convention. Noted to do in the next iteration since this is a release blocker. 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

When #12014 is finished the coordinate frame will be correct.

@mhkabir
Copy link
Member

mhkabir commented May 14, 2019

Can someone test takeoffs in Offboard before this is merged?

@dagar
Copy link
Member

dagar commented May 14, 2019

Can someone test takeoffs in Offboard before this is merged?

@okalachev is that something you could test quickly?

bool _in_takeoff_ramp = false; /**< true while takeoff ramp is applied */
bool _position_triggered_takeoff = false; /**< true if takeoff was triggered by a position setpoint */
float _takeoff_ramp_velocity = -1.f; /**< current value of the smooth takeoff ramp */
float _takeoff_reference_z; /**< z-position when takeoff ramp was initiated */
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
float _takeoff_reference_z; /**< z-position when takeoff ramp was initiated */
float _takeoff_reference_z{0.0f}; /**< z-position when takeoff ramp was initiated */

@MaEtUgR
Copy link
Member Author

MaEtUgR commented May 14, 2019

@PX4/testflights Thanks a lot for the extended test coverage and feedback.

but while testing stabilized mode, vehicle started to ascend slowly before reaching middle position

That's ok stabilized has no takeoff logic and stays raw manual input as it was.

According to my tests this solution is acceptable, the smooth takeoff works again but it's not perfect. The remaining issues for the ramp itself (which also existed before!) are:

  • Depending on the vehicle tuning the ramp could start a bit above zero thrust.
  • If the task that takes off sets a position and a velocity at the same time (Trajectory mission does that) it can happen that the position setpoint results in an adjustment added to the feed forward velocity and there's a small twitch when the takeoff ends.

I would say the minimum viable takeoff is there and I'll work on fixing the remaining issues on #12014

Can someone test takeoffs in Offboard before this is merged?

I don't know how to test that. I just know that if the vehicle doesn't get off the ground in offboard CI fails (saved me in #12014 already) and since the conditions to takeoff are very similar to what they were for a long time I expect it to work exactly like the auto takeoff.

MaEtUgR added 2 commits May 15, 2019 13:35
After boot the user is in manual mode and if he has an RC
but doesn't switch out the thrust gets set to the throttle stick
position. When he then starts a takeoff from tablet the thrust is still
high while arming and the land detector immediately sees a takeoff
skiping smooth takeoff from the position controller.
@MaEtUgR
Copy link
Member Author

MaEtUgR commented May 15, 2019

@dagar I fixed the zero initialization of your review comment.

I also added the hotfix for the problem I described in the comment above: #12001 (comment) because I realized it's not a rare corner case but also happened to me in the real world testing.

  • Springloaded throttle
  • RC already connected on boot
  • Vehicle boots in manual
  • Switches to position according to my mode switch position
  • When I arm it jumps up without takeoff

I had the fix on my testing branch from that moment on and that showed me it's necessary for the release. I discussed with @bkueng, @RomanBapst (who found this exact problem before) and @bresch how to solve the issue and that the hotfix is viable because a proper solution requires more involved position controller changes.

@MaEtUgR
Copy link
Member Author

MaEtUgR commented May 15, 2019

@LorenzMeier
Copy link
Member

@MaEtUgR What is the next action item here? @bresch @RomanBapst Any ideas you want to contribute?

@MaEtUgR
Copy link
Member Author

MaEtUgR commented May 18, 2019

Should have updated: #12014 is the follow up, it contains these changes + all the additional fixes. It's a different pr because initially I thought this minimal pr is enough to just fix what we had before but that turned out to be not the case.

With only this PR

  • the ramp doesn't start at the correct value depending on vertical velocity control tuning
  • the ramp doesn't stop at the correct value when providing velocity and position setpoints during takeoff (which smooth mission does)
  • the takeoff can be triggered accidentally when the state fluctuates during idling

I addressed all of these in #12014 let me also update the description there.

@MaEtUgR MaEtUgR closed this May 18, 2019
@julianoes julianoes deleted the fix-smooth-takeoff branch May 20, 2019 05:53
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.

Smooth takeoff broken