The PID controller project is all about generating steering angles that create a safe and comfortable driving experience. Imagine a beginner driver and maybe they have been told “try to stay in the middle of the lane” and they see they are a little to the left so they steer right but too hard. Now they need to move a little left so they steer left but too much and so on back and forth creating a really annoying and unsafe driving experience. A PID controller system is about taking a steering system that might know how to steer well and giving it parameter to work with so it produces nice smooth lines that gradually bring a car to where it is desired without over or under steering.
Once again Udacity team up with the best this time Andrew Gray from Uber is here to teach us all about how PID works.
PID is a method for controlling that actually goes way back. Wikipedia have a great page on it that goes into the history if you are curios. First credited use of PID or similar was Christiaan Huygens in the 17th century to regulate the gap between millstones in windmills . Wow I love when something cutting edge technology has old roots. The PID system has also been used in cruise control in cars and steering control in ships all before the modern electronic era!
So what exactly is it? PID stands for Proportional, Integral and Differential. These are 3 related but different values calculated to take into account a desired heading, the current heading and the steering that needs to happen to get them to match. If we just used P for steering we get over-steering and over correcting, in other words oscillating around a desired heading but never staying on it. The other two terms mitigate this effect and generate an effect where steering far away from a desired point is large and then reduces as we get closer to the desired heading. For example if you were far from a center of a lane you might move the steering wheel a lot to quickly get back to centre but then as you get closer to the centre you reduce the steering wheel input to more slowly adjust the car and near the centre you almost completely straighten the wheel. So you do this the whole time but getting a computer to do this is actually quite hard. The animated graph here is from the Wikipedia page and shows what happens if we start adjusting the amount that we factor in the PID terms.
This is a image for the simulator running with a good PID setup , basically it stays near the middle of the road but still have smooth corners. Here you can see the car near the center and in a good position for the gradual bend in the road ahead. As the road straightens out it would return to the very center. If your PID setup is off it will go too wide a the corners or bounce around left to right a lot. This is based on the same simulator as the behavior cloning project but it is used in a different way.
Really what we have achieved in this project is not too obvious from a description and a few screenshots. We had tutorial material in Python and we had to implement the project in C++. This is great practice because that is what you do in industry the whole time. Also we had to learn by experimentation. This is so important because often we don’t know the best way until we experimented to find it. Even though there are only 3 terms to adjust. But until you developed some sense to what levels are used to there is a lot of guessing so initially I did a series of experience with large variations. I picked the best result and did smaller variations and picked the best results and did smaller variations and then some more experiments to confirm before I was happy. All that gave me a good understanding of PID and how seemingly small adjustments can make big differences. Having the simulator helped show this very clearly. Eventually I could get the car to go quite quickly but still corner well. Another thing achieved here is a set up for the final project. We have a lot of freedom about how we might implement the final project but PID is a common and useful mechanism for steering and throttle and brake controllers. Eventually I did use these methods in the final project so this PID controller project even though it was one of the smallest projects in the course was still a valuable set up for the final project and indeed “real world” solutions.