Longitudinal and Lateral Controller on a Simulated Track Environment

This was the final project for the first course of the self driving car specialization on Coursera – Introduction to Self-Driving Cars. The goal was to implement a lateral and longitudinal controller for a car on a race track given a set of target waypoints and some basic information such as vehicle position, yaw, and speed. More advanced concepts like state estimation, localization, visual perception, and motion planning will be covered in the following courses.

My longitudinal controller is a rudimentary implementation of a PID controller. Unfortunately, I know very little about PID controllers and the course videos didn’t give any examples of how the tuning process worked. So, I relied on my Google-fu and adjusted the parameters through trial and error. In the end, even if the throttle inputs were not as smooth as a human driver might have been, the longitudinal controller was sufficient in keeping the vehicle close to the desired velocity.

For my lateral controller, I implemented the Stanley controller which was a method used by the aptly named Stanley – Stanford University's autonomous vehicle that won the 2005 DARPA Grand Challenge. This was a good chance to polish my rusty trigonometry skills and had me drawing diagrams to visualize the correct angles and headings. Surprisingly, the algorithm worked well enough without the crosstrack error adjustment. I suspect there is no rush to fix crosstrack error on a relatively open environment like a race track.

Simulation

The simulation was run on CARLA, the open-source simulator for autonomous driving research. A script was provided by the course staff that takes care of all the components required besides the longitudinal and lateral controllers. Once running, the script will access the CARLA environment and start receiving state information and sending steering, throttle, and brake commands in return.

Below are the resulting speed as well as the throttle, brake, and steering inputs for the car. Initially, I had a lot of trouble setting up a proper longitudinal controller so I set a static value for the throttle and worked on the lateral controller. Although there was a lot of derivations required to implement the Stanley controller, the individual steps were not too difficult. Once the edge cases were addressed and the vehicle was steering correctly, I implemented the PID controller for longitudinal control. One surprising observation was that even though the PID controller was programmed to brake if necessary, the brakes were not used at all. In fact, the throttle value stayed above 0.5 once it got up to speed. To the right, you can see the 2D map of the track. The actual vehicle trajectory tracks the reference line provided by the waypoints quite well. In my final solution, I was able to complete 100% of the waypoints evaluated by the grader.

Grader Output

Assessment passed!, 100.00% of waypoints completed.