ArduCopter Automatic PID Tuning - BRAVE TESTERS ONLY

DISCLAIMER: This could be dangerous and might crash your copter.

OK! I made some new changes to the autotuning algorithm and I have tested it again in the simulator. I think this is ready for some real world testing from some VERY BRAVE users, or some simulation testing. Unfortunately I do not own a quad and my octo is out of commission until Tuesday, or I would be testing this right now outside.

 

 

 

First, here is what is new:

1. The amount of change applied to the P gain scales down with each iteration. This allows for quicker acquisition and better resolution of your Pretty Good Gain

2. If the tuning logic moved the P gain in the wrong direction it will revert to the best P gain that had been found and use that as the new launching point which should save some iterations

How to use it:

1. Replace the files in your ArduCopter 2.2b2 code base with the files that I have included in the .zip.

2. Upload the code to your board and test in the simulator so that you can get a feel for how it works (follow the same steps below for setup starting at step 5)

3. Update the config file to disable the HIL setting or change your frame type, etc...

4. Re-upload the code for live flight IF YOU DARE

5. Connect the APM to the Mission Planner.

6. Go to the configuration tab and manually set the CH7_OPTION to 8 as seen below and click "Write Params"

7. Set your Integral (I) gains for pitch and roll to zero and click "Write Params"

8. Bring the copter to a hover and flip CH7 to the high position to activate the auto tuning mode

9. Roll to the right or left and quickly return the stick to the center position. (Repeat this step at least 5 times)

10. Deactivate auto tuning mode by flipping CH7 to the low position

11. Reactivate auto tuning mode by flipping CH7 to the high position

12. Pitch the copter forward or back and quickly return the stick to the center position. (Repeat this step at least 5 times)

13. Deactivate auto tuning mode by flipping CH7 to the low position

14. Go to the configuration tab of the Mission planner and click "Refresh Params" to see your new tuned P gains

15. Write those values down.

The idea of steps 9 and 12 is to introduce a wobble and let the copter try to even itself out. Don't go too aggressive with your pitch or roll... again its just to introduce a disturbance.

 

My videos are in 1080p so that you will be able to read whats on the screen.

 

Questions, comments, discussion is welcome and encouraged!

Autotuning_AdamRivera_01202012.zip

Views: 2613

Tags: arducopter, automatic tuning, pid


Developer
Comment by Jean-Louis Naudin on January 20, 2012 at 11:58pm

Good work Adam, I really appreciate that you have done. I am also using Machine Learning process to improve the flights enveloppe of some UAVs...

Regards, Jean-Louis


Developer
Comment by Michael Oborne on January 21, 2012 at 12:27am

Adam, can you test with the latest trunk code? i made a mod to the code to fix the dapenning factor. Attitude hil was feeding in the attitude and rates into the dcm library, but no the imu library. and the dampening is based off that.


Developer
Comment by R_Lefebvre on January 21, 2012 at 6:38am

This is EPIC.  This is going to help SO MANY people!  Are you going to be able to apply this to Alt_Hold and Loiter?  That's what would help me the most.  

Now, at the end of the video, you said that if you keep doing it, it will lower it from 1.4.  Maybe a silly question, but you're sure that it won't just keep lowering it every time you run the test?  It does sometimes recognize when P is too low, right?

And do you know how well it will work in the real world with a noisy system?  ie: If you jerk the stick to initiate the tuning response, when it is trying to settle the quad, there will be all kinds of external interactions which will make the system response noisy.


Developer
Comment by Adam Rivera on January 21, 2012 at 8:03am

Jean-Louis: Thanks for your kind words. As you probably know, stuff like this gets continuously improved as ideas dawn on you... I am working on some improvements to this already and integrating the integral gain logic.

Michael: I will pull it down and test a bit later today. Thanks for letting me know.

Robert: This could definitely be applied to alt_hold, but I'm not as familiar with the loiter routines. I could definitely take a look though. At the end of the video I was really making a guess that the P value would continue to lower because of the P value that I had arrived at for the roll. It should not continue to lower the P value indefinitely. My strategy for preventing that is counting how many iterations at 50hz it took to go from the peak to the valley in the oscillation. That gets factored into the distance between the peak and valley like this.

(peak - valley) + iterations

We are looking for a low number, so as the distance between the peak and valley gets smaller that sum gets lower, BUT as a side effect it takes longer to get from that peak to that valley. So as you can see by adding in the number of iterations I can tell if the P value has made the copter too sluggish. You bring up an interesting point though because some people may prefer more stability or more response... I am considering adding that as some sort of configurable constant for the user.... perhaps a slider bar in the Mission Planner (Stable------------------------------------Responsive).

Real world with noise.... that is a whole new beast. If a wind gust comes at an inopportune time the results will definitely be skewed at this point. See my next comment for more on that.


Developer
Comment by Adam Rivera on January 21, 2012 at 8:06am

TODO:

1. The weighted performance value needs to be proportional to the users input disturbance amplitude. The problem here is that if your disturbances aren't relatively consistent in amplitude, the results will not be as accurate.

2. Determine how to ignore noise that will inevitably exist in real world applications, unless you are fortunate enough to fly on a day with no wind.

3. Make the tuning result semi-configurable (more stable vs more responsive)

I'm sure I will think of more enhancements. Stay tuned and thanks for reading!


Developer
Comment by R_Lefebvre on January 21, 2012 at 8:16am

I would think the algorithms you are creating will be applicable to Alt-Hold and Loiter.  So if you're up to it, give it a shot.  This is fantastic.  Tuning PID loops is a black art, and I think some people will really benefit from this.


Developer
Comment by Adam Rivera on January 21, 2012 at 8:18am

I will definitely attempt it. The way it is written it should be very easy to implement in other routines, its more that I hope it works in those other places... we shall see!


Developer
Comment by Jean-Louis Naudin on January 21, 2012 at 11:11am

Good luck Adam in your soon tests flights... I cross my fingers for you and I am waiting impatiently your results...

 

Comment by Jeb Bailey on January 21, 2012 at 1:01pm

What're the chances that this will work with the ArduPlane code?  Or can it be made to?  I'd love to test this out on a fixed wing platform.


Developer
Comment by Adam Rivera on January 21, 2012 at 1:32pm

It should really work with any airframe. I am close to finishing some new changes including the Integral gain so you might want to wait on that. Istronglyrecommend trying it in the simulator first though. I haven't flow this for real yet, and I have no simulator time with fixed wing aircraft.

Comment

You need to be a member of DIY Drones to add comments!

Join DIY Drones

Social Networking

Contests

Season Two of the Trust Time Trial (T3) Contest has now begun. The fourth round is an accuracy round for multicopters, which requires contestants to fly a cube. The deadline is April 14th.

A list of all T3 contests is here

Groups

Advertisement

© 2013   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service