13 #include "mf_common/Float32Array.h" 14 #include "mf_robot_simulator/Command.h" 15 #include <nav_msgs/Path.h> 16 #include <geometry_msgs/TransformStamped.h> 17 #include <geometry_msgs/PoseArray.h> 19 #include <eigen3/Eigen/Dense> 24 using Eigen::MatrixXd;
25 using Eigen::DiagonalMatrix;
33 tf_listener_(tf_buffer_)
45 vector<double> model_csts;
46 vector<double>
P, Q_x, R_u, R_delta;
55 nh_.param<vector<double>>(
"P",
P, vector<double>(13, 1.0));
56 nh_.param<vector<double>>(
"Q_x", Q_x, vector<double>(13, 1.0));
57 nh_.param<vector<double>>(
"R_u", R_u, vector<double>(4, 1.0));
58 nh_.param<vector<double>>(
"R_delta", R_delta, vector<double>(4, 1.0));
60 nh_.param<vector<double>>(
"model_constants", model_csts, vector<double>(11, 0.0));
62 nh_.param<vector<double>>(
"bnd_input",
bounds_.
input, vector<double>(4, 0.0));
87 command_pub_ =
nh_.advertise<mf_robot_simulator::Command>(
"command", 0);
102 vector<float> control;
103 bool control_computed;
105 geometry_msgs::PoseArray expected_traj;
108 control, expected_traj
111 if (control_computed) {
117 mf_robot_simulator::Command
msg;
119 msg.delta_r = control[1];
120 msg.delta_e = control[2];
158 int main(
int argc,
char **argv)
160 ros::init(argc, argv,
"mpc");
Declaration of a node for Model Predictive Control of an underwater robot.
Declaration of physical underwater robot model.
bool disable_vbs_
Whether to disable Variable Buoyancy System (VBS)
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.
Eigen::MatrixXf R_delta
Penalty on the control change rate.
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.
ros::NodeHandle nh_
Node handler (for topics and services)
Declaration of common functions.
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.
void fill_diag_mat(const std::vector< T > &v, Eigen::DiagonalMatrix< T, Eigen::Dynamic > &D)
Fills a Eigen DiagonalMatrix from a std::Vector.
Class defining the robot model.
int main(int argc, char **argv)
Main function called before node initialisation.
float desired_speed_
Desired speed (m/s) of the robot.
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.
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.
float last_desired_speed_
Last desired speed (m/s) of the robot.