A ROS 2 package implementing Nonlinear Model Predictive Control (NMPC) for differential drive robots using the Acados solver.
This package provides a ROS 2 node that implements NMPC for trajectory tracking of differential drive robots. It uses the Acados solver for efficient solution of the optimal control problem.
- ROS 2 (tested on Humble, but should work on other distributions)
- Acados (with Python interface)
- Python 3
- CMake (>= 3.8)
-
Install ROS 2 and create a workspace:
mkdir -p ~/ros2_ws/src cd ~/ros2_ws/src
-
Clone this repository into your ROS 2 workspace:
git clone https://github.com/SokhengDin/ROS2-NMPC-ACADOS.git
-
Install Acados following the official installation guide.
-
Update the
ACADOS_INSTALL_DIRinCMakeLists.txtto point to your Acados installation directory. -
Build the package:
cd ~/ros2_ws colcon build --packages-select ros2_nmpc
-
Source the workspace:
source ~/ros2_ws/install/setup.bash
-
Configure the NMPC parameters in
config/nmpc_diff_params.yaml. -
Launch the NMPC node:
ros2 launch ros2_nmpc nmpc_differential_drive_node.launch.py
-
The node will subscribe to
/odomfor the current robot state and publish velocity commands to/cmd_vel.
You can modify the NMPC parameters in config/nmpc_diff_params.yaml. The main parameters are:
lbx,ubx: State constraints (lower and upper bounds)lbu,ubu: Control constraints (lower and upper bounds)Q_diag: State cost diagonalR_diag: Control cost diagonalR_rate_diag: Control rate cost diagonaldt: Time stepnum_trajectory_points: Number of points in the reference trajectorydistance_threshold: Threshold for considering target reachedtarget_x,target_y,target_theta: Target pose
To use this NMPC controller with a different robot model:
- Modify the
differential_drive_modelinacados_generated/to match your robot's dynamics. - Update the
NMPCDifferentialDriveclass insrc/nmpc_differential_drive.cppto use the new model. - Adjust the parameters in
config/nmpc_diff_params.yamlto suit your robot and control requirements.
- If you encounter "file not found" errors during compilation, ensure that all Acados generated files are in the correct location and that the
ACADOS_INSTALL_DIRinCMakeLists.txtis set correctly. - If the node fails to start, check that the Acados solver library
libacados_ocp_solver_differential_drive.sois present in theacados_generated/differential_drive/directory.