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.
- If the lane is free ahead, it prefers to stay in it.
- If it is not, check if the closest ones are free before considering passing.
- Only overtake if there is space to gain in the new lane.
- Prefer the left lane over the right lane to pass a car.
- Do not turn left/right if the vehicle is in the left-most/right-most lane.
- 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
- cmake >= 3.5
- All OSes: click here for installation instructions
- make >= 4.1
- Linux: make is installed by default on most Linux distros
- Mac: install Xcode command line tools to get make
- Windows: Click here for installation instructions
- gcc/g++ >= 5.4
- Linux: gcc / g++ is installed by default on most Linux distros
- Mac: same deal as make - [install Xcode command line tools]((https://developer.apple.com/xcode/features/)
- Windows: recommend using MinGW
- uWebSockets
- Run either
install-mac.sh
orinstall-ubuntu.sh
. - If you install from source, checkout to commit
e94b6e1
, i.e.git clone https://github.com/uWebSockets/uWebSockets cd uWebSockets git checkout e94b6e1
- Run either
Basic Build Instructions
- Clone this repo.
- Make a build directory:
mkdir build && cd build
- Compile:
cmake .. && make
- 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