dataMPC_parking
dataMPC_parking copied to clipboard
arXiv 2011.00413: (MATLAB Simulation) Collision Avoidance in Tightly-Constrained Environments without Coordination: a Hierarchical Control Approach.
dataMPC_parking
Collision Avoidance in Tightly-Constrained Environments without Coordination: a Hierarchical Control Approach
Authors:
- Xu Shen, [email protected]
- Edward Zhu, [email protected]
- Yvonne R. Stürz, [email protected]
This repository contains all codes for MATLAB prototyping and simulation. The Python+ROS implementation on the BARC car can be found in mpclab_strategy_obca
.
Dependencies
MATLAB:
(for running simulation)
- MPT Toolbox and Yalmip (For solving and viz)
- Parallel Computing Toolbox (Only for generating dataset)
- Deep Learning Toolbox (For network training and predicting)
- CasADi (For controller formulation)
- Forces Pro (For real-time implementation)
Python:
(only for processing rosbags from experiments)
- ROS Noetic
- Packages for pip-installation are listed in
requirement.txt
Quick Demo Guide:
Clone this repository
Download the demo data files:
Link. Place the files in the correct directories. (create new folders when necessary)
(For people having troubles accessing Google Drive, use Baidu instead: https://pan.baidu.com/s/1fJX0sF51U1Gc_mCmgmwt-g Access Code: a7ho)
To solve the offline rollouts:
- Run
./nominal_MPC/path_planning_tv_CFTOC.m
.
To run the strategy-guided approach online:
- Run
./online_MPC/experiments/experiment.m
- After solving, copy the name of the datalog file. The name is printed in the command window, e.g. "Data saved in: xxx/FSM_HOBCA_strat_fp_Exp4_Col0_xxxx.mat"
- Run
./online_MPC/plotting/generate_movie.m
to visualize the performance. Specify the desired datalog at line 6, e.g. "FSM_HOBCA_strat_fp_Exp4_Col0_xxxx".
File Structure:
-
./bag_processing/
: The ipython notebooks for parsing experiment data and plot-
bag_processing.ipynb
is to plot the static images -
video_processing.ipynb
is to plot the video
-
-
./extract_traj/
: The ipython notebooks for extracting data from CARLA data folder -
./learning/
: Different models to learn the mapping from relative configuration to startegies-
strategy_learning/
: learn strategy classifers-
strategy_datagen.m
: Generate strategy labels from offline rollouts -
load_train_classify.m
: Load the strategy labels and offline rollouts and make dataset. Train different models. -
predict_strategy_filter.m
: Apply a filter to the strategy prediction and visualize it along with offline rollouts
-
-
-
./nominal_MPC/
: OBCA to solve the collision avoidance problem and produce rollouts offline-
path_planning_tv_CFTOC.m
: Script to solve one individual scenario with time varying OBCA -
path_planning_datagen_par.m
: Script to generate a bunch of rollouts with parallel process
-
-
./online_MPC/
: SG and BL-OBCA onine-
constraint_generation/
: Strategy Predictor Class and the functions to construct constraints -
controllers/
: The controller classes-
ebrake_controller.m
: The Emergency Break controller -
hpp_obca_controller_FP.m
: The SG-OBCA controller -
obca_controller_FP.m
: The BL-OBCA controller -
safety_controller.m
: The safety controller
-
-
dynamics/
: Vehicle dynamics -
experiments/
: The main experiments scripts. Note that the Baseline method are referred as "Naive" in all codes-
experiment.m
: The script to pick scenario and run experiment -
datagen.m
: The script to solve all scenarios and generate statistics -
FSM_HOBCA_naive_fp.m
: The function to use BL control framework (Set of policies: BL-OBCA, Safety, Emergency-Brake) -
FSM_HOBCA_strat_fp_infalted.m
: The function to use SG control framework (Set of policies: SG-OBCA, Safety, Emergency-Brake)
-
-
plotting/
: Functions to plot -
utils/
: Utils for running experiments-
FiniteStateMachine.m
: The class definition to select different control policies
-
-
Change log
05/25/2021
- Tested the components for demo purpose.
10/01/2020
- Reorganize the files. Now
FSM_HOBCA_naive_fp.m
andFSM_HOBCA_strat_fp.m
are all functions. Useexperiment.m
ordatagen.m
to call them. - Added
Safe-Yield
state.
09/29/2020
- Datagen with FSM
09/28/2020
- Code up the Finite State Machine formulation (
./online_MPC/utils/FiniteStateMachine.m
,./online_MPC/experiments/FSM_online_HOBCA_strat_fp.m
) - Changed the
plotExp.m
to accomodate data files generated by FSM. - Change some function name:
-
check_collision.m
->check_collision_point.m
-
check_current_collision.m
->check_collision_poly.m
-
- Wrap the neural network and filter into
./online_MPC/constraint_generation/StrategyPredictor.m
09/22/2020
- Have another flow of control logic (
./online_MPC/experiments/BACK_*
):- The score will influence the safety controller;
- If the HOBCA is feasible, follow the mode given by score;
- If HOBCA is infeasible, activate the safety controller too;
- In safety controller, if backing up still lead to collision, activate emergency break (which is equivalent to collision here).
- Updated the input to
check_collision_poly.m
function and its usage. - Updated the
./online_MPC/experiments/datagen.m
to have simple evaluation too.
09/21/2020
- Added up and bottom constraints;
- Datagen code for
hobca_strat
andhobca_naive
are finished.
09/16/2020
- Fixed bug in
./online_MPC/dynamics/bike_dynamics_rk4.m
- Added forces pro implementations of naive receding horizon MPC and collision buffer MPC
- A bunch of plotting updates in
./online_MPC/plotting/plotExp.m
- Standardized controller and experiment file formats
- Forces pro generated files are dumped into
./online_MPC/experiments/forces_pro_gen
09/11/2020
- Added rate constriants to safety controller.
- Always solve HOBCA in every timestep. If the threshold just comes above the threshold, the HOBCA is applied only if it is feasible.
- Log more information: actual collision at every time step, the entire time every iteration.
- (TODO) Add a slack to HOBCA distance constriants to encourage larger distance.
09/04/2020
- Added Forces Pro for HppOBCA (Ed). But it will becomes infeasible at some time.
- The exitflag = -6 bug was resolved.
- Dump the plotting and movie generation into a function
./online_MPC/plotting/plotExp.m
- Log the console output into diary file.
08/30/2020
- Added Forces Pro implementation. The class is defined in
./online_MPC/controllers/HPPControlFP.m
and the experiment script is./online_MPC/experiments/online_HPP_force.m
- The Forces Pro generated files are all added into
.gitignore
with the formatFP_*
08/27/2020
- Added the CasADi implementation (Ed).
- Reorgainzed the files. Now all the experiment scripts are in
./online_MPC/experiments
, using either class or CasADi formulation of controllers. All CFTOC-based scripts and functions are in./online_MPC/exp_controllers_CFTOC
.
08/21/2020
- Added the safety controller (Ed)
- Rewrite all controllers in classdef.
MpcController
is the base class, andHppController
,NivController
,HPPobcaController
are subclasses. - Added the up and bottom constraints into
MpcController
.
08/18/2020
- Added
ref_v
for tracking. The score will only discount theref_v
, instead ofref_x
. - Lock the strategy if there are already a certain steps colliding.
08/13/2020
- Added
online_MPC/score_KF.m
for filtering strategy prediction, which helps to overcome sudden jump.
08/12/2020
- The biased hyperplane seems to not perform well... Instead, we can bias the reference trajectory based on strategy prediction scores. The current logic is: if
max(score) < 0.5
, it will yield; if [0.5, 0.6] it will uses a discountedv_ref
; ifmax(score) > 0.6
, it will use the fullv_ref
. Still need to be verified across many test exps. - Fixed the annoying problem of dyn model frame. Now everything is in CoG, and the inputs are [beta, a], where
beta = atan(lr/(lf+lr)*tan(delta))
. Since this function is also monotonic fordelta
, the real vehicle experiment can easily transform it back todelta
. - Changed the input limit. The max acc is now
[-1, 1]
and beta is[-0.35, 0.35]
.
08/11/2020
- Encode the hyperplane constraints into OBCA formulation (
online_MPC/HPPobca_CFTOC.m
). The warm start can be the extended previous iteration. The waypoints to detect collision can also be the previous extend previous z_opt. (online_MPC/online_HOBCA.m
)
08/10/2020
- Generate the score-biased hyperplane (Edward)
- Add the option of score biased hyperplane into
online_MPC/online_HOBCA.m
andonline_MPC/online_hppMPC.m
08/07/2020
- Moved
learning/models
into./models
- Created folder
./online_MPC
and computed the hyperplane online (Edward) - Designed the online MPC controller based on the computed hyperplane, and compare it with the naive formulation.
online_MPC/online_hppMPC.m
compares the hyperplane constrained circular model with naive circular one;online_MPC/online_HOBCA.m
compares the "hpp warm-started" HOBCA with naive circular version.
08/04/2020
- Added NN classifier for strategy prediction (
learning/nn_clas.m
) and added one-hot label variables for it (learning/load_train_classify.m
) - Modified predict and viz script to show strategy posterior probability at the same time (
learning/predict_vs_opt_strategy.m
)
08/03/2020
- Added the strategy generation (
nominal_MPC/check_strategy_labels.m
andnominal_MPC/generat_strategy_data.m
) and its parallel datagen version for constructing dataset (learning/strategy_datagen.m
). - Changed
learning/loda_train_model.m
tolearning/load_train_regression.m
for the specific use of regression of hyperplane. - Added
load_train_classify.m
for constructing dataset for strategy classification. - Added classifiers: Gaussian SVM (
learning/gSVM.m
), bagged tree (learning/bagTree.m
), and KNN (learning/knn.m
)
07/31/2020
- Small modification of saving and loading.
- Added the movie recording function. (
learning/predict_vs_opt_midpoint.m
)
07/30/2020
- Manually divided the ~80% training set and 20% validation set for NN and GP (
learning/load_train_model.m
) - Simplified the GP code, so that it only fits once, output compact model, and offer validation MSE. (
gp.m
)
07/29/2020
- Added the GP training. For every element in the flattened label vector, train one GP for it, with all feature dimensions as the predictor. (
learning/gp.m
) - Renamed
learning/train_network.m
intolearning/load_train_model.m
so that user has the option to train either NN or GP. The NN training is also organized intolearning/nn.m
- Changed the prediction and viz script so that it can switch between GP and NN. (
learning/predict_vs_opt_midpoint.m
)
07/28/2020
- Changed the
learning/gen_feature_label.m
so that it will switch between mid-point mode or free hyperplane mode - Added mid-point into
learning/train_network.m
and seperated the normalization process. (The normalized variable is not used for training now) Also added a new variablereg_data
for regression toolbox. - Created a new script for prediction and visualization in mid-point mode. (
learning/predict_vs_opt_midepoint.m
)
07/27/2020
- Customized the training code (
learning/train_network.m
) - Check the network prediction vs opt (
learning/predict_vs_opt.m
) - Reorganized the data folder:
-
./data/
is the folder to place trajectory examples -
./hyperplane_dataset/
is the folder to place generated hyperplanes for training -
./learning/models/
is the folder to place learned models
-
- Added the hyperplane generation v2, where the hyperplanes are forced to go across the middle point of two sets, and slope is the free decision variable. (
nominal_MPC/generate_hyperplane_v2.m
andlearning/hyperplane_datagen_v2.m
) - ~~TODO: The slope will have the wrapping issue and jumps from pi/2 to -pi/2. Need to smooth it in training feature.~~
07/26/2020
- Reorganized the folder tree, placed all learning related into
./learning/
- Generate hyperplanes from all scenarios and make the dataset (
learning/hyperplane_datagen.m
) - Train a shallow 2-layer FC network and save the model (
learning/train_network.m
)
07/25/2020
- Generate optimal hyperplanes by solving a SVM problem: The current vehicle vertices are hard constraints, the future vertices are soft with slack var. (
nominal_MPC/generate_hyperplanes.m
, Author: Edward) - Generate hyperplane dataset by traversing all data files. (
learning/hyperplane_datagen.m
)
07/23/2020
- Cleaned the code:
- Script for Time Invariant Obstacles:
nominal_MPC/path_planning_ti.m
- Script for Time Varying Obstacles:
nominal_MPC/path_planning_tv_CFTOC.m
andnominal_MPC/*_datagen*
- Scipt for Data loading and visualization:
nominal_MPC/data_viz.m
- Controller Functions:
nominal_MPC/OBCA.m
,nominal_MPC/OBCA_tv
,emergency_break.m
,nominal_MPC/speed_controller.m
- Warm Start Functions:
nominal_MPC/DealWultWS.m
,nominal_MPC/DualMultWS_tv.m
,nominal_MPC/hybrid_A_star.m
,nominal_MPC/unicycleWS.m
- Dynamics and other utils:
nominal_MPC/bikeFE.m
,nominal_MPC/check_collision_*
,nominal_MPC/plotCar.m
- Script for Time Invariant Obstacles:
07/22/2020
- Added data loading and viz script (
data_viz.m
)
07/20/2020
- Added the parallel computing version for faster dataset generation (
path_planning_datagen_par.m
)
07/13/2020
- Path planning with the CFTOC formulation (
path_planning_tv_CFTOC.m
):- Use the simple reference traj to check the collision. If no collsion, adjust the initial state to produce it.
- Try to solve the exact collision avoidance problem. Firstly, use the unicycle model as state WS, and then dual WS, and finally OBCA.
- If the exact problem cannot be solved, try to solve a speed profile on ref path for collision avoidance.
- If the speed profile cannot be solved too, solve a most conservative emergency break.
- Iteratively run over all
exp_num
s and generate data with log file (path_planning_datagen.m
) - Minor fix about constraints of the controller.
07/12/2020
- HOBCA with time variant obstacle formulation. (But in the test, the obstacle remains static for now.)
- Use the simplified vehicle model and collision avoidance constraints for WS, rather than Hybrid A*. Because the Hybrid A* may produce reverse motion due to the collision buffer.
- Changed some function API.
07/06/2020
- HOBCA with multiple obstacles added.
- TODO: dynamic object.
07/02/2020
- HOBCA deployed in MATLAB where only one static obstacle is present. The file is
path_planning.m
. - Workflow:
- Obstacle is firstly defined as Polyhedron;
- The figure is captured as a frame for Hybrid A* toolbox;
- The planned path is smoothened;
- Dual multipliers are firstly warm started;
- The warm starting states are also computed;
- The main optimization is solved
- TODO: Add num of obstacles; Think about dynamic object.