-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
state.c
230 lines (206 loc) · 7.82 KB
/
state.c
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
/*
* Copyright (C) 2010 The Paparazzi Team
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/** \file state.c
* \brief general inteface for the main vehicle states
*/
#include "state.h"
struct State state;
/*
* Set State functions (int versions)
*/
inline void StateSetPositionEcef_i(struct EcefCoor_i* ecef_pos) {
INT32_VECT3_COPY(state.ecef_pos_i, *ecef_pos);
/* clear bits for all position representations and only set the new one */
state.pos_status = (1 << POS_ECEF_I);
}
inline void StateSetPositionNed_i(struct NedCoor_i* ned_pos) {
INT32_VECT3_COPY(state.ned_pos_i, *ned_pos);
/* clear bits for all position representations and only set the new one */
state.pos_status = (1 << POS_NED_I);
}
inline void StateSetPositionLla_i(struct LlaCoor_i* lla_pos) {
LLA_COPY(state.lla_pos_i, *lla_pos);
/* clear bits for all position representations and only set the new one */
state.pos_status = (1 << POS_LLA_I);
}
inline void StateSetSpeedNed_i(struct NedCoor_i* ned_speed) {
INT32_VECT3_COPY(state.ned_speed_i, *ned_speed);
/* clear bits for all speed representations and only set the new one */
state.speed_status = (1 << SPEED_NED_I);
}
inline void StateSetAccelNed_i(struct NedCoor_i* ned_accel) {
INT32_VECT3_COPY(state.ned_accel_i, *ned_accel);
/* clear bits for all speed representations and only set the new one */
state.accel_status = (1 << ACCEL_NED_I);
}
inline void StateSetNedToBodyQuat_i(struct Int32Quat* ned_to_body_quat) {
QUAT_COPY(state.ned_to_body_quat_i, *ned_to_body_quat);
/* clear bits for all attitude representations and only set the new one */
state.att_status = (1 << ATT_QUAT_I);
}
inline void StateSetNedToBodyRMat_i(struct Int32RMat* ned_to_body_rmat) {
RMAT_COPY(state.ned_to_body_rmat_i, *ned_to_body_rmat);
/* clear bits for all attitude representations and only set the new one */
state.att_status = (1 << ATT_RMAT_I);
}
inline void StateSetNedToBodyEulers_i(struct Int32Eulers* ned_to_body_eulers){
EULERS_COPY(state.ned_to_body_eulers_i, *ned_to_body_eulers);
/* clear bits for all attitude representations and only set the new one */
state.att_status = (1 << ATT_EULER_I);
}
inline void StateSetBodyRates_i(struct Int32Rates* body_rate){
RATES_COPY(state.body_rates_i, *body_rate);
/* clear bits for all attitude representations and only set the new one */
state.rate_status = (1 << RATE_I);
}
/*
* Get State functions (int versions)
*/
inline struct EcefCoor_i StateGetPositionEcef_i(void) {
if (!bit_is_set(state.pos_status, POS_ECEF_I)) {
if (bit_is_set(state.pos_status, POS_NED_I)) {
if (state.ned_initialised_i) {
//ecef_of_ned_point_i(&state.ecef_pos_i, &state.ned_origin_i, &state.ned_pos_i);
}
} else if (bit_is_set(state.pos_status, POS_LLA_I)) {
ecef_of_lla_i(&state.ecef_pos_i, &state.lla_pos_i);
} else {
//try floats....
}
/* set bit to indicate this representation is computed */
SetBit(state.pos_status, POS_ECEF_I);
}
return state.ecef_pos_i;
}
inline struct NedCoor_i StateGetPositionNed_i(void) {
if (!bit_is_set(state.pos_status, POS_NED_I)) {
if (bit_is_set(state.pos_status, POS_ECEF_I)) {
if (state.ned_initialised_i) {
ned_of_ecef_point_i(&state.ned_pos_i, &state.ned_origin_i, &state.ecef_pos_i);
}
} else if (bit_is_set(state.pos_status, POS_LLA_I)) {
if (state.ned_initialised_i) {
ned_of_lla_point_i(&state.ned_pos_i, &state.ned_origin_i, &state.lla_pos_i);
}
} else {
//try floats....
}
/* set bit to indicate this representation is computed */
SetBit(state.pos_status, POS_NED_I);
}
return state.ned_pos_i;
}
inline struct LlaCoor_i StateGetPositionLla_i(void) {
if (!bit_is_set(state.pos_status, POS_LLA_I)) {
if (bit_is_set(state.pos_status, POS_ECEF_I)) {
lla_of_ecef_i(&state.lla_pos_i, &state.ecef_pos_i);
} else if (bit_is_set(state.pos_status, POS_NED_I)) {
if (state.ned_initialised_i) {
//lla_of_ned_point_i(&state.lla_pos_i, &state.ned_origin, &state.ned_pos_i);
}
} else {
//try floats....
}
/* set bit to indicate this representation is computed */
SetBit(state.pos_status, POS_LLA_I);
}
return state.lla_pos_i;
}
inline struct NedCoor_i StateGetSpeedNed_i(void) {
if (!bit_is_set(state.speed_status, SPEED_NED_I)) {
if (bit_is_set(state.speed_status, SPEED_ECEF_I)) {
if (state.ned_initialised_i) {
ned_of_ecef_vect_i(&state.ned_speed_i, &state.ned_origin_i, &state.ecef_speed_i);
}
} else {
//try floats....
}
/* set bit to indicate this representation is computed */
SetBit(state.speed_status, SPEED_NED_I);
}
return state.ned_speed_i;
}
inline struct NedCoor_i StateGetAccelNed_i(void) {
if (!bit_is_set(state.accel_status, ACCEL_NED_I)) {
if (bit_is_set(state.accel_status, ACCEL_ECEF_I)) {
if (state.ned_initialised_i) {
ned_of_ecef_vect_i(&state.ned_accel_i, &state.ned_origin_i, &state.ecef_accel_i);
}
} else {
//try floats....
}
/* set bit to indicate this representation is computed */
SetBit(state.accel_status, ACCEL_NED_I);
}
return state.ned_accel_i;
}
inline struct Int32Quat StateGetNedToBodyQuat_i(void) {
if (!bit_is_set(state.att_status, ATT_QUAT_I)) {
if (bit_is_set(state.att_status, ATT_RMAT_I)) {
INT32_QUAT_OF_RMAT(state.ned_to_body_quat_i, state.ned_to_body_rmat_i);
} else if (bit_is_set(state.att_status, ATT_EULER_I)) {
INT32_QUAT_OF_EULERS(state.ned_to_body_quat_i, state.ned_to_body_eulers_i);
} else {
//try floats....
}
/* set bit to indicate this representation is computed */
SetBit(state.att_status, ATT_QUAT_I);
}
return state.ned_to_body_quat_i;
}
inline struct Int32RMat StateGetNedToBodyRMat_i(void) {
if (!bit_is_set(state.att_status, ATT_RMAT_I)) {
if (bit_is_set(state.att_status, ATT_QUAT_I)) {
INT32_RMAT_OF_QUAT(state.ned_to_body_rmat_i, state.ned_to_body_quat_i);
} else if (bit_is_set(state.att_status, ATT_EULER_I)) {
INT32_RMAT_OF_EULERS(state.ned_to_body_rmat_i, state.ned_to_body_eulers_i);
} else {
//try floats....
}
/* set bit to indicate this representation is computed */
SetBit(state.att_status, ATT_RMAT_I);
}
return state.ned_to_body_rmat_i;
}
inline struct Int32Eulers StateGetNedToBodyEulers_i(void) {
if (!bit_is_set(state.att_status, ATT_EULER_I)) {
if (bit_is_set(state.att_status, ATT_QUAT_I)) {
INT32_EULERS_OF_QUAT(state.ned_to_body_eulers_i, state.ned_to_body_quat_i);
} else if (bit_is_set(state.att_status, ATT_RMAT_I)) {
INT32_EULERS_OF_RMAT(state.ned_to_body_eulers_i, state.ned_to_body_rmat_i);
} else {
//try floats....
}
/* set bit to indicate this representation is computed */
SetBit(state.att_status, ATT_EULER_I);
}
return state.ned_to_body_eulers_i;
}
inline struct Int32Rates StateGetBodyRates_i(void) {
if (!bit_is_set(state.rate_status, RATE_I)) {
if (bit_is_set(state.rate_status, RATE_F)) {
RATES_FLOAT_OF_BFP(state.body_rates_i, state.body_rates_f);
}
/* set bit to indicate this representation is computed */
SetBit(state.rate_status, RATE_I);
}
return state.body_rates_i;
}