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 computeCoriolisFromMass(const Matrix6d& mass, const Vector6d& velocity) const;
31 
35  void updateMass();
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 isSystem3DOF;
81 
87  explicit SystemDynamicsBase(const bool is3DOF);
88 
92  virtual ~SystemDynamicsBase() = default;
93 
94  /* ------------------------------------------------------------------ */
95  /* Const accessors */
96  /* ------------------------------------------------------------------ */
97 
99  const Matrix6d& getM() const {
100  return M_;
101  }
102 
104  const Matrix6d& getMrb() const {
105  return Mrb_;
106  }
107 
109  const Matrix6d& getMaMatrix() const {
110  return Ma_;
111  }
112 
114  const Matrix6d& getDlMatrix() const {
115  return Dl_;
116  }
117 
119  const Matrix6d& getDnlMatrix() const {
120  return Dnl_;
121  }
122 
124  const Vector3d& getRgbVec() const {
125  return rgb_;
126  }
127 
129  const Vector3d& getRbbVec() const {
130  return rbb_;
131  }
132 
134  const Vector3d& getFgn() const {
135  return fgn_;
136  }
137 
139  const Vector3d& getFbn() const {
140  return fbn_;
141  }
142 
144  double getMassValue() const {
145  return mass_;
146  }
147 
149  double getWeight() const {
150  return weight_;
151  }
152 
154  double getBuoyancyValue() const {
155  return buoyancy_;
156  }
157 
158  /* ------------------------------------------------------------------ */
159  /* Dynamics evaluation (const) */
160  /* ------------------------------------------------------------------ */
161 
169  Matrix6d getD(const Vector6d& velocity) const;
170 
178  Matrix6d getCrb(const Vector6d& velocity) const;
179 
187  Matrix6d getCa(const Vector6d& velocity) const;
188 
196  Matrix6d getC(const Vector6d& velocity) const;
197 
205  Vector6d getG(const Quaterniond& q) const;
206 
214  Vector6d getG(const Vector3d& rpy) const;
215 
229  virtual Vector6d getInverseDynamics(const Vector6d& velocity, const Vector6d& acceleration,
230  const Quaterniond& orientation) const;
231 
232  /* ------------------------------------------------------------------ */
233  /* Mutators (maintain M_ = Mrb_ + Ma_ invariant) */
234  /* ------------------------------------------------------------------ */
235 
243  void setMass(double m);
244 
250  void setBuoyancy(double factor);
251 
257  void setI(const std::array<double, 6>& I);
258 
264  void setMa(const std::array<double, 6>& m);
265 
271  void setDl(const std::array<double, 6>& d);
272 
278  void setDnl(const std::array<double, 6>& d);
279 
285  void setRbb(const std::array<double, 3>& rbb);
286 
292  void setRgb(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
void setMass(double m)
Sets vehicle mass and recomputes weight, buoyancy, and the rigid-body mass matrix.
Definition: SystemDynamicsBase.cpp:68
Matrix6d getCrb(const Vector6d &velocity) const
Evaluates the rigid-body Coriolis matrix Crb(v)
Definition: SystemDynamicsBase.cpp:37
void setDnl(const std::array< double, 6 > &d)
Sets the diagonal quadratic (nonlinear) damping coefficients.
Definition: SystemDynamicsBase.cpp:116
double getBuoyancyValue() const
Returns the net buoyancy force in N.
Definition: SystemDynamicsBase.h:154
const Vector3d & getRgbVec() const
Returns the centre of gravity in the body frame.
Definition: SystemDynamicsBase.h:124
void setRgb(const std::array< double, 3 > &rgb)
Sets the centre-of-gravity position in the body frame.
Definition: SystemDynamicsBase.cpp:130
void setDl(const std::array< double, 6 > &d)
Sets the diagonal linear damping coefficients.
Definition: SystemDynamicsBase.cpp:109
Matrix6d getCa(const Vector6d &velocity) const
Evaluates the added-mass Coriolis matrix Ca(v)
Definition: SystemDynamicsBase.cpp:41
virtual Vector6d getInverseDynamics(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
virtual ~SystemDynamicsBase()=default
Virtual destructor.
const Vector3d & getRbbVec() const
Returns the centre of buoyancy in the body frame.
Definition: SystemDynamicsBase.h:129
const Matrix6d & getDnlMatrix() const
Returns the quadratic damping matrix Dnl.
Definition: SystemDynamicsBase.h:119
const Matrix6d & getM() const
Returns the total mass matrix M = Mrb + Ma.
Definition: SystemDynamicsBase.h:99
const Matrix6d & getDlMatrix() const
Returns the linear damping matrix Dl.
Definition: SystemDynamicsBase.h:114
void setMa(const std::array< double, 6 > &m)
Sets the diagonal added-mass coefficients.
Definition: SystemDynamicsBase.cpp:101
SystemDynamicsBase(const bool is3DOF)
Constructs the dynamics base and sets the DOF flag.
Definition: SystemDynamicsBase.cpp:5
void setRbb(const std::array< double, 3 > &rbb)
Sets the centre-of-buoyancy position in the body frame.
Definition: SystemDynamicsBase.cpp:123
double getMassValue() const
Returns the vehicle mass in kg.
Definition: SystemDynamicsBase.h:144
const Vector3d & getFgn() const
Returns the gravitational force vector in the world frame.
Definition: SystemDynamicsBase.h:134
const bool isSystem3DOF
True if the vehicle is constrained to the XY-Yaw plane (3DOF surface vehicle)
Definition: SystemDynamicsBase.h:80
Matrix6d getC(const Vector6d &velocity) const
Evaluates the total Coriolis matrix C(v) = Crb(v) + Ca(v)
Definition: SystemDynamicsBase.cpp:45
double getWeight() const
Returns the vehicle weight in N.
Definition: SystemDynamicsBase.h:149
const Matrix6d & getMrb() const
Returns the rigid-body mass matrix Mrb.
Definition: SystemDynamicsBase.h:104
void setI(const std::array< double, 6 > &I)
Sets the rigid-body inertia tensor.
Definition: SystemDynamicsBase.cpp:91
Matrix6d getD(const Vector6d &velocity) const
Evaluates the total damping matrix D(v) = Dl + Dnl*diag(|v|)
Definition: SystemDynamicsBase.cpp:13
const Vector3d & getFbn() const
Returns the buoyancy force vector in the world frame.
Definition: SystemDynamicsBase.h:139
void setBuoyancy(double factor)
Sets the buoyancy force as a scale factor relative to vehicle weight.
Definition: SystemDynamicsBase.cpp:86
const Matrix6d & getMaMatrix() const
Returns the added-mass matrix Ma.
Definition: SystemDynamicsBase.h:109
Vector6d getG(const Quaterniond &q) const
Evaluates the 6DOF gravitational and buoyancy restoring vector G(q)
Definition: SystemDynamicsBase.cpp:49