Quadrotor-NMPC-Control-开源项目复现与问题记录
Quadrotor-NMPC-Control 开源项目复现与问题记录
ACADOS NMPC Quadrotor Position Control Demo
四旋翼高速NMPC控制 ACADOS
项目环境配置流程如下:
git clone
cd Quadrotor-NMPC-Control
conda activate mujo # my conda env
安装 ACADOS
ACADOS 是一个复杂的优化工具,需要手动编译和安装。以下是安装步骤:
git clone
cd acados
mkdir -p build
cd build
cmake ..
make install
如果 cmake .. 遇到如下报错:
cmake ..
– Build type is Release
– ACADOS_WITH_OPENMP: OFF
CMake Error at external/CMakeLists.txt:48 (add_subdirectory):
The source directory
TEXT
/home/hjx/hjx_file/MuJoCo/Quadrotor-NMPC-Control/acados/external/blasfeo
does not contain a CMakeLists.txt file.
CMake Error at external/CMakeLists.txt:61 (add_subdirectory):
The source directory
TEXT
/home/hjx/hjx_file/MuJoCo/Quadrotor-NMPC-Control/acados/external/hpipm
does not contain a CMakeLists.txt file.
–
– Target: BLASFEO is X64_AUTOMATIC, HPIPM is X64_AUTOMATIC
– Linear algebra: HIGH_PERFORMANCE
– Octave MEX (OFF)
– System name:version Linux:5.15.0-131-generic
– Build type is Release
– Installation directory is /home/hjx/hjx_file/MuJoCo/Quadrotor-NMPC-Control/acados
– OpenMP parallelization is OFF
– Configuring incomplete, errors occurred!
See also “/home/hjx/hjx_file/MuJoCo/Quadrotor-NMPC-Control/acados/build/CMakeFiles/CMakeOutput.log”.
从 CMake 错误信息来看,问题是由于
blasfeo
和
hpipm
子模块缺失导致的。这些子模块是 ACADOS 的核心依赖项,通常通过 Git 子模块初始化来获取。以下是解决此问题的详细步骤:
初始化 Git 子模块
ACADOS 使用 Git 子模块来管理依赖项(如
blasfeo
和
hpipm
)。如果子模块未初始化,CMake 将无法找到相关的
CMakeLists.txt
文件。
进入 ACADOS 目录
cd /home/hjx/hjx_file/MuJoCo/Quadrotor-NMPC-Control/acados
初始化子模块
运行以下命令初始化子模块:
git submodule update –init –recursive
检查子模块是否成功初始化
确保
blasfeo
和
hpipm
目录已正确下载:
ls external/blasfeo
ls external/hpipm
重新运行 CMake
子模块初始化完成后,重新运行 CMake:
mkdir -p build
cd build
cmake ..
检查依赖项
确保已安装所有依赖项。在 Ubuntu 上,可以运行以下命令安装依赖:
sudo apt-get install cmake build-essential gcc g++ gfortran
编译 ACADOS
CMake 配置成功后,编译 ACADOS:
make install
检查 libacados.so
是否生成
编译完成后,检查
libacados.so
是否生成:
ls /home/hjx/hjx_file/MuJoCo/Quadrotor-NMPC-Control/acados/lib/libacados.so
设置环境变量
确保
LD_LIBRARY_PATH
包含
libacados.so
的路径。运行以下命令:
export LD_LIBRARY_PATH=/home/hjx/hjx_file/MuJoCo/Quadrotor-NMPC-Control/acados/lib:$LD_LIBRARY_PATH
注意在.bashrc文件中添加:
ACADOS
export ACADOS_SOURCE_DIR=/home/hjx/hjx_file/MuJoCo/Quadrotor-NMPC-Control/acados
export LD_LIBRARY_PATH=/home/hjx/hjx_file/MuJoCo/Quadrotor-NMPC-Control/acados/lib:$LD_LIBRARY_PATH
最后安装 Python 接口
进入
acados_template
目录,安装 Python 接口:
cd /home/hjx/hjx_file/MuJoCo/Quadrotor-NMPC-Control/acados/interfaces/acados_template
conda activate mujo
pip install .
OK,到这里环境配置完成!
下面开始运行对应的demo文件:main.py (注意在终端运行)
python main.py
初次运行应该会遇到如下的提示:
hovor speed: 15.777730167256925 krpm
field AcadosOcpDims.N has been migrated to AcadosOcpOptions.N_horizon. setting AcadosOcpOptions.N_horizon = N. For future comppatibility, please use AcadosOcpOptions.N_horizon directly.
Tera template render executable not found, while looking in path:
/home/hjx/hjx_file/MuJoCo/Quadrotor-NMPC-Control/acados/bin/t_renderer
In order to be able to render the templates, you need to download the tera renderer binaries from:
Do you wish to set up Tera renderer automatically?
y/N? (press y to download tera or any key for manual installation)
问题是由于
t_renderer
未找到导致的。
t_renderer
是 ACADOS 用于渲染模板的工具,缺失时会影响代码生成。
因此只要在运行窗口处输入 “y” 即可
最终的main.py文件运行无误后,会出现如下的界面:
说明项目代码运行成功!!!
参考: