-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsatellite_cpp.h
280 lines (276 loc) · 10.4 KB
/
satellite_cpp.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#include<iostream>
#include<math.h>
#include "frames_cpp.h"
using namespace std;
class Satellite
{
float v_state[7];
float time;
float v_pos_i[3], v_vel_i[3];
quat v_q_BI, v_q_BO;
float v_w_BO_b[3], v_w_BI_b[3], v_dist_b[3], v_solar_dist_b[3], v_aero_dist_b[3], v_gg_dist_b[3], v_control_b[3], v_sun_i[3], v_sun_o[3], v_mag_o[3], v_mag_i[3], v_sun_b_m[3], mag_b_m_c[3], mag_b_m_p[3];
quat quatEstimate;
float v_w_BO_b_m[3];
int light;
float v_req_Magmoment_b[3], v_app_torque_b[3];
float gpsData[7], J2Data[7];
float GyroVarBias[3];
public: Satellite(float v_state0[7], float time0)
{
setTime(time0);
setState(v_state0);
}
void setState(float v_state1[7]) // set state
{
for(int i = 0; i<7; i++)
v_state[i] = v_state1[i];
}
float* getState() // return state
{
return v_state;
}
void setPos(float v_pos[3]) // set position in eci (earth centered inertial frame)
{
for(int i = 0; i<3; i++)
v_pos_i[i] = v_pos[i];
}
float* getPos() // return position in eci
{
return v_pos_i;
}
void setVel(float v_vel[3]) // set velocity in eci
{
for(int i = 0; i<3; i++)
v_vel_i[i] = v_vel[i];
}
float* getVel() // return velocity in eci
{
return v_vel_i;
}
void setQ_B0(quat v_w) // set error quaternion
{
for(int i = 0; i<4; i++)
v_state[i] = v_w.arr[i];
}
quat getQ_B0() // return error quaternion
{
float dummy[4];
for(int i = 0; i<4; i++)
dummy[i] = v_state[i];
quat a = quat(dummy);
return a;
}
quat getQ_BI() // get exact quaternion from inertial frame to body frame
{
float dummy[4];
for(int i = 0; i<4; i++)
dummy[i] = v_state[i];
quat v_q_B = quat(dummy);
quat v_q_BI = qBO2qBI(v_q_B, v_pos_i, v_vel_i);
return v_q_BI;
}
void setW_B0_b(float v_w[3]) // set angular velocity of Body frame wrt orbit frame in body frame
{
for(int i = 4; i<7; i++)
v_state[i] = v_w[i-4];
}
float* getW_B0_b() // return angular velocity of Body frame wrt orbit frame in body frame
{
static float a[3];
for(int i = 4; i<7; i++)
a[i-4] = v_state[i];
return a;
}
float* getW_BI_b() // return exact angular velocity of body frame with respect to inertial frame expressed in body frame
{
float v_w_BO_b[3];
for(int i = 4; i<7; i++)
v_w_BO_b[i-4] = v_state[i];
quat v_q_BO;
for(int i = 0; i<4; i++)
v_q_BO.arr[i] = v_state[i];
static float v_w_BI_b[3];
for(int i = 0; i<3; i++)
v_w_BI_b[i] = (wBOb2wBIb(v_w_BO_b,v_q_BO,v_w_IO_o))[i];
return v_w_BI_b;
}
void setTime(float y) // set time
{
time = y;
}
float getTime() // return time
{
return time;
}
void setDisturbance_b(float v_torque_dist_b[3]) // set disturbance in body (about center of mass)
{
for(int i = 0; i<3; i++)
v_dist_b[i] = v_torque_dist_b[i];
}
float* getDisturbance_b() // return disturbance in body
{
return v_dist_b;
}
void setsolarDisturbance_b(float v_solar_torque_dist_b[3])
{
for(int i = 0; i<3; i++)
v_solar_dist_b[i] = v_solar_torque_dist_b[i];
}
float* getsolarDisturbance_b()
{
return v_solar_dist_b;
}
void setaeroDisturbance_b(float v_aero_torque_dist_b[3])
{
for(int i = 0; i<3; i++)
v_aero_dist_b[i] = v_aero_torque_dist_b[i];
}
float* getaeroDisturbance_b()
{
return v_aero_dist_b;
}
void setggDisturbance_b(float v_gg_torque_dist_b[3])
{
for(int i = 0; i<3; i++)
v_gg_dist_b[i] = v_gg_torque_dist_b[i];
}
float* getggDisturbance_b()
{
return v_gg_dist_b;
}
void setControl_b(float v_control[3]) // set control torque in body
{
for(int i = 0; i<3; i++)
v_control_b[i] = v_control[i];
}
float* getControl_b() // return control torque in body
{
return v_control_b;
}
void setSun_i(float v_sv_i[3]) // set sun vector in eci
{
for(int i = 0; i<3; i++)
v_sun_i[i] = v_sv_i[i];
}
float* getSun_i() // return sun vector in eci
{
return v_sun_i;
}
float* getSun_o() // return sun vector in orbit
{
v_sun_o = ecif2orbit(v_pos_i, v_vel_i, v_sun_i);
return v_sun_o;
}
void setMag_i(float v_mg_i[3]) // set mag in eci
{
for(int i = 0; i<3; i++)
v_mag_i[i] = v_mg_i[i];
}
float* getMag_i() // return mag in eci
{
return v_mag_i;
}
float* getMag_o() // return mag in orbit
{
v_mag_o = ecif2orbit(v_pos_i, v_vel_i, v_mag_i);
return v_mag_o;
}
void setSun_b_m(float v_sv_b_m[3]) // set sunsensor measurement in body
{
for(int i = 0; i<3; i++)
v_sun_b_m[i] = v_sv_b_m[i];
}
float* getSun_b_m() // return sunsensor measurement in body
{
return v_sun_b_m;
}
void setMag_b_m_c(float v_mag_b_m[3]) // set current mag measurement in body
{
for(int i = 0; i<3; i++)
mag_b_m_c[i] = v_mag_b_m[i];
}
float* getMag_b_m_c() // return mag measurement in body
{
return mag_b_m_c;
}
void setMag_b_m_p(float v_mag_b_m[3]) // set previous mag measurement in body
{
for(int i = 0; i<3; i++)
mag_b_m_p[i] = v_mag_b_m[i];
}
float* getMag_b_m_p() // return mag measurement in body
{
return mag_b_m_p;
}
void setQUEST(quat v_q_BO_m) // set quest quaternion
{
for(int i = 0; i<4; i++)
quatEstimate.arr[i] = v_q_BO_m.arr[i];
}
quat getQUEST() // return quest quaternion
{
return quatEstimate;
}
void setOmega_m(float omega_m[3])
{
for(int i = 0; i<3; i++)
v_w_BO_b_m[i] = omega_m[i];
}
float* getOmega_m()
{
return v_w_BO_b_m;
}
void setLight(int flag)
{
light = flag;
}
int getLight()
{
return light;
}
void setMagmomentRequired_b(float v_rq_Magmoment_b[3]) // set applied torque
{
for(int i = 0; i<3; i++)
v_req_Magmoment_b[i] = v_rq_Magmoment_b[i];
}
float* getMagmomentRequired_b() // get applied torque
{
return v_req_Magmoment_b;
}
void setAppTorque_b(float v_app_torque[3]) // set applied torque
{
for(int i = 0; i<3; i++)
v_app_torque_b[i] = v_app_torque[i];
}
float* getAppTorque_b() // get applied torque
{
return v_app_torque_b;
}
void setgpsData(float gpsdata[7]) // gpsdata is an array of 7 elements containing v_pos_m,v_vel_m,time_m in sequence
{
for(int i = 0; i<7; i++)
gpsData[i] = gpsdata[i];
}
float* getgpsData() // get gpsData
{
return gpsData;
}
void setJ2Data(float J2data[7]) // J2data is an array of 7 elements containing v_pos_m,v_vel_m,time_m in sequence
{
for(int i = 0; i<7; i++)
J2Data[i] = J2data[i];
}
float* getJ2Data() // get J2Data
{
return J2Data;
}
void setGyroVarBias(float v_gyro_bias[3]) // set bias of gyroscope
{
for(int i = 0; i<3; i++)
GyroVarBias[i] = v_gyro_bias[i];
}
float* getGyroVarBias() // get bias of gyroscope
{
return GyroVarBias;
}
};