9 #ifndef ROBOT_MODEL_HPP 10 #define ROBOT_MODEL_HPP 13 #include <geometry_msgs/Pose.h> 14 #include <tf2_ros/transform_broadcaster.h> 15 #include <eigen3/Eigen/Dense> 71 void eval_ode(
const state_type &x,
const input_type &u, state_type &dxdt,
const double t);
88 void integrate(state_type &state,
const input_type &input,
double t1,
89 double t2,
double init_step);
105 template <
class MatrixT>
107 MatrixT &A, MatrixT &B)
const;
125 template <
class MatrixT>
127 MatrixT &Ad, MatrixT &Bd,
float dt)
const;
135 template <
class VectorT,
class MatrixT>
137 MatrixT &Ad, MatrixT &Bd,
float dt)
const;
175 std::vector<double>
c_;
190 void ode(
const state_type &x, state_type &dxdt,
const double t);
203 Eigen::Matrix3d
jac_pos(
double phi,
double theta,
double psi);
215 Eigen::Matrix3d
jac_orient(
double phi,
double theta,
double psi);
222 inline double sign(
double x)
const;
229 double a = 1/
c_[3] * (-
c_[1]*speed -
c_[2]*speed*
speed);
230 return sign(speed) * sqrt(abs(a));
236 double delta = pow(
c_[1], 2) - 4*
c_[2]*
c_[3]*pow(propeller_speed, 2);
237 return -(
c_[1] + sqrt(delta)) / (2*
c_[2]);
244 double r = (-
c_[8] - sqrt(pow(
c_[8], 2) + K*pow(u, 2))) / (2*
c_[9]);
245 double R_squared = -
c_[10]*delta_r / (
c_[8]/r +
c_[9]);
247 return sqrt(R_squared);
254 double r = (-
c_[4] - sqrt(pow(
c_[4], 2) + K*pow(u, 2))) / (2*
c_[5]);
255 double R_squared = -
c_[7]*delta_e / (
c_[4]/r +
c_[5]);
257 return sqrt(R_squared);
263 return (
double) (x >= 0);
277 const geometry_msgs::Pose &pose,
282 state[0] = pose.position.x;
283 state[1] = pose.position.y;
284 state[2] = pose.position.z;
285 to_euler(pose.orientation, state[3], state[4], state[5]);
Eigen::Matrix3d jac_pos(double phi, double theta, double psi)
Computes the Jacobian of the position.
input_type u_
Model inputs.
void get_lin_discr_matrices(const state_type &x_0, const input_type &u_0, MatrixT &Ad, MatrixT &Bd, float dt) const
Gets the matrices of the discretised linearised system.
Eigen::Matrix3d jac_orient(double phi, double theta, double psi)
Computes the Jacobian of the orientation.
void ode(const state_type &x, state_type &dxdt, const double t)
ODE used to integrate the model.
double sign(double x) const
Returns the sign of a real number.
double elev_turn_radius(double u, double delta_e) const
Computes the elevation turning radius.
std::vector< double > state_type
Data type of the state.
Declaration of common functions.
double g_
Gravity acceleration.
void integrate(state_type &state, const input_type &input, double t1, double t2, double init_step)
Integrates the model over a period of time.
double steady_speed(double n) const
Computes the horizontal speed in steady state.
void eval_ode(const state_type &x, const input_type &u, state_type &dxdt, const double t)
Evaluate the ODE.
double lat_turn_radius(double u, double delta_r) const
Computes the lateral turning radius.
Class defining the robot model.
std::vector< double > input_type
Data type of the input.
double steady_propeller_speed(double speed) const
Computes the propeller speed in steady state.
RobotModel::state_type to_state(const geometry_msgs::Pose &pose, int state_size)
Converts a pose into a state message.
std::vector< double > c_
Model constants.
void to_euler(const tf2::Quaternion &quat, double &roll, double &pitch, double &yaw)
Converts a quaternion to Roll-Pitch-Yaw Euler angles.
void get_lin_matrices(const state_type &x_0, const input_type &u_0, MatrixT &A, MatrixT &B) const
Gets the matrices of the linearised system.