## Saturday, 14 June 2014

### PID Control

posted 24 Nov 2011 05:36 by David Taylor   [ updated 24 Nov 2011 05:43 ]

 After reading through some more research trying to understand the reason TriRot was not just perfectly stable when it lifted off for its first flight, I came across that old jewel that I last looked at when I was studying engineering, The PID controller, where the acronym stands for Proportional, Integral, Differential controller. What I had originally was a 1:1 control system. If the IMU said I was tilting 5 degrees, I would correct exactly the same in the other direction. Looking back now, this does not account for the inertia of the system and any overshoot would be dealt with very slowly resulting in an unstable system (as evidenced by that last video ;-). Proportional ControlThis simply means that if the error is X you respond with X*Y where Y is the relative proportion you want to respond with. I.E., if Y = 1.5 and the error is 2 you will at that stage respond with 3. The idea being that you slightly exaggerate your response to get a quick correction. Y is referred to as the Gain Factor or Kp for Proportional Gain. Integral ControlHere we look at the time the error has been around. So you take the amplitude of the error and you multiply it with the time it’s been around. You also add a gain value to this for good measure (Ki). Effectively, you are working out the Area a graph is occupying. The graph here would be the output from the IMU. The best way to work out the area a graph occupies is to use integration. Differential ControlThis looks at the rate of change, or effectively the slope of the graph. This term also has a Gain factor, but in this case actually limiting the output, since your gain is generally in the 0.002 range. Take a look at the following articles which helped me make sense of it all: http://en.wikipedia.org/wiki/PID_controller http://en.wikipedia.org/wiki/Integral http://en.wikipedia.org/wiki/Differentiation_(mathematics) I don’t think I need to do full integration nor am I able to do full differentiation since I don’t know the function of the graph that will be generated by the random movements. So For integration I simply multiply the current amplitude with the timespan since the last loop and then sum that with previous calculations. For the differentiation, I again take the difference in amplitude (or y) and divide it by the difference in time (or again the timespan since the last loop). I’ve only just uploaded this to TriRot last night, spun up the motors (trying not to wake the kids) and moved it around a bit in my hand, but it seems allot more aggressive. I do still have to do the PID Tuning, which I’m expecting to be the hard part. Here is a Graph of a previous Pitch Test I took from TriRot. Effectively it’s just an output from the IMU in the Pitch axis, to which I have applied the PID algorithms in Excel. This is what convinced me that this might just work. In this test: Kp = 1.1, Ki = 0.25, and Kd = 0.01