Status: This repository is still under development, expecting new features/papers and a complete tutorial to explain it. Feel free to raise questions/suggestions through GitHub Issues, if you want to use the current version of this repository.
This repository provides a toolkit to test control and planning problems for car racing simulation environment.
Click to open Table of Contents
This project was developed by the help from the following papers:
Parallelized optimization for overtake racing behavior with multiple autonomous vehicles [IEEE] [arXiv] [Video]
@inproceedings{he2022parallel,
title={Autonomous racing with multiple vehicles using a parallelized optimization with safety guarantee using control barrier functions},
author={He, Suiyi and Zeng, Jun and Sreenath, Koushil},
booktitle={2022 IEEE International Conference on Robotics and Automation (ICRA)},
year={2022}
}
Design model predictive control with control barrier functions for obstacle avoidance in car racing problems [IEEE] [arXiv] [NorCal Control Workshop Talk]
@inproceedings{zeng2021mpccbf,
title={Safety-critical model predictive control with discrete-time control barrier function},
author={Zeng, Jun and Zhang, Bike and Sreenath, Koushil},
booktitle={2021 American Control Conference (ACC)},
year={2021},
volume={},
number={},
pages={3882-3889}
}
original structure of the project from the paper:
Current project structure after refactoring (discard ROS1 dependency and moved the planner and combine the controller together with the planner):
the controllers and planners work together to control the ego vehicle and help it navigate through the track with other vehicles. The relationship between the controllers and planners can be better understood in the context of the LMPCRacingGame class.
The LMPCRacingGame class is a controller that inherits from the LMPC class. It extends the functionality of the LMPC controller by incorporating additional racing game constraints and logic, such as collision avoidance with other vehicles, overtaking, and managing the positions of the vehicles on the track.
The planners are used within the LMPCRacingGame class to plan the trajectory and determine the optimal control inputs for the ego vehicle. The RacingGameParam class is used to store the planning parameters, such as the time horizon and the planning prediction factor. The LMPCRacingGame class uses these parameters to generate safe and efficient trajectories for the ego vehicle while considering the positions and velocities of other vehicles on the track.
In summary, the controllers are responsible for determining the control inputs for the ego vehicle based on the current state and desired trajectory, while the planners are used to generate the desired trajectory by considering the environment, including other vehicles and track constraints. The LMPCRacingGame class combines the functionality of both the controller and planner to enable the ego vehicle to navigate through the track while avoiding collisions and overtaking other vehicles.
the simulator has noise in the dynamics of the ego vehicle. This noise is added by default when updating the vehicle's state in the OffboardDynamicBicycleModel class. The noise is added to the longitudinal acceleration and yaw rate in the _update_dynamics()
method of the class.
However, there is an option to remove this noise by using the --zero-noise
argument when running the script. When this argument is passed, the set_zero_noise()
method is called on the ego vehicle, which sets the noise standard deviations for acceleration and yaw rate to zero. This effectively removes the noise from the ego vehicle's dynamics during the simulation.
- We recommend creating a new conda environment:
conda env create -f environment.yml
conda activate car-racing
Run following command in terminal to install the car racing simulator package.
pip install -e .
In this project, pytest
is used to test the code autonomously after pushing new code to the repository. Currently, three files in the tests
folder are used for testing pid or mpc tracking controller, mpc-cbf controller and racing game planner, respectively. To test other features, add files to the tests
folder and update the tests.yml
file under the .github/workflows
folder.
The following documentation contains documentation and common terminal commands for simulations and testing.
To save the historic states and inputs used for learning-based MPC, run the following command for each track layout firstly:
python car_racing/tests/lmpc_test.py \
--track-layout l_shape --lap-number 7 --simulation --save-trajectory
Then you can run the following command:
python car_racing/tests/lmpc_test.py \
--track-layout l_shape --lap-number 10 --simulation --direct-lmpc --animation --plotting
This allows to test algorithm for learning-based MPC. The argparse arguments are listed as follow,
name | type | choices | description |
---|---|---|---|
track_layout |
string | l_shape , m_shape , goggle , ellipse |
track layouts |
lap_number |
int | any number that is greater than 2 |
number of laps that will be simulated |
direct_lmpc |
action | store_true |
if true, the simulator will begin the LMPC controller directly using store trajectories |
zero_noise |
action | store_true |
no noises in dynamic update if true |
save_trajectory |
action | store_true |
if true and when the controller is LMPC, simulator will store the history states and inputs |
simulation |
action | store_true |
generate simulation data if true, otherwise read simulation data from existing files |
plotting |
action | store_true |
save plotting if true |
animation |
action | store_true |
save animation if true |
To save the historic states and inputs used for learning-based MPC, run the following command for each track layout firstly:
python car_racing/tests/overtake_planner_test.py \
--track-layout l_shape --lap-number 7 --simulation --number-other-agents 0 --save-trajectory
Then you can run the following command:
python car_racing/tests/overtake_planner_test.py \
--track-layout l_shape --lap-number 10 --simulation --direct-lmpc --animation --plotting --number-other-agents 3
This allows to test algorithm for racing competition. The argparse arguments are listed as follow,
name | type | choices | description |
---|---|---|---|
track_layout |
string | l_shape , m_shape , goggle , ellipse |
track layouts |
lap_number |
int | any number that is greater than 2 |
number of laps that will be simulated |
direct_lmpc |
action | store_true |
if true, the simulator will begin the LMPC controller directly using store trajectories |
sim_replay |
action | store_true |
if true, by changingfile path, the simulator will simulate with different parameters but from same initial conditions |
zero_noise |
action | store_true |
no noises in dynamic update if true |
diff_alpha |
action | store_true |
if true, different alpha values will be used for same initial conditions |
random_other_agents |
action | store_true |
other agents will be generated randomly if true |
number_other_agents |
int | any number that is greater than 0 , when it is set to 0 , the algorithm is LMPC |
number of agents that will be generated |
save_trajectory |
action | store_true |
if true and when the controller is LMPC, simulator will store the history states and inputs |
multi_tests |
action | store_true |
if ture, 100 groups of randomly generated tests will be simulated |
simulation |
action | store_true |
generate simulation data if true, otherwise read simulation data from existing files |
plotting |
action | store_true |
save plotting if true |
animation |
action | store_true |
save animation if true |
Currently, path planner and trajecotry planner are available for the overtaking maneuver. Changing the varibale self.path_planner
in base.py
to True
allows the controller to simulate with path planner.
The test modes below are from the old project of the paper we referenced. Since it is not nessesary for our project, we haven't refactor the code for it to run on the new version of this codebase. Needs some refactoring job before using the test below.
Run
python car_racing/tests/system_identification_test.py
This allows to identify the linearized dynamics of the racing car by regression.
Run
python car_racing/tests/control_test.py --ctrl-policy mpc-lti --track-layout l_shape --simulation --plotting --animation
This allows to test algorithm for tracking. The argparse arguments are listed as follow,
name | type | choices | description |
---|---|---|---|
ctrl_policy |
string | pid , mpc-lti , lqr |
control policy |
track_layout |
string | l_shape , m_shape , goggle , ellipse |
track layouts |
simulation |
action | store_true |
generate simulation data if true, otherwise read simulation data from existing files |
plotting |
action | store_true |
save plotting if true |
animation |
action | store_true |
save animation if true |
Run
python car_racing/tests/mpccbf_test.py --track-layout l_shape --simulation --plotting --animation
This allows to test algorithm for MPC-CBF controller. The argparse arguments are listed as follow,
name | type | choices | description |
---|---|---|---|
track_layout |
string | l_shape , m_shape , goggle , ellipse |
track layouts |
simulation |
action | store_true |
generate simulation data if true, otherwise read simulation data from existing files |
plotting |
action | store_true |
save plotting if true |
animation |
action | store_true |
save animation if true |
Run
python car_racing/tests/ilqr_test.py --track-layout l_shape --simulation --plotting --animation
This allows to test algorithm for iLQR controller. The argparse arguments are listed as follow,
name | type | choices | description |
---|---|---|---|
track_layout |
string | l_shape , m_shape , goggle , ellipse |
track layouts |
simulation |
action | store_true |
generate simulation data if true, otherwise read simulation data from existing files |
plotting |
action | store_true |
save plotting if true |
animation |
action | store_true |
save animation if true |
from detail explaination of our project please refer to our documentations below:
Project report: https://drive.google.com/file/d/1qqdYlhszkwPwZETbUJ6PtY3SAp_if8y6/view?usp=sharing
project presentation: https://docs.google.com/presentation/d/1UmvFBaMAFYTbx05MaQgZgqfkojcb9ZeR/edit?usp=sharing&ouid=106817078880653835914&rtpof=true&sd=true
Proejct website: https://eecs106b-banana-radiation.github.io/