Self-Driving Car Engineer Nanodegree Program
The program main.cpp allows to generate a path for a car in a simulator. The path will seek to avoid collisions, change lanes when the current lane is too slow and avoid sudden acceleratoin, breaking and jerks.
Below follows an explanation of how the paths are generated.
note: we recommend to use the chrome extension github mathjax to read this documentation to render the math.
To plan the paths the path planning module uses a finite state machine with corresponding cost functions. It also calculates the positions of the cars around itself through sensor fusion and first order polynomial.
A Finite State Machine (FSM) permits to decide on the actions that should be taken at any given moment. The states are as follows,
- KL: keep lane, don't change anything to the path.
- KLA: keep lane accelerate, increase the reference speed.
- KLD: keep lane decelerate, decrease the reference speed.
- PLCL: Plan lane change left
- PLCR: Plan lane change right, this state only returns a cost lower than the maximum cost if the resulting path is still within the lane change range and no collisions would be created by the lane change. If the lane change is permitted, plan a change to the right.
The permitted changes are illustrated in the following picture
The decision to change into a state is based on cost functions. We explain these below.
The cost for keeping lane is set to
The cost for accelerating in a lane is set to
The cost for accelerating in a lane is set to
The cost for planning shifting lane left and right in a lane is set to
We generate a path by creating a spline along our longitudinal and latitudinal data points that we want to visit. We then proceed by making the path discrete by steps dependent on the reference speed. This speed is changed by the KLA and KLD states.
You can download the Term3 Simulator which contains the Path Planning Project from the releases tab.
As shown below the current implementation allows to drive at least 8.47 miles without incident