Debian Codegraph @

src/FDM/YASim/Integrator.hpp

raw symbols SCIP
1 #ifndef _INTEGRATOR_HPP
2 #define _INTEGRATOR_HPP
3
4 #include "BodyEnvironment.hpp"
5 #include "RigidBody.hpp"
6
7 namespace yasim {
8
9 //
10 // These objects are responsible for extracting force data from a
11 // BodyEnvironment object, using a RigidBody object to calculate
12 // accelerations, and then tying that all together into a new
13 // "solution" of position/orientation/etc... for the body. The method
14 // used is a fourth-order Runge-Kutta integration.
15 //
16 class Integrator
17 {
18 public:
19 // Sets the RigidBody that will be integrated.
20 void setBody(RigidBody* body) { _body = body; }
21
22 // Sets the BodyEnvironment object used to calculate the second
23 // derivatives.
24 void setEnvironment(BodyEnvironment* env) { _env = env; }
25
26 // Sets the time interval between steps. Units can be anything,
27 // but they must match the other values (if you specify speed in
28 // m/s, then angular acceleration had better be in 1/s^2 and the
29 // time interval should be in seconds, etc...)
30 void setInterval(float dt) { _dt = dt; }
31 float getInterval() const { return _dt; }
32
33 // The current state, i.e. initial conditions for the next
34 // integration iteration. Note that the acceleration parameters
35 // in the State object are ignored.
36 State* getState() { return &_s; }
37 void setState(State* s) { _s = *s; }
38
39 // Do a 4th order Runge-Kutta integration over one time interval.
40 // This is the top level of the simulation.
41 void calcNewInterval();
42
43 private:
44 void orthonormalize(float* m);
45 void rotMatrix(float* r, float dt, float* out);
46
47 // Transforms a "local" vector to a "global" vector (not coordinate!)
48 // using the specified orientation.
49 void l2gVector(const float* orient, const float* v, float* out) {
50 Math::tmul33(orient, v, out); }
51
52 void extrapolatePosition(double* pos, float* v, float dt, float* o1, float* o2);
53
54 BodyEnvironment* _env;
55 RigidBody* _body;
56 float _dt;
57
58 State _s;
59 };
60
61 }; // namespace yasim
62 #endif // _INTEGRATOR_HPP