PID loops and Tuning

I have heard a lot of different versions of what a PID loop is. I am going to post my version as taught to me by my PID coach when learning to tune and autopilot on a UAV. Also i am going to throw some tuning tips in as well.P term -The P term is like a big strong man on the steering wheel. He sees he is off course and muscles the steering wheel over in the direction he thinks he should be going. Nothing really accurate about it, just proportional to the obvious error that he perceives.I term -The I term is like your average backseat driver. He looks closer at the error they are off course and is tugging at the steering wheel gently... at first... to get back on course. But the longer he sees the error the more excited he gets and the harder he tugs.D term -The d Term is a very nervous individual. He doesn't mind so much that he is in error as he minds speeding past where he wants to be and having to go back. So he is constantly looking at how fast their collective goal is approaching and is fighting both the P-strongman and the I-backseat driver to prevent them from overshooting their target.Now for a little tuning tips...Start Small -Use very small Control values. Forget about the D term for now. it will only cause you grief until you get some solid results from the P term .Set your I term low as well. Especially if you expect large errors to occur. Remember that the I term is adding up all the error and when he is in error for any length of time he will exert a very strong powerful force on whatever you are controlling. I think an error limit routine in your code with help deal with this. For instance if you are flying a UAV, and you want to change altitude. You would, of course add power. Well how fast does your overloaded uav climb? If you went from 500 to 600 feet it might take a few minutes. Meanwhile your PID loop has made 6000 readings in the last second! Now lets send the UAV to 3000 feet! See what I mean?Change one thing at a time -Don't get carried away changing ten different values in your PIDs. You will go crazy. Enough said.Set your trims -On a UAV you want to trim the aircraft to fly staight and level before you start telling the autopilot how to fly it. Remember that a PID controlled anything works on error. Environmental factors will give you enough to overcome without throwing in some error on your own.Nested PIDs -Sometimes you want to use nested PID loops. Example is my heading control routine. If i pass the PID turn values directly to my rudder I could get some really high turn rates. So I nest that PID inside my turn Rate PID. So my heading PID gives me a suggested turn rate that I check against my maximum allowed turn rate. If the PID suggests a turn rate of 15 I set it back to 7 (i like a turn rate of 7 degrees per second and that is my set Maximum) then i pass that to my Turn rate PID. My turn Rate PID checks the YAW rate gyro and then calculates how much rudder is added or reduced to satisfy the suggested turn rate from the Heading PID.Record Everything -I don't mean video Camera either. Record all of your data. In a UAV I record the ALT, desired altitude ,AirSpeed, Desired airspeed, Heading, Desired Heading, and all the servo positions.Why you may ask? Duh! For tuning!!You can easily write software or use excel to 'see' what the aircraft or whatever your controlling is doing. this makes it sooooooo much easier to tune!Now, if you are feeling froggy -Design your device with real time tuning i.e: Write it so you can chage you PIDs on the fly...literally! Flying a UAV is risky at best. If you have to launch and recover your UAV a hundred times to tune it you risk killing it a hundred times. It is best to have two people to tune a UAV. one to fly and one to upload new PID terms and then release the bird to the autopilot to see what happens. When you are satisfied (or not) give the pilot control again and make changes.Accelerometers and Kalman filters -you would be really surprised how well a UAV can fly if the aircraft is inherantly stable. you definately need to kill the noise on your gyros because these will be needed for turn rates and envioronmentally induced roll (Wind gusts and air pockets). Do you really need to know the attitude of the aircraft if the aircraft at zero with fly straight and level? Remember, if you want to use all the positional data on your aircraft then be prepared to isolate the autopilot gyros and Accelerometers from the vibration from your Fuji boxer 4 stroke engine 9 inches away!When you tune the UAV correctly the aircraft with fly without all that extreme math and do well with just you PIDs cranking away.Good luck! Try not to make new craters with your UAVs

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • Developer

    Just a little experience advice. You don't need I or D gains on almost anything for basic astable aircraft unless you are looking for rockstar performance that is imperceptable to the eye. IE P gain on roll is all that is required. I use zero derivative gains on any of my controllers and have stellar response. The few integral gains I use are on airspeed and altitude holds and that just because its easier to have the controller find the aircrafts trim point for a given airspeed then it is for me to manually tweek the pushrod in and out flight after flight until its perfect. My altitude/airspeed hold is very unconventional but works on the same classical control techniques. (energy height feedback). So in summary if you cant get basic control with simply P gains to start with you are never going to be able to tweak it out. You will only make it works. The I and D are used to increase performance but if the performance isn't first there based on the P then you will be chaseing a moving target.

    *Note attached Google earth file's altitude its on rails with no steady state error

    8NOV09.kml

  • Here is a PID simulator I through together so you can "See" the effects of the PID loop on an altitude.

    Download it Here
  • Great post!!!
  • I have a similar question to Jason.

    I am wondering when, or how, to reset my Integral term.

    Currently, I am setting a threshold to reset the integral term, i.e. when the error is suitably reduced, the I term is set to 0.
  • Developer
    I had a question regarding the I term in PID loops. If I grows over time based on accumulated errors, what mechanism causes it to get smaller? Is it overshoot that reduces it?

    For example, if I've taken a long time overcoming a force - like gravity in your example- and my I has grown to its limit, I should be able to reduce my error to 0. But once I've reached 0, isn't my I term still large? Is it D that counteracts it? Or is there another mechanism that does it? Or do I need an opposite error to reduce it until I steadily reach 0?

    Thanks, Jason
  • 3D Robotics
    Great post! Many thanks for the useful advice, which sounds spot on.
This reply was deleted.

Activity

Neville Rodrigues liked Neville Rodrigues's profile
Jun 30
Santiago Perez liked Santiago Perez's profile
Jun 21
More…