|
MFCPP
1.0
|
Corentin Chauvin-Hameau – 2019-2020
|
|
Coverage Path Planning for an underwater robot surveying a marine farm
|
|
Node for Model Predictive Control of a robot. More...
#include <mpc_node.hpp>

Classes | |
| struct | MPCBounds |
| Bounds on the MPC problem. More... | |
| struct | MPCTuningParameters |
| MPC tuning parameters. More... | |
Public Member Functions | |
| MPCNode () | |
| ~MPCNode () | |
| void | run_node () |
| Runs the node. More... | |
Private Member Functions | |
| void | init_node () |
| Initialises the node and its parameters. More... | |
| std::vector< geometry_msgs::Pose > | adapt_path (const std::vector< geometry_msgs::Pose > &orig_path, const geometry_msgs::Point ¤t_position, int nbr_steps, float &spatial_resolution, float &time_resolution, float &desired_speed) |
| Generates a path of the right size for MPC prediction. More... | |
| template<class VectorT > | |
| bool | fill_ref_pts (int N, int n, int m, const std::vector< geometry_msgs::Pose > &path, float desired_speed, float last_desired_speed, const RobotModel &robot_model, VectorT &X_ref, VectorT &U_ref) |
| Fills reference points for MPC optimisation. More... | |
| template<class VectorT > | |
| void | modulo_ref_state (VectorT &X_ref, const VectorT &x0, int n) |
| Changes reference state orientation to prevent modulo discontinuity. More... | |
| template<class VectorT , class MatrixT > | |
| void | fill_ltv_G_H_D (const VectorT &X_ref, const VectorT &U_ref, int N, float dt, float ds, MatrixT &G, MatrixT &H, VectorT &D) |
| Fills the G and H matrices used to express X with respect to U and X0. More... | |
| template<class MatrixT > | |
| void | fill_lti_G (const MatrixT &Ad, const MatrixT &Bd, int N, MatrixT &G) |
| Fills the G matrix used to express X with respect to U and X0. More... | |
| template<class MatrixT > | |
| void | fill_lti_H (const MatrixT &Ad, int N, MatrixT &H) |
| Fills the H matrix used to express X with respect to U and X0. More... | |
| template<class MatrixT > | |
| void | fill_L (const MatrixT &P, const MatrixT &Q_x, int N, MatrixT &L) |
| Fills the L matrix used for quadratic cost wrt state error. More... | |
| template<class MatrixT > | |
| void | fill_M (const MatrixT &R_u, const MatrixT &R_delta, int N, MatrixT &M) |
| Fills the M matrix used for quadratic cost wrt control input error. More... | |
| template<class VectorT , class MatrixT > | |
| void | fill_V (VectorT control_ref, VectorT last_control, const MatrixT &R_delta, int N, VectorT &V) |
| Fills the V matrix used for the linear cost wrt control input error. More... | |
| template<class MatrixT > | |
| void | fill_lti_LG (const MatrixT &G, const MatrixT &P, const MatrixT &Q_x, int n, int m, int N, MatrixT &LG) |
| Fills the product of L and G matrices. More... | |
| template<class VectorT , class MatrixT > | |
| void | fill_bounds_objs (const MPCBounds &bounds, int n, int N, const VectorT &X0, const VectorT &X_ref, const VectorT &U_ref, const MatrixT &G, const MatrixT &H, const VectorT &D, VectorT &lb, VectorT &ub, MatrixT &Ab) |
| Fills the different bounds objects. More... | |
| template<class VectorT , class T > | |
| bool | solve_qp (const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &P, const VectorT &q, const VectorT &lb, const VectorT &ub, const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &Ab, VectorT &solution) |
| Solves a Quadratic Program. More... | |
| bool | compute_control (float &desired_speed, float last_desired_speed, std::vector< float > &command, geometry_msgs::PoseArray &expected_traj) |
| Computes the control signal to send to the robot. More... | |
| void | path_cb (const nav_msgs::Path msg) |
| Callback for the desired path. More... | |
| void | state_cb (const mf_common::Float32Array msg) |
| Callback for the current robot state. More... | |
Private Attributes | |
| ros::NodeHandle | nh_ |
| Node handler (for topics and services) More... | |
| ros::Subscriber | path_sub_ |
| Subscriber for the desired path. More... | |
| ros::Subscriber | state_sub_ |
| Subscriber for the current robot state. More... | |
| ros::Publisher | command_pub_ |
| Publisher for the computed command. More... | |
| ros::Publisher | expected_traj_pub_ |
| Publisher for the expected controlled trajectory. More... | |
| tf2_ros::Buffer | tf_buffer_ |
| Buffer for tf2. More... | |
| tf2_ros::TransformListener | tf_listener_ |
| Transform listener for tf2. More... | |
| nav_msgs::Path | path_ |
| Path to follow. More... | |
| bool | path_received_ |
| Whether a new path has been received. More... | |
| bool | state_received_ |
| Whether the robot state has ever been received. More... | |
| RobotModel | robot_model_ |
| Robot model. More... | |
| std::vector< float > | state_ |
| Current robot state. More... | |
| std::vector< float > | last_control_ |
| Last control applied to the robot. More... | |
| MPCTuningParameters | tuning_params_ |
| MPC tuning parameters. More... | |
| MPCBounds | bounds_ |
| Bounds for the MPC. More... | |
| Eigen::VectorXf | qp_last_primal_ |
| Last primal solution of the Quadratic Problem. More... | |
| Eigen::VectorXf | qp_last_dual_ |
| Last dual solution of the Quadratic Problem. More... | |
| bool | qp_warm_start_ |
| Whether the QP can start warm. More... | |
ROS parameters | |
| float | main_freq_ |
| Frequency of the main loop. More... | |
| std::string | fixed_frame_ |
| Fixed frame. More... | |
| float | desired_speed_ |
| Desired speed (m/s) of the robot. More... | |
| float | last_desired_speed_ |
| Last desired speed (m/s) of the robot. More... | |
| float | time_horizon_ |
| Time horizon (s) for the MPC prediction. More... | |
| int | nbr_steps_ |
| Number of steps for the MPC prediction. More... | |
| bool | disable_vbs_ |
| Whether to disable Variable Buoyancy System (VBS) More... | |
| bool | ltv_mpc_ |
Node for Model Predictive Control of a robot.
MatrixT template can either be Eigen::MatrixXf or Eigen::MatrixXd. VectorT template can either be Eigen::VectorXf or Eigen::VectorXd.
Definition at line 33 of file mpc_node.hpp.
| mfcpp::MPCNode::MPCNode | ( | ) |
Definition at line 31 of file mpc_node.cpp.
| mfcpp::MPCNode::~MPCNode | ( | ) |
Definition at line 39 of file mpc_node.cpp.
|
private |
Generates a path of the right size for MPC prediction.
The path will have as many poses as steps for MPC, with a desired spatial resolution. The desired speed and size of the path are maintained, so if the desired spatial resolution leads to a too long path, the resolution is decreased to fit. If so, the time resolution is also shrinked (ie the path duration is smaller) and the desired speed is decreased.
| [in] | orig_path | Path provided by the path planner |
| [in] | current_position | Current position of the robot |
| [in] | nbr_steps | Number of MPC prediction steps |
| [in,out] | spatial_resolution | Distance between two MPC steps |
| [in,out] | time_resolution | Time between two MPC steps |
| [in,out] | desired_speed | Desired speed |
|
private |
Computes the control signal to send to the robot.
The desired speed might be changed if the robot is close to the end of the path.
| [in,out] | desired_speed | Desired speed (m/s) of the robot |
| [in] | last_desired_speed | Last desired speed |
| [out] | command | Computed control input to apply |
| [out] | expected_traj | Expected controlled trajectory |
|
private |
Fills the different bounds objects.
| [in] | bounds | Bounds of the MPC problem |
| [in] | n | Size of the state |
| [in] | N | Number of steps for the MPC prediction |
| [in] | X0 | Initial offset |
| [in] | X_ref | Reference state (x_0_ref, ..., x_N_ref) |
| [in] | U_ref | Reference input (u_0_ref, ..., u_N_ref) |
| [in] | G | Used to express X with respect to U and X0 |
| [in] | H | Used to express X with respect to U and X0 |
| [in] | D | Used to express X with respect to U and X0 |
| [out] | lb | Lower bound on Ab*U |
| [out] | ub | Upper bound on Ab*U |
| [out] | Ab | Multiplicative factor in front of U in the bound inequalities |
|
private |
|
private |
|
private |
|
private |
Fills the product of L and G matrices.
Optimisation in the Linear Time Invariant MPC case
| [in] | G | G matrix |
| [in] | P | Penalty on the last state error |
| [in] | Q_x | Penalty on the intermediary states errors |
| [in] | n | Size of the state |
| [in] | m | Size of the input |
| [in] | N | Number of steps for the MPC prediction |
| [out] | LG | LG matrix |
|
private |
Fills the G and H matrices used to express X with respect to U and X0.
Linear Time Varying MPC version.
| [in] | X_ref | State reference |
| [in] | U_ref | Control reference |
| [in] | N | Number of steps for the MPC prediction |
| [in] | dt | Sampling time |
| [in] | ds | Spatial resolution of reference path |
| [out] | G | G matrix |
| [out] | H | H matrix |
| [out] | D | D vector |
|
private |
|
private |
Fills reference points for MPC optimisation.
| [in] | N | Number of steps for the MPC prediction |
| [in] | n | Dimension of the state vector |
| [in] | m | Dimension of the control vector |
| [in] | path | Reference path to follow (of size N+1) |
| [in] | desired_speed | Desired speed (m/s) of the robot |
| [in] | last_desired_speed | Last desired speed (m/s) of the robot |
| [in] | robot_model | Robot model |
| [out] | X_ref | Reference state to fill (x0_ref, ..., xN_ref) |
| [out] | U_ref | Reference output to fill (u0_ref, ..., uN_ref) |
|
private |
Fills the V matrix used for the linear cost wrt control input error.
| [in] | control_ref | Reference control |
| [in] | last_control | Last control applied to the robot |
| [in] | R_delta | Penalty on the control change rate |
| [in] | N | Number of steps for the MPC prediction |
| [out] | V | V matrix |
|
private |
Initialises the node and its parameters.
Definition at line 42 of file mpc_node.cpp.
|
private |
Changes reference state orientation to prevent modulo discontinuity.
Adds multiple of 2pi to each orientation so that error in orientation is continuous over the reference points.
| [in,out] | X_ref | Reference state |
| [in] | x0 | Current robot state |
| [in] | n | Dimension of the state |
|
private |
Callback for the desired path.
Definition at line 138 of file mpc_node.cpp.
| void mfcpp::MPCNode::run_node | ( | ) |
Runs the node.
Definition at line 92 of file mpc_node.cpp.
|
private |
|
private |
Callback for the current robot state.
Definition at line 145 of file mpc_node.cpp.
|
private |
Bounds for the MPC.
Definition at line 80 of file mpc_node.hpp.
|
private |
Publisher for the computed command.
Definition at line 68 of file mpc_node.hpp.
|
private |
Desired speed (m/s) of the robot.
Definition at line 91 of file mpc_node.hpp.
|
private |
Whether to disable Variable Buoyancy System (VBS)
Definition at line 95 of file mpc_node.hpp.
|
private |
Publisher for the expected controlled trajectory.
Definition at line 69 of file mpc_node.hpp.
|
private |
Fixed frame.
Definition at line 89 of file mpc_node.hpp.
|
private |
Last control applied to the robot.
Definition at line 78 of file mpc_node.hpp.
|
private |
Last desired speed (m/s) of the robot.
Definition at line 92 of file mpc_node.hpp.
|
private |
Whether to use the Linear Time Varying (LTV) version of MPC
Definition at line 96 of file mpc_node.hpp.
|
private |
Frequency of the main loop.
Definition at line 88 of file mpc_node.hpp.
|
private |
Number of steps for the MPC prediction.
Definition at line 94 of file mpc_node.hpp.
|
private |
Node handler (for topics and services)
Definition at line 65 of file mpc_node.hpp.
|
private |
Path to follow.
Definition at line 73 of file mpc_node.hpp.
|
private |
Whether a new path has been received.
Definition at line 74 of file mpc_node.hpp.
|
private |
Subscriber for the desired path.
Definition at line 66 of file mpc_node.hpp.
|
private |
Last dual solution of the Quadratic Problem.
Definition at line 83 of file mpc_node.hpp.
|
private |
Last primal solution of the Quadratic Problem.
Definition at line 82 of file mpc_node.hpp.
|
private |
Whether the QP can start warm.
Definition at line 84 of file mpc_node.hpp.
|
private |
Robot model.
Definition at line 76 of file mpc_node.hpp.
|
private |
Current robot state.
Definition at line 77 of file mpc_node.hpp.
|
private |
Whether the robot state has ever been received.
Definition at line 75 of file mpc_node.hpp.
|
private |
Subscriber for the current robot state.
Definition at line 67 of file mpc_node.hpp.
|
private |
Buffer for tf2.
Definition at line 70 of file mpc_node.hpp.
|
private |
Transform listener for tf2.
Definition at line 71 of file mpc_node.hpp.
|
private |
Time horizon (s) for the MPC prediction.
Definition at line 93 of file mpc_node.hpp.
|
private |
MPC tuning parameters.
Definition at line 79 of file mpc_node.hpp.
1.8.11