-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathState.h
87 lines (74 loc) · 2.94 KB
/
State.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*******************************************************************
* State.h
* KPS
*
* Author: Kareem Omar
* kareem.omar@uah.edu
* https://github.com/komrad36
*
* Last updated Feb 27, 2016
* This application is entirely my own work.
*******************************************************************/
//
// Dual representation of a satellite state as:
// a) a Plain Old Data vector of 13 doubles,
// i.e. an Eigen Array or Matrix type with dimensions
// 13 by 1, as needed by the numerical integrators, which
// do not care about the meaning of the different
// parts of the vector and integrate it all in one go
// b) an organized Plain Old Data struct consisting of
// the satellite's position, velocity, orientation,
// and angular velocity, represented by glm vectors
// and a glm quaternion (for the orientation)
//
// The ability to reinterpret the same struct without copying
// is crucial to the speed of the application. Parts of the
// 13-vector, such as the velocity, say, can be rapidly treated as
// individual 3-vectors for manipulation by the ODE, printing, etc.,
// yet when Eigen needs to consider the whole vector for integration,
// it can do so with no overhead.
//
#pragma once
#include <algorithm>
#include "glm_util.h"
#include "Eigen_util.h"
// Eigen requires 16-byte alignment for SSE. Because this
// struct will be reinterpreted as an Eigen Array, it, too,
// must align itself along 16-byte boundaries.
//
// NOTE: due to this pack request the actual State struct will
// end up 14 doubles long, not 13. This is okay. The padding is at
// the end and does not interfere with anything in conversion.
struct alignas(16) State {
// Position in ECI frame [m]
vec3 r;
// Velocity in ECI frame [m/s]
vec3 v;
// Orientation
// NOTE: this quaternion turns the ECI frame axes into the Body frame axes,
// i.e. rotates a VECTOR from the Body frame into the ECI frame.
// See the KPS research paper for more.
quat q;
// Angular velocity of the satellite about the body axes [rad/s]
// i.e. angular velocity of Body frame relative to ECI frame,
// coordinatized in the body frame
vec3 w;
State() {}
State(const vec3& state_r, const vec3& state_v, const quat& state_q, const vec3& state_w) : r(state_r), v(state_v), q(state_q), w(state_w) {}
};
// Interpret a const Eigen 13-vector as a const State struct
inline const State& e_to_s(const dEvec13& e_state) {
return reinterpret_cast<const State&>(e_state);
}
// Interpret an Eigen 13-vector as a State struct
inline State& e_to_s(dEvec13& e_state) {
return reinterpret_cast<State&>(e_state);
}
// Interpret a const State struct as a const Eigen 13-vector
inline const dEvec13& s_to_e(const State& s_state) {
return reinterpret_cast<const dEvec13&>(s_state);
}
// Interpret a State struct as an Eigen 13-vector
inline dEvec13& s_to_e(State& s_state) {
return reinterpret_cast<dEvec13&>(s_state);
}