• Stars
    star
    164
  • Rank 230,032 (Top 5 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 4 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A toolkit for testing control and planning algorithm for car racing.

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.

car-racing

This repository provides a toolkit to test control and planning problems for car racing simulation environment.

Click to open Table of Contents

Table of Contents

Preview

References

If you find this project useful in your work, please consider citing 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}
}

Features

Installation

  • 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 .

Auto Testing

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.

Contributing

Execute pre-commit install to install git hooks in your .git/ directory, which allows auto-formatting if you are willing to contribute to this repository.

Please contact major contributors of this repository for additional information.

Quick-Demos

Docs

The following documentation contains documentation and common terminal commands for simulations and testing.

Offboard

System Identification

Run

python car_racing/tests/system_identification_test.py

This allows to identify the linearized dynamics of the racing car by regression.

Tracking performance with controllers

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

Racing competition with ego controller (MPC-CBF)

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

Racing competition with ego controller (iLQR)

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

Racing competition with ego controller (LMPC)

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

Racing competition with ego planner and controller

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.

Realtime (under development)

To start the simulator, run the following command in terminal:

roslaunch car_racing car_racing_sim.launch track_layout:=goggle

This allows you to run the simulator and visualization node. Change the track_layout, you can get differnt tracks. The center line of the race track is plotted in red dash line; the optimal trajectory of the race track is plotted in green line. To add new vehicle with controller in the simulator, run the following commands in new terminals:

rosrun car_racing vehicle.py --veh-name vehicle1 --color blue --vx 0 --vy 0 --wz 0 --epsi 0 --s 0 --ey 0

rosrun car_racing controller.py --ctrl-policy mpc-lti --veh-name vehicle1

These allow to start nodes for the vehicle and corresponding controller. The argparse arguments are listed as follow,

name type choices description
veh_name string a self-defined name vehicle's name
color string color's name vehicle's color in animation
vs, vy, wz, epsi, s, ey float initial states vehicle's initial states in Frenet coordinates
ctrl_policy string pid, mpc-lti, mpc-cbf , lmpc vehicle's controller type

More Repositories

1

CBF-CLF-Helper

Matlab Interface for Control Barrier Function (CBF) and Control Lyapunov Function (CLF) based control methods.
MATLAB
243
star
2

GenLoco

Python
226
star
3

NMPC-DCLF-DCBF

A collection of work using nonlinear model predictive control (NMPC) with discrete-time control Lyapunov functions (CLFs) and control barrier functions (CBFs)
MATLAB
205
star
4

MPC-CBF

"Safety-Critical Model Predictive Control with Discrete-Time Control Barrier Function" by J. Zeng, B. Zhang and K. Sreenath https://arxiv.org/abs/2007.11718
199
star
5

cbf

An open source repository for control, planning and navigation about control barrier functions.
Python
153
star
6

Lane-Change-CBF

Rule-Based Safety-Critical Control Design with Application to Autonomous Lane Change https://arxiv.org/abs/2103.12382
MATLAB
88
star
7

quadruped_nmpc_dcbf_duality

C++
83
star
8

prompt2walk

Code for Prompt a Robot to Walk with Large Language Models https://arxiv.org/abs/2309.09969
Python
78
star
9

isaac_berkeley_humanoid

Python
45
star
10

multiple-quadrotor-flexible-hose

Multiple quadrotors carrying a flexible hose: dynamics, differential flatness and control
MATLAB
37
star
11

CBF-Pointwise-Feasibility

"Safety-Critical Control using Optimal-decay Control Barrier Functions with Guaranteed Point-wise Feasibility" by J. Zeng, B. Zhang, Z. Li and K. Sreenath https://arxiv.org/pdf/2103.12375.pdf
MATLAB
25
star
12

berkeley_humanoid_description

OpenSCAD
16
star
13

ilqr-iterative-tasks

i2LQR: Iterative LQR for Iterative Tasks in Dynamic Environments (CDC 2023) https://arxiv.org/abs/2302.14246
Python
15
star
14

geometric-toolbox

Contains all the functions (such as hat map, rotations, transport map, etc.) used during the development of geometric mechanics and control of robotic systems.
MATLAB
15
star
15

Quad-Load

Geometric control and differential flatness of a quadrotor UAV with a cable-suspended load.
MATLAB
9
star
16

PPQL

Differential flatness based path planning with direct collocation on hybrid modes for a quadrotor with a cable-suspended payload (RA-L 2020)
MATLAB
6
star
17

dynamics_on_manifolds

Symbolic Computation of Dynamics on Smooth Manifolds
Scala
5
star
18

vo-polytope

Velocity Obstacle for Polytopic Collision Avoidance for Distributed Multi-Robot Systems (RA-L 2023)
Python
5
star
19

Quad-Load-Pulley

"Geometric Control and Differential Flatness of a Quadrotor UAV with Load Suspended from a Pulley" by J. Zeng, P. Kotaru and K. Sreenath https://ieeexplore.ieee.org/document/8815173
MATLAB
5
star
20

ball-and-beam-project

EE222/ME237 Nonlinear Systems, Spring 2022, Starter code for the course project.
MATLAB
4
star
21

Quad-Load-Offset

"Geometric Control of a Quadrotor with a Load Suspended from an Offset" by J. Zeng and K. Sreenath https://ieeexplore.ieee.org/document/8814939
MATLAB
3
star
22

depth_cbf

Point Cloud-Based Control Barrier Function Regression for Safe and Efficient Vision-Based Control
2
star