Unfortunately, he does not show how to actually implement a PID controller, or how to tweak the values of the algorithm, so I thought I’d show you how it’s done.
For my robot, I chose the trike base by HiTechnic, because it is simple, and usable for my next program. The result:
If you are new to NBC, the main thing to remember that an action consist of a line, starting with the action, usually followed by the variable to store the result in, followed by other parameters.
Another important concept are comments, which start with //. These are my notes about what the code does, to help you understand it.
If you want to know more about NBC, read this tutorial.
If you have built a robot, and written the PID controller, the last thing you need to do is tweak the parameters on the lines that start with #define.
kp is multiplied by the proportial, this is where you start. Set the other two to zero, and this one to any value.
If the robot does not move, increase it. If the robot oscillates wildly, decrease it. Do this until it until it oscillates just a bit.
Now divide kp roughly in half, so that it does not oscillate, but stops to early. Now increase ki until it reaches the target as fast as needed. It will overshoot its target.
Finally, increase kd until it stops on target with as little oscillation as possible. You might need to go back and tweak the other parameters a bit.