This package implements a Model Predictive Control (MPC) based local planner for a differential drive robot using the CasADi optimization framework. It is designed to be used as a plugin within the ROS move_base navigation stack.
- Change goal_reached function to be FSM-aware
- Improve heading error calculation to reduce oscillations near the goal
- Incorporate obstacle cost into the MPC cost function using costmap values
-
Implements nonlinear MPC using CasADi and IPOPT
-
FSM = TRACK, ROTATE, STOP
-
Optimizes over forward velocity
vand angular velocityw -
Penalizes:
- Position error to reference trajectory
- Control effort (v and w)
- Heading (orientation) error
-
Uses ROS
costmap_2d::Costmap2DROSand TF for robot state -
Compatible with
nav_core::BaseLocalPlannerinterface
- ROS (tested on Noetic)
- CasADi (installed from source or via pip)
pluginlibgeometry_msgs,tf2,costmap_2d
cd ~/catkin_ws/src
git clone https://github.com/emirhancibir/mpc_local_planner
cd ..
catkin_make- Add the planner to your
move_baseconfig:
base_local_planner: "mpc_local_planner/MPCPlanner"-
Ensure CasADi is installed and linked properly in
CMakeLists.txtandpackage.xml. -
Launch with
move_baseand send a goal inmapframe.
The MPC minimizes the following cost at each time step k:
J = ∑ (||x_k - ref_k||^2 + lambda1 * ||u_k||^2 + lambda2 * heading_error_k^2)
Where:
x_kis the robot state [x, y, theta]u_kis the control input [v, w]ref_kis the reference waypointheading_error_kis the orientation error (wrapped in [-pi, pi])
x_next = x + v * dt * cos(theta)
y_next = y + v * dt * sin(theta)
theta_next = theta + w * dt- The robot is expected to move forward only (
vin [0, vmax]). - Angular velocity is symmetric (
win [-wmax, +wmax]). - Heading error is wrapped properly to avoid oscillations using CasADi-safe modulo logic.