Project requires the following open source simulator : link
- Clone this repo.
- Make a build directory:
mkdir build && cd build
- Compile:
cmake .. && make
- Run it:
./path_planning
.
- 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
The goal of the path planner is to generate a safely navigatable trajectory along a 3 lange highway with other traffic. The speed limit of the highway is 50MPH (~80km/h), other cars are expected to follow speed limit (+- 10MPH).
The car is also expected to reach the destination with minimum time while meeting the following standards in the order of priority :
- Physical Feasibility (Basically stay nonholonomic & no teleportations!!!)
- Safety (Car must at all times try to stay in the middle of a lane, except when lange changing. No collisions, or running over objects)
- Legality (Traffic rules including speed limit, one-way rules, should be duely followed at all times)
- Comfort (no acceleration over 10 m/s^2 and jerk over 10 m/s^3)
- Efficiency (Reach destination in minimal time, while following the above rules)
The project code has been divided into four sequential parts
1. Sensor fusion : main.cpp [line 253-301]
Here the data from the cars sensor fusion module is read.
Two logics are implemented at this point :
- Detect if there are any cars directly ahead of ego car in 35m. If so turn the
too_close
flagtrue
. - Identify all cars ahead and behind the ego car in all lanes within a set distance and classify them by the lane numbers they belong to. Three counters are used for this
l_lane, m_lane, r_lane
, corresponding to left, middle and right lanes respectively.
2. Speed Control main.cpp [line 303-311]
- The velocity of the car is initially set to zero, and it is incremented in steps of 0.4 as long as the car is below the speed limit and there are no cars directly ahead in collision range.
- The velocity of the car is decremented by 0.5 if there is a car ahead. There is a further collision avoidance routine which would switch the speed of the ego car to that of the car directly ahead if the space between them are below 5m
main.cpp [line 276]
.
3. Switch lane main.cpp [line 314-334]
- The switch lane checks the flag
too_close
, if there is a car ahead going slow, it will get ready for lane change. This is done using aswitch
statement. If the car is in the lane 0 it can change to lane 2, if the car is in lane 1 it can either change to lane 0 or 2, and finally if the car is in lane 2 it can change to lane 1. - Before initializing the lane change maneuver the car checks if its safe to perform. This is done using the data from the variables
l_lane, m_lane, r_lane
. The lane change has to consider future position of the cars. There are two scenarios to consider, the car lagging could suddenly increase speed, or the car leading could suddenly reduce the speed. By taking into consideration the max speed limit (50mph), it became clear that it would be safe to swith lane when there are no cars 15m ahead and behind (in the lane to which the ego car is switching). This logic has been implemented onmain.cpp [line 285]
. - This information is also printed on to the terminal. It shows the number of collision potential cars in a given lane.
4. Use spline to generate trajectory main.cpp [line 303-311]
- For a smooth trajectory generation Spline interpolation in the Frenet coordinate was performed.
- Spline interpolation was chosen because:
- An open source spline generation library for C++ was easily available.
- Spline generated paths are guaranteed to be continous at merging points and they also have continous first and second derivative where they join, assuring a very smooth jerk free motion.
- The spline control points were selected to be 3, and they were spread at a distance of 30 meaters each.
main.cpp [line 371]
- Using Frenet coordinates proved to be extremely beneficial as the longitudal motion s can be easily represented as current s point in the Frenet coordinate plus a desired constant distance. And the lateral point is a constant d corrensponding to the center of the current lane.
- The code complies with cmake.
- The car is able to drive multiple laps without any incidents (including collisions or breaking speed limit).
- At all times the max acceleration and jerk is kept in acceptable range.
- The car changes lanes when ever it is feasible and necessary.