/CarND-Path-Planning-Project

Create a path planner that is able to navigate a car safely around a virtual highway

Primary LanguageC++

CarND-Path-Planning-Project

Self-Driving Car Engineer Nanodegree Program

Basic Build Instructions

  1. Clone this repo.
  2. Make a build directory: mkdir build && cd build
  3. Compile: cmake ../src && make
    To create an Eclipse project, run cmake -G"Eclipse CDT4 - Unix Makefiles" ../src
  4. Run it: ./path_planning.

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

I changed the location of the CMakeLists.txt file following a warning message from cmake. I moved CMakeLists.txt to src/. CMake Warning in CMakeLists.txt: - The build directory was a subdirectory of the source directory. - This is not supported well by Eclipse. It is strongly recommended to use a build directory which is a sibling of the source directory.

Simulator.

You can download the Term3 Simulator which contains the Path Planning Project from the releases tab .

Goals

In this project your goal is to safely navigate around a virtual highway with other traffic that is driving below the 50 MPH speed limit. The car's uses idealised but delayed localization and sensor fusion data, there is also a sparse map list of waypoints around the highway. The car tries to go as close as possible to the 50 MPH speed limit, which means passing slower traffic when possible, note that other cars will try to change lanes too. The car should avoid hitting other cars as well as driving inside of the marked road lanes at all times, unless going from one lane to another. The car should be able to make one complete loop around the 6946m highway. Since the car is trying to go 50 MPH, it should take a little over 5 minutes to complete 1 loop. Also the car should not experience total acceleration over 10 m/s^2 and jerk that is greater than 50 m/s^3.

The map of the highway is in data/highway_map.txt

Each waypoint in the list contains [x,y,s,dx,dy] values. x and y are the waypoint's map coordinate position, the s value is the distance along the road to get to that waypoint in meters, the dx and dy values define the unit normal vector pointing outward of the highway loop.

The highway's waypoints loop around so the frenet s value, distance along the road, goes from 0 to 6945.554.

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

This car controller is a simple prototype for a highway controller. Its implementation is both simple and naive and I see many areas that would benefit from improvement. For example, a more robust implementation would implement a probalistic and predictive behavioural model of the other vehicles on the road and base the driving decisions on this predictive model. Currently the model only considers a first-order estimation of the future state of the vehicles in Frenet coordinates.

Now, let's describe the implementation of the controller.

main.cpp

Load up map values for waypoint's x,y,s and d normalized normal vectors read from a file. The RoadGeometry object handles waypoint map and handles the road geometry.

The file instantiate double buffer to save a first few points. The data is logged using a Double buffering thread that runs concurrently to the main thread.

The main function instanciates the DrivingState class. This class is responsible for taking driving decisions depending on other vehicles in vicinity.

The main class uses a WebSocket callback to communicate with the simulator to provide the future trajectory points and to retrieve Sensor Fusion data.

trajectory.cpp

Functions:

  • ideal_trajectory: this function implements an ideal trajectory that was useful for debugging trajectory closing-loop issues.
  • my_trajectory: this function implements a jerk minimized trajectory parametrized by desired speed and accelerations. This function calculates and control the Self Driving vehicle speed and lane position using a Jerk minimizing function to control the vehicle speed. It uses the previously calculated for implementing a continous path. The Jerk minimization is computed in the Frenet coordinate system. The function also tries to estimate the time lag between the previously sent datapoints and the current step. my_trajectory calls functions in optim_jmt.cpp

optim_jmt.cpp

Functions:

  • optim_jmt_affine: this function optimises the jerk for the s coordinate in the Frenet system. Optimize final distance position s start and s final so that the jerk is defined by an affine function. This type of affine jerk seems to reduce the envelope of the jerk and the acceleration. The speed tends do not overshoot in this configuration. This was found in my quick experiments but would need to be proven formally. The routine uses a concept of virtual acceleration. The equivalent virtual acceleration corresponds to the equivalent average acceleration that would satisfy the motion time constraints.

  • optim_jmt_quadratic : this function optimises the jerk for the d coordinate in the Frenet system is the quadratic Jerk version of optim_jmt_affine. The function solves for a minimum quadratic Jerk polynomial and uses a concept of virtual speed, similar to the virtual acceleration concept used for the optim_jmt_affine.

jmt.cpp

Functions:

  • JMT and JMT_affine: : uses the C++ Matrix calculation Eigen library to compute the functions as described in optim_jmt.cpp

planner.cpp

Implements the class DrivingState. This class decides the finite state machine that computes the driving decisions that the vehicle takes on the highway as a function of the other driving agents. The main metric used to evaluate the cost of the decision is the estimated time to collision to vehicles in vicinity. When the vehicle is following a lead vehicles it maintains a safe distance from it using a simple proportional controller.

utils.cpp

Implements the vehicles position points logger using a concurrent thread that uses double buffering. Example of a glitchy speed profile debugged thanks to my double buffered logger

points.cpp

Implement some simple data structures to perform some calculations on waypoints.

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