|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 P-part 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 LDR-array). 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 P-potentiometer is too high, the wheelchair starts to oscillate and jumps off the track. If the P-multiplier is too low, the car doesn't steer enough in curves and it will lose the track.
The D-part computes the difference of the line position between the actual program loop and the previous program loop. The car steers against this change. The D-part 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 D-part itself can't steer the vehicle. With amplifying the D-part by turning its poti in the direction of +5V, it is possible to avoid an oscillation of the car. But if the D-multiplier 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 I-part 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 I-part is the only part of the PID-controller, 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 D-part are. If the I-multiplier is set too high, the wheelchair can start to oscillate as well, but in a lower frequency, as if the P-part is multiplied too strong. In practice, I had the feeling, that the shaky behavior of the D-part can be cleared a bit by increasing the I-value. But perhaps, this was just a wish and the placebo effect of playing with the I-poti 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 P-poti. The car should turn, so that the line is in the middle beyond the LDR-array.
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 P-poti value a bit and end loop (go on with 4).
3.d) Increase the value of the D-poti a little bit.
3. Return to start loop: - - - - - - - - - - - - - - - - - - - - - - - - - - -
4. Increase the value of the D-poti 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 D-value a bit more.
Remark: In principle, the D-poti 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 D-value, the car loses the track less easy. But of course, this is neither good for the gears, nor for the motor driver.
Remark2: The I-value 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.