Class MPCController

Inheritance Relationships

Base Type

  • public ControllerMethodBase

Class Documentation

class MPCController : public ControllerMethodBase

A MPC Controller.

Public Functions

MPCController()
~MPCController() override

Destructor.

void on_initialize() override

Initializes parameters and MPC controller.

Throws:

std::runtime_error – if initialization fails.

void update_rt(NavState &nav_state) override

Updates the controller using the given NavState.

Parameters:

nav_state – Current navigation state, including odometry and planned path.

void publish_mpc_path(void *data, const std::vector<double> &best_path, nav_msgs::msg::Path path)

Publishes the selected path by MPC controller.

Parameters:
  • dataMPCParameters object as data pointer

  • best_path – Vector of velocities generated by MPC

  • path – Path obtained from navstate

void collision_checker(void *data, std::vector<double> &u)

Check if there is a possible collision.

Parameters:
  • dataMPCParameters object as data pointer

  • u – Vector of velocities generated by MPC

Protected Attributes

int horizon_steps_ = {5}

Prediction horizon for MPC.

double dt_ = {0.1}

Time step for MPC.

double safety_radius_ = {0.35}

Safety radius to avoid obstacles.

double max_lin_vel_ = {1.5}

Maximum linear velocity for MPC.

double max_ang_vel_ = {1.5}

Maximum angular velocity for MPC.

bool verbose_ = {false}

Value to debug on terminal.

double last_v_ = {0.0}

Last value for linear velocity before than collision.

double last_w_ = {0.0}

Last value for angular velocity before than collision.

bool collision_state_ = {false}

Collision state flag.

double collision_factor_ = {0.618033}

Collision avoidance for recalculate velocities.

double fallback_goal_pos_tol_ = {0.05}

Default positional tolerance (meters).

double fallback_goal_yaw_tol_ = {0.05}

Default angular tolerance (radians).

std::unique_ptr<MPCOptimizer> optimizer_

MPC optimizer.

rclcpp::Publisher<nav_msgs::msg::Path>::SharedPtr mpc_path_pub_

Publisher for MPC path.

rclcpp::Publisher<sensor_msgs::msg::PointCloud2>::SharedPtr detection_pub_

Publisher for MPC obstacles.