

Back to the diary  This manual explains how to adjust the PID controller of Gallerydrive vehicles. First a quick word about what the PID controller does: The PID controller receives data about the actual line position from the Line Detection Unit. Then, it computes a steering voltage to keep the Gallerydrive car on the track. To compute the steering voltage, the program uses three formulas. One computes the potential (P), the second computes the integral (I) and the third computes the derivate (D) between the current position and the desired position. Each result (the result of the P, I and D formula) is multiplied by a factor, which is directly proportional to the poti position of the P, I and D potis. Then, those results are added , reversed, and given out to the wheelchair's motor driver as steering voltage. This means, if all the potis are turned to GND, all the factors are zero and the car doesn't steer at all. These are the absolute basics, so far. Now, I will explain what the different formulas do in practice. The Ppart is directly related to the actual difference between current line position and desired line position (while the desired line position is always the middle of the LDRarray). The stronger the car departs from the desired position, the stronger it steers into the direction of the desired position. If the value of the Ppotentiometer is too high, the wheelchair starts to oscillate and jumps off the track. If the Pmultiplier is too low, the car doesn't steer enough in curves and it will lose the track. The Dpart computes the difference of the line position between the actual program loop and the previous program loop. The car steers against this change. The Dpart is not related to the desired position, it is only related to the change of the position compared to the last program cycle. This explains, why the Dpart itself can't steer the vehicle. With amplifying the Dpart by turning its poti in the direction of +5V, it is possible to avoid an oscillation of the car. But if the Dmultiplier is too high, the car will drive quite shaky (it oscillates in a high frequency). The steering voltages can get very high, then, because the car is always counter steering. The Ipart sums up all the differences between current and desired position. The longer the car drives besides the desired position, the more it will counter steer. Theoretically, the Ipart is the only part of the PIDcontroller, which can equalize current and desired position. In practice, a small aberration between current and desired position doesn't matter. So, this part of the formula is not as necessary in our case as the P and the Dpart are. If the Imultiplier is set too high, the wheelchair can start to oscillate as well, but in a lower frequency, as if the Ppart is multiplied too strong. In practice, I had the feeling, that the shaky behavior of the Dpart can be cleared a bit by increasing the Ivalue. But perhaps, this was just a wish and the placebo effect of playing with the Ipoti was already enough to satisfy me.
If this was still too theoretical, here is the translation of the first email, which I sent to Tilman. This contains the step by step manual in geek language: 1. Put car on line. Turn P, I, D and Speed poti to zero Volts. 2. Slowly start to increase the value of the Ppoti. The car should turn, so that the line is in the middle beyond the LDRarray. 3. Start loop:                            3.a) Drag the car strongly off the line. 3.b) Look what happens. 3.c) If the car starts to oscillate, decrease the Ppoti value a bit and end loop (go on with 4). 3.d) Increase the value of the Dpoti a little bit. 3. Return to start loop:                            4. Increase the value of the Dpoti a little bit. 5. Drag the wheelchair off the track and look if it goes back faster to the middle position, now. 6. If necessary, turn up the Dvalue a bit more. Remark: In principle, the Dpoti can be turned up to its maximum. But then you get this shaky driving behavior, because it always counter steers extremely. Here, you will have to find a compromise between a good driving feeling and safety, concerning the car staying on the line. With a high Dvalue, the car loses the track less easy. But of course, this is neither good for the gears, nor for the motor driver. Remark2: The Ivalue is more important during straight tracks. It reacts very slow und doesn't have much effect on tracks with a lot of curves. Just turn it up a little bit, otherwise the wheelchair can go off the track quite strongly. Remark3: In the source code, there are multipliers for the P, I and D value as well. (Those should be numbers, which multiply Kp, Ki and Kd). I got those values by experiments and they are related to my wheelchair and to the frequency of my crystal (but the crystal frequency only affects the D and the I value). If the range of your potis is wrong, you can play with those multipliers.


Please note, that the content on this webpage is licensed under a Creative Commons Attribution 2.0 License. Please respect the copyright of other webpages' content, which are linked from this webpage. 