I did some research and implemented a self learning PID algorithm. It is located in my cloned repo http://code.google.com/r/litho23-ardupilot/. I really like how it turned out. I hope you all are able to use it with success i'm lacking hardware right now to do further testing.
For those looking at the repo it is in the libraries/PID/ location.
I couldn't figure out how to add a parameter to the EEPROM memory so it is 95% implemented.
Matt: Unfortunately this was not plug and play in ArduCopter. I am working on some updates that will make your lib mirror the header from AC_PID.h so I can just swap them out. I don't have much experience with ArduPlane...
Ok. Got it implemented for the RATE pid controllers. You can check out the changes I made in my WIP clone under the autotuning branch. It's too late to start HIL testing tonight, but I will upload this to my APM2 tomorrow and see how it works.
Matt, How would you expect this self learning PID algorithm to cope with nested PID control loops? I am thinking that if I used this library for the Stab PIDs and the Rate PIDs it may not work. Thoughts?
I will try with Rate gains first.
Ok... Good to know. So the final values are not written to EEPROM, but they are updated in real-time, correct? So in other words, if I refresh the params list in the MP I can see the gains change as it flies?
It gets a little gray here.... I haven't added anything to write the tuned variables to the EEPROM right now. If you wanted to know the value you would have to write some code to print to screen or something similar to EEPROM or a log file. There are two variable here one is the initial gain you defined in your APM_Config.h file. The other is a temporary variable that lives inside the SLPID object, which is the tunningIntergrator value.
If you really want to test out the SLPID you can try setting all the gains to one and view the tunningIntegrator value through some type of logging code. If you do this I suggest setting the G (gamma) value to 0.7-1 because gamma controls how fast it tunes. Too fast and it will overcompensate too slow and it won't change fast enough to make an impact.
I'm taking a different approach for now and I am just looking at the error graphs from the APM Planner and comparing them to graphs from the same mission, but with the original PID.
I'm at work right now and can't continue my testing I started it last night. I used low initial values (0.001) for the variables that are typically set to 0 and a gamma of 0.5 I didn't notice much of a change. I only did one run. I plan to increase my new initial values to 0.01 then 0.1 and see what happens.
I forgot to mention again that the the final tuning value will be the tuningIntegrator * initial_PID_value (from the APM_Config.h file)
Right... just realized that. Ok, sounds good! I will keep that in mind. I should get to HIL testing tonight.
Cool. Saw your edit. That is what I figured. One question... what is the scale_factor param on the get_pid method? I had to refactor each gain into its own get method (ie. get_i, get_p, get_d). Do you foresee that being an issue?
Ok. Just got done with some HIL testing. It didn't really seem to converge on better gains. I have the gamma set to 1.
Yeah, my SITL testing isn't showing much of a difference either. I've ran simulations in MATLAB and SIMULINK. I'll post those results so you know the theory works. I'm still testing different initial values to see if anything changes.
Did you write any code that logs the value of the tuning integrator i'd be interested to see if that value is changing like it should.
Thanks for trying it out. Did it make your copter less stable or just the same?
Ok. I just had a couple tests with a fix for the lastError. I would encourage you to pull down my clone (autotuning) branch to check out the changes I made to make it a bolt-on lib to replace AP_PID. I applied it to the rate and stab gains, but I am skeptical that it will work with both at the same time. It seems to me that each loop will be fighting the effects of the other loop. Does that sound correct?
In my HIL testing the rate gains seem quite solid, but I can't tell if that is because of the self learning. I am working on adding some logging so I can see what is happening under the covers.
Ok. I started with some more aggressive gains and it went pretty nuts on me. I don't think it is able to cope very well with gains that are far out of sync. I am going to discontinue testing for a bit here and let you play with it a bit more.