CarND-Path-Planning-Project

This project implements a path planner for highway driving. It is also known as the worst driving commuter ever. The planner is written in C plus plus and builds upon a simulator built with Unity by Udacity. In this write-up, I will talk about some of the features of the planner, namely trajectory generation for lane keeping, lane change decision making to overtake slower vehicles, and speed adjustments to prevent tailgating.

Lane keeping

The simulator provides a set of general waypoints across a round track of 6.5 to 7 km. The path planner generates a spline which connects these waypoints to form a drivable trajectory. The planner tries to calculate fifty points into the future of the vehicle; it does however only add to the already calculated but not driven waypoints.

Slower cars

The ego vehicle starts in the middle lane with a speed of zero. It increases its speed steadily unless it achieves its target speed of 49.5 miles per hour, or unless it approaches a slower vehicle. In this case, it would check whether the adjacent lanes are free and prepare a lane change to be able to drive at its desired speed.

Lane change heuristic

When the vehicle has decided to perform a lane change, it checks its adjacent lane if the lane is currently occupied. If it is in the middle lane, it first checks the left lane, but if that is occupied it also checks the right lane. If no lane is currently free, the vehicle will reduce its speed until the slow car is either too far away, or until a neighbor lane becomes unoccupied and the vehicle can change lanes to overtake the slow vehicle. As soon as there is no slow vehicle in front of the ego vehicle, it will increase its speed again to achieve its desired speed of 49.5 mph.

Trajectory generation

The spline is then used to generate future x and y coordinates depending on the required lane and the currently desired speed of the vehicle. The coordinates are then returned to the simulator, which employs them to show the vehicles performance.

Future Work

There are many possible improvements that could be made to the path planner. The one I have been heard from friends and family the most were to make the vehicle drive after German law, which prohibits the vehicle to overtake on the right side of another vehicle. Another possible improvement would be to change the lane change heuristic to something smarter, like a cost function or an improved state machine. At the moment whenever a slow vehicle is in front of the ego vehicle, it reduces its speed to a much lower value than the slow vehicle. This causes the ego vehicle to „jojo“ behind the slow vehicle. It would be better if it would stay close to the slow car, matching the speed and preparing an overtake maneuver, or deciding not to overtake because there may be a slower vehicle in the other lane.

Basic Build Instructions

  1. Clone this repo.
  2. Make a build directory: mkdir build && cd build
  3. Compile: cmake .. && make
  4. Run it: ./path_planning.

Here is the data provided from the Simulator to the C++ Program

Main car's localization Data (No Noise)

["x"] The car's x position in map coordinates

["y"] The car's y position in map coordinates

["s"] The car's s position in frenet coordinates

["d"] The car's d position in frenet coordinates

["yaw"] The car's yaw angle in the map

["speed"] The car's speed in MPH

Previous path data given to the Planner

//Note: Return the previous list but with processed points removed, can be a nice tool to show how far along the path has processed since last time.

["previous_path_x"] The previous list of x points previously given to the simulator

["previous_path_y"] The previous list of y points previously given to the simulator

Previous path's end s and d values

["end_path_s"] The previous list's last point's frenet s value

["end_path_d"] The previous list's last point's frenet d value

Sensor Fusion Data, a list of all other car's attributes on the same side of the road. (No Noise)

["sensor_fusion"] A 2d vector of cars and then that car's [car's unique ID, car's x position in map coordinates, car's y position in map coordinates, car's x velocity in m/s, car's y velocity in m/s, car's s position in frenet coordinates, car's d position in frenet coordinates.

Details

  1. The car uses a perfect controller and will visit every (x,y) point it recieves in the list every .02 seconds. The units for the (x,y) points are in meters and the spacing of the points determines the speed of the car. The vector going from a point to the next point in the list dictates the angle of the car. Acceleration both in the tangential and normal directions is measured along with the jerk, the rate of change of total Acceleration. The (x,y) point paths that the planner recieves should not have a total acceleration that goes over 10 m/s^2, also the jerk should not go over 50 m/s^3. (NOTE: As this is BETA, these requirements might change. Also currently jerk is over a .02 second interval, it would probably be better to average total acceleration over 1 second and measure jerk from that.

  2. There will be some latency between the simulator running and the path planner returning a path, with optimized code usually its not very long maybe just 1-3 time steps. During this delay the simulator will continue using points that it was last given, because of this its a good idea to store the last points you have used so you can have a smooth transition. previous_path_x, and previous_path_y can be helpful for this transition since they show the last points given to the simulator controller with the processed points already removed. You would either return a path that extends this previous path or make sure to create a new path that has a smooth transition with this last path.

Tips

A really helpful resource for doing this project and creating smooth trajectories was using http://kluge.in-chemnitz.de/opensource/spline/, the spline function is in a single hearder file is really easy to use.


Dependencies

Editor Settings

We've purposefully kept editor configuration files out of this repo in order to keep it as simple and environment agnostic as possible. However, we recommend using the following settings:

  • indent using spaces
  • set tab width to 2 spaces (keeps the matrices in source code aligned)

Code Style

Please (do your best to) stick to Google's C++ style guide.

Project Instructions and Rubric

Note: regardless of the changes you make, your project must be buildable using cmake and make!

Call for IDE Profiles Pull Requests

Help your fellow students!

We decided to create Makefiles with cmake to keep this project as platform agnostic as possible. Similarly, we omitted IDE profiles in order to ensure that students don't feel pressured to use one IDE or another.

However! I'd love to help people get up and running with their IDEs of choice. If you've created a profile for an IDE that you think other students would appreciate, we'd love to have you add the requisite profile files and instructions to ide_profiles/. For example if you wanted to add a VS Code profile, you'd add:

  • /ide_profiles/vscode/.vscode
  • /ide_profiles/vscode/README.md

The README should explain what the profile does, how to take advantage of it, and how to install it.

Frankly, I've never been involved in a project with multiple IDE profiles before. I believe the best way to handle this would be to keep them out of the repo root to avoid clutter. My expectation is that most profiles will include instructions to copy files to a new location to get picked up by the IDE, but that's just a guess.

One last note here: regardless of the IDE used, every submitted project must still be compilable with cmake and make./

How to write a README

A well written README file can enhance your project and portfolio. Develop your abilities to create professional README files by completing this free course.