hfoffani / PathPlanning

A C++ implementation of a path planner for self-driving cars.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Path Planning

A C++ implementation of a path planner for self-driving cars.

This project implements a Path Planner to safely navigate a virtual highway with other traffic that is driving +-10 MPH of the 50 MPH speed limit. It uses the Udacity simulator which is available on Github.

The Model

The model consists of two main parts. The Behavior Planning and the Trajectory Generation,

Behavior Planning

The Behavior Planning is implemented using a simple Finite State Machine with three states: KEEP_LANE, LANE_CHANGE_LEFT, LANE_CHANGE_RIGHT.

The maneuver preferences are tuned using a cost function for each action.

  1. If the lane is free ahead, it prefers to stay in it.
  2. If it is not, check if the closest ones are free before considering passing.
  3. Only overtake if there is space to gain in the new lane.
  4. Prefer the left lane over the right lane to pass a car.
  5. Do not turn left/right if the vehicle is in the left-most/right-most lane.
  6. Prefer the middle lane over the left and right lanes.

If the car cannot change lanes because they are busy, try to mimic the current velocity of the car ahead keeping a safe distance.

The output of this step is the lane and the speed that the car should target.

Trajectory Generation

With the next optimal lane and speed, the process generates a path that smoothly respects the highway map and the desired action.

Using geometry from the map waypoints data, the current position of the car and the target destination I create 3 points spread along the next 90mts. These three points plus two more from the previous trajectory conforms the input dataset.

A spline algorithm fed by the input dataset provides a function that allows us to interpolate the rest of the points spread by 20ms each.

The interpolated points are converted to global coordinates before sending them to the simulator.


Dependencies

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.

License

This project is published under the Apache License.

Contributions

I gratefully honor Pull Requests. Please, consider formatting the code with K&R style and four spaces tabs.

Who do I talk to?

For questions or requests post an issue here or tweet me at @herchu

About

A C++ implementation of a path planner for self-driving cars.


Languages

Language:C++ 83.1%Language:Fortran 11.5%Language:C 2.0%Language:CMake 1.8%Language:Cuda 1.1%Language:Shell 0.2%Language:Python 0.1%Language:JavaScript 0.1%Language:CSS 0.0%