The Simulator can be downloaded here.
To run the simulator on Mac/Linux, first make the binary file executable with the following command:
sudo chmod u+x {simulator_file_name}
- 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 DriveController (DC) is the main component of the path planner. It creates a trajectory based on the current environment state.
When the class is initialized, the Map
class and the Car
class are stored in the DC:
Map highway_map = Map();
Car car = Car();
DriveController drive_controller = DriveController(&car, &highway_map);
The sensor fusion data (positions of the cars surrounding the ego car) has to be updated every cycle:
drive_controller.update_environment(sensor_fusion);
The same applies for the current car status:
drive_controller.car->setX(j[1]["x"]);
drive_controller.car->setY(j[1]["y"]);
drive_controller.car->setS(j[1]["s"]);
drive_controller.car->setD(j[1]["d"]);
drive_controller.car->setYaw(j[1]["yaw"]);
drive_controller.car->setSpeed(j[1]["speed"]);
After the current environment and the car status are updated, the DC can generate a trajectory. To do that, the plan_path()
function is called.
vector<vector<double>> next_vals = drive_controller.plan_path(previous_path_x.size());
It handles acceleration, checks if lanes are safe and performs lane changes.
Then, the trajectory is generated in the vector<vector<double>> DriveController::create_trajectory(int prev_size)
function. It generates 5 anchor points (in car centered coordinate system) and then creates a spline using the anchor points. Using the spline, a set number of trajectory points can be generated. Finally, the points have to be transformed back into a global coordinate system. The spline is used to smooth the trajectory in order to stay in the jerk boundaries.
The Car
class is a data class that stores the current position, speed and lane of the ego car.
The Map
class is a data class that stores the map attributes (x, y, s, dx, dy).