14 #include "mf_common/Float32Array.h" 15 #include <nav_msgs/Path.h> 16 #include <geometry_msgs/TransformStamped.h> 17 #include <geometry_msgs/PoseArray.h> 18 #include <geometry_msgs/Pose.h> 19 #include <tf2_ros/transform_listener.h> 21 #include <eigen3/Eigen/Dense> 122 const std::vector<geometry_msgs::Pose> &orig_path,
123 const geometry_msgs::Point ¤t_position,
125 float &spatial_resolution,
126 float &time_resolution,
144 template <
class VectorT>
147 const std::vector<geometry_msgs::Pose> &path,
149 float last_desired_speed,
165 template <
class VectorT>
182 template <
class VectorT,
class MatrixT>
184 int N,
float dt,
float ds,
185 MatrixT &G, MatrixT &H, VectorT &D);
197 template <
class MatrixT>
198 void fill_lti_G(
const MatrixT &Ad,
const MatrixT &Bd,
int N, MatrixT &G);
209 template <
class MatrixT>
210 void fill_lti_H(
const MatrixT &Ad,
int N, MatrixT &H);
220 template <
class MatrixT>
221 void fill_L(
const MatrixT &
P,
const MatrixT &
Q_x,
int N, MatrixT &L);
231 template <
class MatrixT>
243 template <
class VectorT,
class MatrixT>
244 void fill_V(VectorT control_ref, VectorT last_control,
245 const MatrixT &
R_delta,
int N, VectorT &V);
260 template <
class MatrixT>
261 void fill_lti_LG(
const MatrixT &G,
const MatrixT &
P,
const MatrixT &
Q_x,
int n,
262 int m,
int N, MatrixT &LG);
280 template <
class VectorT,
class MatrixT>
284 const VectorT &X0,
const VectorT &X_ref,
const VectorT &U_ref,
285 const MatrixT &G,
const MatrixT &H,
const VectorT &D,
286 VectorT &lb, VectorT &ub, MatrixT &Ab
294 template <
class VectorT,
class T>
296 const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> &
P,
300 const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> &Ab,
318 float &desired_speed,
319 float last_desired_speed,
321 geometry_msgs::PoseArray &expected_traj
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.
Declaration of physical underwater robot model.
bool disable_vbs_
Whether to disable Variable Buoyancy System (VBS)
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.
ros::Publisher expected_traj_pub_
Publisher for the expected controlled trajectory.
float time_horizon_
Time horizon (s) for the MPC prediction.
MPCBounds bounds_
Bounds for the MPC.
Node for Model Predictive Control of a robot.
Eigen::MatrixXf Q_x
Penalty on the intermediary states errors.
ros::Subscriber path_sub_
Subscriber for the desired path.
nav_msgs::Path path_
Path to follow.
std::vector< float > last_control_
Last control applied to the robot.
tf2_ros::Buffer tf_buffer_
Buffer for tf2.
Eigen::MatrixXf R_delta
Penalty on the control change rate.
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.
Eigen::MatrixXf R_u
Penalty on the control input error.
float main_freq_
Frequency of the main loop.
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.
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.
ros::NodeHandle nh_
Node handler (for topics and services)
std::vector< float > state_
Current robot state.
Eigen::MatrixXf P
Penalty on the last state error.
bool qp_warm_start_
Whether the QP can start warm.
std::vector< double > input
void state_cb(const mf_common::Float32Array msg)
Callback for the current robot state.
RobotModel robot_model_
Robot model.
void path_cb(const nav_msgs::Path msg)
Callback for the desired path.
Bounds on the MPC problem.
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.
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.
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.
Class defining the robot model.
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.
float desired_speed_
Desired speed (m/s) of the robot.
void modulo_ref_state(VectorT &X_ref, const VectorT &x0, int n)
Changes reference state orientation to prevent modulo discontinuity.
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.
std::string fixed_frame_
Fixed frame.
int nbr_steps_
Number of steps for the MPC prediction.
ros::Publisher command_pub_
Publisher for the computed command.
MPCTuningParameters tuning_params_
MPC tuning parameters.
void init_node()
Initialises the node and its parameters.
ros::Subscriber state_sub_
Subscriber for the current robot state.
tf2_ros::TransformListener tf_listener_
Transform listener for tf2.
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.
Eigen::VectorXf qp_last_dual_
Last dual solution of the Quadratic Problem.
void run_node()
Runs the node.
bool state_received_
Whether the robot state has ever been received.
bool path_received_
Whether a new path has been received.
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.
float last_desired_speed_
Last desired speed (m/s) of the robot.
Eigen::VectorXf qp_last_primal_
Last primal solution of the Quadratic Problem.