# neural-mpc **Repository Path**: wangshengkai111/neural-mpc ## Basic Information - **Project Name**: neural-mpc - **Description**: No description available - **Primary Language**: Unknown - **License**: GPL-3.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-03-15 - **Last Updated**: 2025-03-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Real-Time Neural MPC This repository contains the code for experiments associated to our paper ``` Real-time Neural-MPC: Deep Learning Model Predictive Control for Quadrotors and Agile Robotic Platforms ``` [Arxiv Link](https://arxiv.org/pdf/2203.07747) If you are looking for the ML-CasADi framework code you can find it [here](https://github.com/TUM-AAS/ml-casadi). ## Installation ### Checkout Submodules ``` git submodule update --init --recursive ``` ### Acados - Follow the [installation instructions](https://docs.acados.org/installation/index.html). - Install the [Python Interface](https://docs.acados.org/python_interface/index.html). - Ensure that `LD_LIBRARY_PATH` is set correctly (`DYLD_LIBRARY_PATH`on MacOS). - Ensure that `ACADOS_SOURCE_DIR` is set correctly. ### Further Requirements ``` pip install -r requirements.txt ``` Make sure the ML-CasADi framework is part of the python path. ``` export PYTHONPATH="${PYTHONPATH}:/ml-casadi" ``` Python 3.9 is recommended. # Experiments The provided code is based on the work of [Torrente et al.](https://github.com/uzh-rpg/data_driven_mpc) All functionality of the original code base is retained. Change the working directory to ``` cd ros_dd_mpc ``` ## Simulation ### Data Collection Run the following script to collect a few minutes of flight samples ``` python src/experiments/point_tracking_and_record.py --recording --dataset_name simplified_sim_dataset --simulation_time 300 ``` ### Fitting a MLP Model Edit the following variables of configuration file in `config/configuration_parameters.py` (class `ModelFitConfig`) so that the training script is referenced to the desired dataset. For redundancy, in order to identify the correct data file, we require to specify both the name of the dataset as well as the parameters used while acquiring the data. In other words, you must input the simulator options used while running the previous python script. If you did not modify these variables earlier, you don't need to change anything this time as the default setting will work: ``` # ## Dataset loading ## # ds_name = "simplified_sim_dataset" ds_metadata = { "noisy": True, "drag": True, "payload": False, "motor_noise": True } ``` The following command will train an MLP model with 4 hidden layers 64 neurons each to model the residual error on the velocities in x, y, and z direction (7, 8, 9 in the state). We assign a name to the model for future referencing, e.g.: `simple_sim_mlp` ``` python src/model_fitting/mlp_fitting.py --model_name simple_sim_mlp --hidden_size 64 --hidden_layers 4 --x 7 8 9 --y 7 8 9 --epochs 100 ``` The model will be saved under the directory `ros_dd_mpc/results/model_fitting//` ### Fitting GP and RDRv For instructions on how to fit a GP or RDRv model for comparison see the [here](https://github.com/uzh-rpg/data_driven_mpc) ### Test the Fitted Model ``` python src/experiments/trajectory_test.py --model_version --model_name simple_sim_mlp --model_typ mlp_approx ``` where the `model_type` argument can be one of `mlp_approx`(Real-time Neural MPC), `mlp` (Naive Integration), `gp` (Gaussian Process Model). For a baseline comparison result run the same script without model parameters: ``` python src/experiments/trajectory_test.py ``` Multiple models can be compared at once via ``` python src/experiments/comparative_experiment.py --model_version --model_name --model_type --fast ``` Results are saved in the `results/` folder. ### Citing If you use this code in an academic context, please cite the following publication: ``` @article{salzmann2023neural, title={Real-time Neural-MPC: Deep Learning Model Predictive Control for Quadrotors and Agile Robotic Platforms}, author={Salzmann, Tim and Kaufmann, Elia and Arrizabalaga, Jon and Pavone, Marco and Scaramuzza, Davide and Ryll, Markus}, journal={IEEE Robotics and Automation Letters}, doi={10.1109/LRA.2023.3246839}, year={2023} } ``` 实时神经MPC 本仓库包含与我们论文相关的实验代码: **实时神经MPC:用于四旋翼飞行器和敏捷机器人平台的深度学习模型预测控制** [Arxiv链接](https://arxiv.org/) 如果您在寻找ML-CasADi框架代码,您可以在这里找到。 ### 安装 #### 检出子模块 ```bash git submodule update --init --recursive ``` #### Acados 1. 按照安装说明进行操作。 2. 安装Python接口。 3. 确保`LD_LIBRARY_PATH`设置正确(在MacOS上是`DYLD_LIBRARY_PATH`)。 4. 确保`ACADOS_SOURCE_DIR`设置正确。 #### 其他要求 ```bash pip install -r requirements.txt ``` 确保ML-CasADi框架在Python路径中。 ```bash export PYTHONPATH="${PYTHONPATH}:/ml-casadi" ``` 推荐使用Python 3.9。 ### 实验 提供的代码基于Torrente等人的工作。原始代码库的所有功能均保留。 将工作目录更改为: ```bash cd ros_dd_mpc ``` #### 仿真 ##### 数据收集 运行以下脚本以收集几分钟的飞行样本: ```bash python src/experiments/point_tracking_and_record.py --recording --dataset_name simplified_sim_dataset --simulation_time 300 ``` ##### 拟合MLP模型 编辑配置文件`config/configuration_parameters.py`中的以下变量(类`ModelFitConfig`),以便训练脚本引用所需的数据集。为了冗余,为了识别正确的数据文件,我们需要指定数据集的名称以及获取数据时使用的参数。换句话说,您必须输入运行上一个Python脚本时使用的模拟器选项。如果您之前没有修改这些变量,这次不需要更改任何内容,因为默认设置将起作用: ```python # ## Dataset loading ## # ds_name = "simplified_sim_dataset" ds_metadata = { "noisy": True, "drag": True, "payload": False, "motor_noise": True } ``` 以下命令将训练一个具有4个隐藏层、每层64个神经元的MLP模型,以建模x、y和z方向速度的残差误差(状态中的7、8、9)。我们为模型分配一个名称以便将来引用,例如:`simple_sim_mlp` ```bash python3 src/model_fitting/mlp_fitting.py --model_name simple_sim_mlp --hidden_size 64 --hidden_layers 4 --x 7 8 9 --y 7 8 9 --epochs 100 ``` 模型将保存在目录`ros_dd_mpc/results/model_fitting//`下。 ##### 拟合GP和RDRv 有关如何拟合GP或RDRv模型以进行比较的说明,请参见[这里](#) ##### 测试拟合模型 ```bash python src/experiments/trajectory_test.py --model_version --model_name simple_sim_mlp --model_type mlp_approx ``` 其中`model_type`参数可以是`mlp_approx`(实时神经MPC)、`mlp`(朴素集成)、`gp`(高斯过程模型)之一。 为了进行基线比较,运行相同的脚本但不带模型参数: ```bash python src/experiments/trajectory_test.py ``` 可以通过以下命令同时比较多个模型: ```bash python src/experiments/comparative_experiment.py --model_version --model_name --model_type --fast ``` 结果保存在`results/`文件夹中。