Self-parking Car in 500 Lines of Code
A good demonstration of the perils of Proportional-only control -- if the only input to the system is only the instantaneous distances to obstacles, the car can't make any decisions that take into account its momentum. This means it's destined to overshoot the target, as we see in the demos.<p>Consider: if you were given a freeze-frame view of the car in the exact right spot, what controls would you send it to keep it there? It'd be impossible to say without knowing the car's velocity - if the car was in the process of reversing, it should apply forwards acceleration to come to a stop, but if it was in the process of going forwards it should apply reverse acceleration.<p>The solution is to add Derivative control. This would look like a second set of inputs to the system comprised of the difference between the current measurements and the prior ones.