controls  3.0.0
SystemDynamicsBase.h
Go to the documentation of this file.
1 #ifndef CONTROLS_DYNAMICS_SYSTEM_DYNAMICS_BASE_H
2 #define CONTROLS_DYNAMICS_SYSTEM_DYNAMICS_BASE_H
3 
4 #include <utils/Transforms.h>
5 
6 #include <array>
7 
21 private:
30  Matrix6d compute_coriolis_from_mass(const Matrix6d& mass, const Vector6d& velocity) const;
31 
35  void update_mass();
36 
38  double mass_ = NAN;
39 
41  double weight_ = NAN;
42 
44  double buoyancy_ = NAN;
45 
47  Matrix3d Irb_ = Matrix3d::Zero();
48 
50  Matrix6d Mrb_ = Matrix6d::Zero();
51 
53  Matrix6d Ma_ = Matrix6d::Zero();
54 
56  Matrix6d M_ = Matrix6d::Zero();
57 
59  Matrix6d Dl_ = Matrix6d::Zero();
60 
62  Matrix6d Dnl_ = Matrix6d::Zero();
63 
65  Vector3d rgb_ = Vector3d::Zero();
66 
68  Vector3d rbb_ = Vector3d::Zero();
69 
71  Vector3d fgn_ = Vector3d::Zero();
72 
74  Vector3d fbn_ = Vector3d::Zero();
75 
76 public:
80  const bool is_system_3dof_;
81 
87  explicit SystemDynamicsBase(const bool is_3dof);
88 
92  virtual ~SystemDynamicsBase() = default;
93 
94  /* ------------------------------------------------------------------ */
95  /* Const accessors */
96  /* ------------------------------------------------------------------ */
97 
99  const Matrix6d& get_m() const {
100  return M_;
101  }
102 
104  const Matrix6d& get_mrb() const {
105  return Mrb_;
106  }
107 
109  const Matrix6d& get_ma_matrix() const {
110  return Ma_;
111  }
112 
114  const Matrix6d& get_dl_matrix() const {
115  return Dl_;
116  }
117 
119  const Matrix6d& get_dnl_matrix() const {
120  return Dnl_;
121  }
122 
124  const Vector3d& get_rgb_vec() const {
125  return rgb_;
126  }
127 
129  const Vector3d& get_rbb_vec() const {
130  return rbb_;
131  }
132 
134  const Vector3d& get_fgn() const {
135  return fgn_;
136  }
137 
139  const Vector3d& get_fbn() const {
140  return fbn_;
141  }
142 
144  double get_mass_value() const {
145  return mass_;
146  }
147 
149  double get_weight() const {
150  return weight_;
151  }
152 
154  double get_buoyancy_value() const {
155  return buoyancy_;
156  }
157 
158  /* ------------------------------------------------------------------ */
159  /* Dynamics evaluation (const) */
160  /* ------------------------------------------------------------------ */
161 
169  Matrix6d get_d(const Vector6d& velocity) const;
170 
178  Matrix6d get_crb(const Vector6d& velocity) const;
179 
187  Matrix6d get_ca(const Vector6d& velocity) const;
188 
196  Matrix6d get_c(const Vector6d& velocity) const;
197 
205  Vector6d get_g(const Quaterniond& q) const;
206 
214  Vector6d get_g(const Vector3d& rpy) const;
215 
229  virtual Vector6d get_inverse_dynamics(const Vector6d& velocity, const Vector6d& acceleration,
230  const Quaterniond& orientation) const;
231 
232  /* ------------------------------------------------------------------ */
233  /* Mutators (maintain M_ = Mrb_ + Ma_ invariant) */
234  /* ------------------------------------------------------------------ */
235 
243  void set_mass(double m);
244 
250  void set_buoyancy(double factor);
251 
257  void set_i(const std::array<double, 6>& I);
258 
264  void set_ma(const std::array<double, 6>& m);
265 
271  void set_dl(const std::array<double, 6>& d);
272 
278  void set_dnl(const std::array<double, 6>& d);
279 
285  void set_rbb(const std::array<double, 3>& rbb);
286 
292  void set_rgb(const std::array<double, 3>& rgb);
293 };
294 
295 #endif // CONTROLS_DYNAMICS_SYSTEM_DYNAMICS_BASE_H
Eigen::Matrix< double, 6, 6 > Matrix6d
Definition: Types.h:20
Eigen::Matrix< double, 6, 1 > Vector6d
Definition: Types.h:29
Base class encoding the 6DOF hydrodynamic model of a marine vehicle.
Definition: SystemDynamicsBase.h:20
Matrix6d get_crb(const Vector6d &velocity) const
Evaluates the rigid-body Coriolis matrix Crb(v)
Definition: SystemDynamicsBase.cpp:37
const Vector3d & get_fgn() const
Returns the gravitational force vector in the world frame.
Definition: SystemDynamicsBase.h:134
const Vector3d & get_rgb_vec() const
Returns the centre of gravity in the body frame.
Definition: SystemDynamicsBase.h:124
const Matrix6d & get_m() const
Returns the total mass matrix M = Mrb + Ma.
Definition: SystemDynamicsBase.h:99
const Matrix6d & get_ma_matrix() const
Returns the added-mass matrix Ma.
Definition: SystemDynamicsBase.h:109
virtual ~SystemDynamicsBase()=default
Virtual destructor.
const Matrix6d & get_mrb() const
Returns the rigid-body mass matrix Mrb.
Definition: SystemDynamicsBase.h:104
const Vector3d & get_fbn() const
Returns the buoyancy force vector in the world frame.
Definition: SystemDynamicsBase.h:139
void set_rbb(const std::array< double, 3 > &rbb)
Sets the centre-of-buoyancy position in the body frame.
Definition: SystemDynamicsBase.cpp:123
double get_weight() const
Returns the vehicle weight in N.
Definition: SystemDynamicsBase.h:149
Vector6d get_g(const Quaterniond &q) const
Evaluates the 6DOF gravitational and buoyancy restoring vector G(q)
Definition: SystemDynamicsBase.cpp:49
void set_dnl(const std::array< double, 6 > &d)
Sets the diagonal quadratic (nonlinear) damping coefficients.
Definition: SystemDynamicsBase.cpp:116
void set_mass(double m)
Sets vehicle mass and recomputes weight, buoyancy, and the rigid-body mass matrix.
Definition: SystemDynamicsBase.cpp:68
void set_buoyancy(double factor)
Sets the buoyancy force as a scale factor relative to vehicle weight.
Definition: SystemDynamicsBase.cpp:86
const Matrix6d & get_dnl_matrix() const
Returns the quadratic damping matrix Dnl.
Definition: SystemDynamicsBase.h:119
const Matrix6d & get_dl_matrix() const
Returns the linear damping matrix Dl.
Definition: SystemDynamicsBase.h:114
Matrix6d get_d(const Vector6d &velocity) const
Evaluates the total damping matrix D(v) = Dl + Dnl*diag(|v|)
Definition: SystemDynamicsBase.cpp:13
Matrix6d get_c(const Vector6d &velocity) const
Evaluates the total Coriolis matrix C(v) = Crb(v) + Ca(v)
Definition: SystemDynamicsBase.cpp:45
void set_dl(const std::array< double, 6 > &d)
Sets the diagonal linear damping coefficients.
Definition: SystemDynamicsBase.cpp:109
const bool is_system_3dof_
True if the vehicle is constrained to the XY-Yaw plane (3DOF surface vehicle)
Definition: SystemDynamicsBase.h:80
Matrix6d get_ca(const Vector6d &velocity) const
Evaluates the added-mass Coriolis matrix Ca(v)
Definition: SystemDynamicsBase.cpp:41
double get_buoyancy_value() const
Returns the net buoyancy force in N.
Definition: SystemDynamicsBase.h:154
double get_mass_value() const
Returns the vehicle mass in kg.
Definition: SystemDynamicsBase.h:144
virtual Vector6d get_inverse_dynamics(const Vector6d &velocity, const Vector6d &acceleration, const Quaterniond &orientation) const
Computes the inertial + Coriolis + damping force M*a + C(v)*v + D(v)*v.
Definition: SystemDynamicsBase.cpp:63
void set_i(const std::array< double, 6 > &I)
Sets the rigid-body inertia tensor.
Definition: SystemDynamicsBase.cpp:91
SystemDynamicsBase(const bool is_3dof)
Constructs the dynamics base and sets the DOF flag.
Definition: SystemDynamicsBase.cpp:5
void set_ma(const std::array< double, 6 > &m)
Sets the diagonal added-mass coefficients.
Definition: SystemDynamicsBase.cpp:101
void set_rgb(const std::array< double, 3 > &rgb)
Sets the centre-of-gravity position in the body frame.
Definition: SystemDynamicsBase.cpp:130
const Vector3d & get_rbb_vec() const
Returns the centre of buoyancy in the body frame.
Definition: SystemDynamicsBase.h:129