Position Control PID Tuning Advice

Hi all,

I was wondering if anyone has any advice for tuning the position control PIDs?

My current setup is as follows:

  • 1.6.0 (40aa7857) with LPE
  • OptiTrack for pose estimation
  • LPE_FUSION = 12

Log of recent flight: http://review.px4.io/plot_app?log=95288759-e565-429b-a4e9-0685c5df7932

Currently, position control is working, but it tends to drift when holding position and overshoot xy control commands. I am hoping to reduce drift in position hold and increase how precisely the quad can be controlled.

I have found the px4 PID tuning guide here: https://docs.px4.io/en/advanced_config/pid_tuning_guide_multicopter.html, but it doesn’t mention tuning position control.

I have also found the parameter list here: https://docs.px4.io/en/advanced_config/parameter_reference.html. I think I should be adjusting the MPC_Z/XY_P and the MPC_Z/XY_VEL_P/I/D parameters, is this correct?

If anyone has any tips or advice on tuning position control, it would be greatly appreciated.

Please let me know if I have forgotten anything / need to give additional information.

Hi, I am going through a similar situation.
Currently , I am looking to try system identification method, which is a package in px4tools.
Please look into px4tools , logsysid.py. There is a sample code that if provided with csv file of your logs, might give you the PID gains for the attitude and attitude rate control.
I have heard that it is the attitude loops which matter the most. Update me as well, if you stumble upon some solution. Also, there is a flightplot method. Something similar to QGC also have some tuning facility.


Maybe this can help you

Hi @Darkus3 have you used flightplot for PID tuning?

Thanks guys. I will try these out today and let you know how it goes.

@abdullahmohiuddin we tried logsysid.py today, but had problems with the DataFrame missing a ground truth attribute similar to: Px4tools and data for local_position_groundtruth, have you had any luck with this?

I also found this: https://github.com/dronecrew/ulog_tools which I think might do the same thing?. We didn’t manage to get it working because we couldn’t get the logger to log fast enough (needs to be > 200 Hz) maybe our SD card is too slow?

We ended up doing some manual tuning of the attitude gains which seems to have improved position control.

Hello @Sam.S / @abdullahmohiuddin,

I was wondering if you ever found a good solution for optimising position control parameters?

Would be great to know if you found either of the suggested methods (flightplot or pyulog in px4tools) in the thread worked for you in the end? Or if any other methods worked well. I’ve tried tuning each axis independently and results are OK but I feel there is room for improvement.

I’ve also been looking for a logfile of a well tuned position control setup to give me an idea of what is possible - if you happened to have a link to such a thing - that would be much appreciated.

Hi @jannsta1,

We spent some time trying the suggested tools but didn’t have much luck so we ended up tuning it manually. Our best position hold performance is around ± 5cm. I can upload a logfile when I am next in the lab if you like?

Hi @Sam.S

Yeah that log would be interesting to see. I haven’t quantified yet but +/-5cm sounds like it could be better than I get at the moment.

I’m keen to try the systems identification approach but stuck with the same problem that you reported of not being able to log the messages at a high enough rate. Even if I only log the 2 required messages and use the recommended SD card it only logs at 145hz. Going to try a newer/ more official version of hardware to see if that makes a difference. Also plan to check if I can get a higher rate on the simulator in the next few days.

I have a similar Problem but not related to PosCTL precision but when the Vehicle is moving and then braking to hold position I have a very strong Oscillation when it changes from Movement to Hold Controller (or whatever this is called). So when I move the Stick to the center rapidly, the Aircraft will decelerate and just before comming to a stop will move back to neutral position just to bank again an come to a full stop. This looks very awkward. Here a Plot of the maneuver, any hints on how to tune this?

Notice the Swing-back around 2:26.3 this does only happen in PosCTL, so I assume Attitude PIDs should be more or less ok. This is a new behavior I got after swapping ESC (the new ones do have active braking, and are more aggressive).

I couldn’t find a position hold log, but here is one with the same setup flying a square trajectory in offboard mode: https://logs.px4.io/plot_app?log=eacc0fe0-cfc1-41a5-a85c-a165d80922c7

Thanks @Sam.S, useful to see. FYI, I eventually got the ulog_tools to generate some results but performance seems to be worse than the default values (for flamewheel 450). Some particularly interesting suggestions were generated for the yaw channel (12.5 for MC_YAWRATE_I!), but going to try and understand the package parameters better in case I’m supposed to select these rather than just using the defaults.

@Andreas_Hoffmann. Sorry not able to offer any advice, if you still have a problem with this you might be better to open a new discussion. Since this happened when you got new ESCs perhaps its a matter of calibrating them? (there is a tool for this in QGroundControl).

@jannsta1 thanks for you reply. I’m in Contact with PX4 Devs and I’ll go for another Try with deactivated Damped Light Function of the BLHeli ESC. It may be that the greatly improved ESC responsiveness needs some special tuning. So we try with conventional Settings.