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

PID autotuner for velocity loop #12479

Closed
wants to merge 7 commits into from
Closed

PID autotuner for velocity loop #12479

wants to merge 7 commits into from

Conversation

bresch
Copy link
Member

@bresch bresch commented Jul 15, 2019

Describe problem solved by the proposed pull request
I've never seen anyone tuning the velocity loop. The main reason is that it's really hard to visualize the velocity tracking while flying and it usually "looks okay". After inspecting many log files, I realized that many velocity loops are poorly tuned.

A common practice of the users to "fix" the poorly tuned velocity loops is to modify the parameters of the setpoints such that the handling qualities requirements are fulfilled in most situations (e.g.:a fast-moving setpoint reduces the reaction delay of a poorly tuned loop). The drawback of this approach is that the response does not follow properly the setpoint and that limited dynamics of the setpoint won't be properly applied by the drone (the drone can exceed acceleration and jerk limits in some conditions).

The idea here is to provide a tool to the user to automatically adjust the PID gains of the velocity controller to easily achieve proper tracking.
The method is an improved version of the classical forced oscillation method that automates the tuning of the ultimate gain without introducing too many harmonics (a drawback of the relay-feedback experiment). Once the ultimate gain is found, the ultimate period is measured and the gains are computed using the well known Ziegler-Nichols rules (https://blog.opticontrols.com/archives/131)

Algorithm block diagram:
autotuning(1)

Additional features:

  • A weak P controller is used to prevent the drone drifting too much during the autotuning sequence
  • Moving the RC sticks during autotuning immediately switches back to manual position control mode
  • The amplitude of the oscillation is bounded

Usage:

  • During a calm day, takeoff and hover at around 15m is position mode
  • Set MPC_XY_ATUNE to 1 and wait until the tuning finishes
  • Adjust the P, I and D gains if needed

You can move the RC sticks at any time to abort the autotuning. To restart autotuning, set the parameter back to 1.

SITL tests:
Left: with parameters after the autotuning
Right: with default parameters
2019-06-06_10-22-52_01_plot

TODO

  • Trigger via MAVLink command
  • Safety against bad parameters (to discuss: should QGC set the parameters? should it be a way to revert back to the previous set of gains?)

@hamishwillee
Copy link
Contributor

Great description. This could go straight into a blog or release note when the feature delivers.

@bresch bresch force-pushed the dev-autotune-velocity branch from 5e3caf3 to 832fb04 Compare July 30, 2019 09:43
@bresch
Copy link
Member Author

bresch commented Jul 30, 2019

@PX4/testflights Can you test that PR during a calm (almost no wind) day please?

  • With a multicopter, takeoff and hover at around 15m is position mode
  • Set MPC_XY_ATUNE to 1 and wait until the tuning finishes (the tuning is done when the drone stops oscillating and that this parameter is reset to 0). This should not take more than 30 seconds.

NOTE the drone will oscillate, this is normal but it should be a controlled oscillation, if this is too extreme, and the drone becomes unstable, simply move the sticks to abort the procedure. You can also switch to stabilized and it will stop.

Also do not forget to save the previous MPC_XY_VEL_[PID] gains as they will be overwritten.

@dannyfpv
Copy link

dannyfpv commented Jul 30, 2019

@bresch we are testing this pr and no changes on MPC_XY_VEL_[PID]

tested on pixhawk 4 v5 f-450
3.0 m/s wind

pr log= https://review.px4.io/plot_app?log=534ce58c-5022-4e41-bba0-b874591cd7a0

@jorge789
Copy link

Tested on PixRacer V4:

Process:
arm and take off in position the vehicle was positioned at 15 meters high. Change parameter MPC_XY_ATUNE from 0 to 1 the vehicle oscillated 5 seconds and stabilized. After moving the lever and parameter MPC_XY_ATUNE returned from 1 to 0 and landed.

Log:
https://review.px4.io/plot_app?log=cbe5b8ee-2672-496b-8408-c73ed859f440

Tested on Pixhawk 2 Cube V3:

Process:
arm and take off in position the vehicle was positioned at 15 meters high. Change parameter MPC_XY_ATUNE from 0 to 1 the vehicle oscillated 5 seconds and stabilized. After moving the lever and parameter MPC_XY_ATUNE returned from 1 to 0 and landed.

Log:
https://review.px4.io/plot_app?log=537bbf81-91ed-40a6-aa9f-7997018a8ff4

Tested on CUAV+ V5:

Process:
arm and take off in position the vehicle was positioned at 15 meters high. Change parameter MPC_XY_ATUNE from 0 to 1 the vehicle oscillated 5 seconds and stabilized. After moving the lever and parameter MPC_XY_ATUNE returned from 1 to 0 and landed.

Log:
https://review.px4.io/plot_app?log=9ba73064-ce74-462e-8d03-3ff912474698

@bresch
Copy link
Member Author

bresch commented Aug 6, 2019

Unfortunately that didn't work as expected. The learning rate is apparently too fast--the critical gain has been underestimated. I have to find a more appropriate learning rate.

@stale
Copy link

stale bot commented Nov 10, 2019

This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.

@stale stale bot added the stale label Nov 10, 2019
@bresch
Copy link
Member Author

bresch commented Nov 11, 2019

No, this isn't dead, I'm going to work on it at some point

@stale stale bot removed the stale label Nov 11, 2019
@mzahana
Copy link
Contributor

mzahana commented Nov 27, 2019

Great initiative @bresch . I also think the tuning of the outer PID loops such as the transnational states vx/vy/vz/x/y/z are dependent on how well tuned the lower level PID loops (rotational states roll_rate/roll ... etc). So I was wondering if this should be done first? I am personally working on an LQR-based + Genetic Algorithm method for tuning the attitude PID loops using ulog files. Will release once I get a usable version.

@stale
Copy link

stale bot commented Feb 27, 2020

This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.

@stale stale bot added the stale label Feb 27, 2020
@bresch bresch removed the stale label Feb 27, 2020
@bresch
Copy link
Member Author

bresch commented Feb 27, 2020

I'll continue to work on that after #14212 gets merged.

@stale
Copy link

stale bot commented May 30, 2020

This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.

@stale stale bot added the stale label May 30, 2020
@bresch
Copy link
Member Author

bresch commented May 31, 2020

I'll rebase and continue it now that we have the interface for acceleration input in place!

@stale stale bot removed the stale label May 31, 2020
@stale stale bot added the stale label Aug 29, 2020
@bresch bresch removed the stale label Aug 31, 2020
@PX4 PX4 deleted a comment from stale bot Oct 16, 2020
@LorenzMeier
Copy link
Member

Closing as stale, leaving the branch.

@dagar dagar deleted the dev-autotune-velocity branch October 9, 2022 19:07
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.

6 participants