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!
Comments
Anish: Thanks! I didn't really have plans for creating an online demo of this. Maybe after I have this solid I can start thinking of that. You could always get your hands on the free simulator called flightgear. That is the one I use.
@adam this is cool, now we have expert system to help, tune PID. Any thoughts of one online on diydrones, so folks could login online and try :)
Jeb, there is an other issue with ArduPlane, the control force changes depending on the flight conditions. if you fly fast a rudder will exsert a very high force on the plane; i think we should change the comand output 5 Newtons, not 12deg of rudder deflection. maybe this is relevant to copters too
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.
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.
Good luck Adam in your soon tests flights... I cross my fingers for you and I am waiting impatiently your results...
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!
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.
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!
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.