-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
state.c
816 lines (735 loc) · 29.7 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
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
/*
* Copyright (C) 2011 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, see
* <http://www.gnu.org/licenses/>.
*/
/**
* @file state.c
* @brief General inteface for the main vehicle states.
*
* This is the more detailed description of this file.
*
* @author Felix Ruess <felix.ruess@gmail.com>
*
*/
#include "state.h"
struct State state;
/*******************************************************************************
* *
* Set and Get functions for the POSITION representations *
* *
******************************************************************************/
/** @addtogroup PosGroup
* @{ */
/************************ Set functions ****************************/
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);
}
//TODO utm in fixedpoint as well?
inline void StateSetPositionUtm_f(struct FloatVect3* utm_pos) {
//TODO utm zone??
VECT3_COPY(state.utm_pos_f, *utm_pos);
/* clear bits for all position representations and only set the new one */
state.pos_status = (uint8_t)(1 << POS_UTM_F);
}
inline void StateSetPositionEcef_f(struct EcefCoor_f* ecef_pos) {
VECT3_COPY(state.ecef_pos_f, *ecef_pos);
/* clear bits for all position representations and only set the new one */
state.pos_status = (1 << POS_ECEF_F);
}
inline void StateSetPositionNed_f(struct NedCoor_f* ned_pos) {
VECT3_COPY(state.ned_pos_f, *ned_pos);
/* clear bits for all position representations and only set the new one */
state.pos_status = (1 << POS_NED_F);
}
inline void StateSetPositionLla_f(struct LlaCoor_f* lla_pos) {
LLA_COPY(state.lla_pos_f, *lla_pos);
/* clear bits for all position representations and only set the new one */
state.pos_status = (1 << POS_LLA_F);
}
/************************ Get functions ****************************/
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_ECEF_F)) {
ECEF_BFP_OF_REAL(state.ecef_pos_i, state.ecef_pos_f);
}
else if (bit_is_set(state.pos_status, POS_NED_I)) {
//TODO check if resolution is good enough
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_NED_F)) {
struct EcefCoor_f _ecef_f1;
ecef_of_ned_point_f(&_ecef_f1, &state.ned_origin_f, &state.ned_pos_f);
ECEF_BFP_OF_REAL(state.ecef_pos_i, _ecef_f1);
}
else if (bit_is_set(state.pos_status, POS_LLA_F)) {
struct EcefCoor_f _ecef_f2;
ecef_of_lla_f(&_ecef_f2, &state.lla_pos_f);
ECEF_BFP_OF_REAL(state.ecef_pos_i, _ecef_f2);
}
else if (bit_is_set(state.pos_status, POS_LLA_I)) {
ecef_of_lla_i(&state.ecef_pos_i, &state.lla_pos_i);
}
else {
/* could not get this representation, set errno */
struct EcefCoor_i _ecef_zero = {0};
return _ecef_zero;
}
/* 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 (state.ned_initialised_i) {
if (bit_is_set(state.pos_status, POS_NED_F)) {
NED_BFP_OF_REAL(state.ned_pos_i, state.ned_pos_f);
}
else if (bit_is_set(state.pos_status, POS_ECEF_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_ECEF_F)) {
struct NedCoor_f _ned_f1;
ned_of_ecef_point_f(&_ned_f1, &state.ned_origin_f, &state.ecef_pos_f);
NED_BFP_OF_REAL(state.ned_pos_i, _ned_f1);
}
else if (bit_is_set(state.pos_status, POS_LLA_F)) {
struct NedCoor_f _ned_f2;
ned_of_lla_point_f(&_ned_f2, &state.ned_origin_f, &state.lla_pos_f);
NED_BFP_OF_REAL(state.ned_pos_i, _ned_f2);
}
else if (bit_is_set(state.pos_status, POS_LLA_I)) {
ned_of_lla_point_i(&state.ned_pos_i, &state.ned_origin_i, &state.lla_pos_i);
}
else {
/* could not get this representation, set errno */
struct NedCoor_i _ned_i = {0};
return _ned_i;
}
} else {
/* ned coordinate system not initialized, set errno */
struct NedCoor_i _ned_zero = {0};
return _ned_zero;
}
/* 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_LLA_F)) {
LLA_BFP_OF_REAL(state.lla_pos_i, state.lla_pos_f);
}
else 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_ECEF_F)) {
struct LlaCoor_f _lla_f;
lla_of_ecef_f(&_lla_f, &state.ecef_pos_f);
LLA_BFP_OF_REAL(state.lla_pos_i, _lla_f);
}
else if (bit_is_set(state.pos_status, POS_NED_I)) {
//TODO
//lla_of_ned_point_i(&state.lla_pos_i, &state.ned_origin_i, &state.ned_pos_i);
}
else if (bit_is_set(state.pos_status, POS_NED_F)) {
//TODO
//lla_of_ned_point_f(&state.lla_pos_f, &state.ned_origin_f, &state.ned_pos_f);
}
else {
/* could not get this representation, set errno */
struct LlaCoor_i _lla_zero = {0};
return _lla_zero;
}
/* set bit to indicate this representation is computed */
SetBit(state.pos_status, POS_LLA_I);
}
return state.lla_pos_i;
}
inline struct EcefCoor_f StateGetPositionEcef_f(void) {
if (!bit_is_set(state.pos_status, POS_ECEF_F)) {
if (bit_is_set(state.pos_status, POS_ECEF_I)) {
ECEF_FLOAT_OF_BFP(state.ecef_pos_f, state.ecef_pos_i);
}
else if (bit_is_set(state.pos_status, POS_NED_F)) {
ecef_of_ned_point_f(&state.ecef_pos_f, &state.ned_origin_f, &state.ned_pos_f);
}
else if (bit_is_set(state.pos_status, POS_NED_I)) {
//TODO check if resolution is good enough
struct EcefCoor_i _ecef_i1;
ecef_of_ned_point_i(&_ecef_i1, &state.ned_origin_i, &state.ned_pos_i);
ECEF_FLOAT_OF_BFP(state.ecef_pos_f, _ecef_i1);
}
else if (bit_is_set(state.pos_status, POS_LLA_F)) {
ecef_of_lla_f(&state.ecef_pos_f, &state.lla_pos_f);
}
else if (bit_is_set(state.pos_status, POS_LLA_I)) {
struct EcefCoor_i _ecef_i2;
ecef_of_lla_i(&_ecef_i2, &state.lla_pos_i);
ECEF_FLOAT_OF_BFP(state.ecef_pos_f, _ecef_i2);
}
else {
/* could not get this representation, set errno */
struct EcefCoor_f _ecef_zero = {0.0f};
return _ecef_zero;
}
/* set bit to indicate this representation is computed */
SetBit(state.pos_status, POS_ECEF_F);
}
return state.ecef_pos_f;
}
inline struct NedCoor_f StateGetPositionNed_f(void) {
if (!bit_is_set(state.pos_status, POS_NED_F)) {
if (state.ned_initialised_f) {
if (bit_is_set(state.pos_status, POS_NED_I)) {
NED_FLOAT_OF_BFP(state.ned_pos_f, state.ned_pos_i);
}
else if (bit_is_set(state.pos_status, POS_ECEF_F)) {
ned_of_ecef_point_f(&state.ned_pos_f, &state.ned_origin_f, &state.ecef_pos_f);
}
else if (bit_is_set(state.pos_status, POS_ECEF_I)) {
struct NedCoor_i _ned_i1;
ned_of_ecef_point_i(&_ned_i1, &state.ned_origin_i, &state.ecef_pos_i);
NED_FLOAT_OF_BFP(state.ned_pos_f, _ned_i1);
}
else if (bit_is_set(state.pos_status, POS_LLA_F)) {
ned_of_lla_point_f(&state.ned_pos_f, &state.ned_origin_f, &state.lla_pos_f);
}
else if (bit_is_set(state.pos_status, POS_LLA_I)) {
struct NedCoor_i _ned_i2;
ned_of_lla_point_i(&_ned_i2, &state.ned_origin_i, &state.lla_pos_i);
NED_FLOAT_OF_BFP(state.ned_pos_f, _ned_i2);
}
else {
/* could not get this representation, set errno */
struct NedCoor_f _ned_f = {0.0f};
return _ned_f;
}
} else {
/* ned coordinate system not initialized, set errno */
struct NedCoor_f _ned_zero = {0.0f};
return _ned_zero;
}
/* set bit to indicate this representation is computed */
SetBit(state.pos_status, POS_NED_F);
}
return state.ned_pos_f;
}
inline struct LlaCoor_f StateGetPositionLla_f(void) {
if (!bit_is_set(state.pos_status, POS_LLA_F)) {
if (bit_is_set(state.pos_status, POS_LLA_I)) {
LLA_FLOAT_OF_BFP(state.lla_pos_f, state.lla_pos_f);
}
else if (bit_is_set(state.pos_status, POS_ECEF_F)) {
lla_of_ecef_f(&state.lla_pos_f, &state.ecef_pos_f);
}
else if (bit_is_set(state.pos_status, POS_ECEF_I)) {
struct LlaCoor_i _lla_i;
lla_of_ecef_i(&_lla_i, &state.ecef_pos_i);
LLA_FLOAT_OF_BFP(state.lla_pos_f, _lla_i);
}
else if (bit_is_set(state.pos_status, POS_NED_F)) {
//TODO
//lla_of_ned_point_f(&state.lla_pos_f, &state.ned_origin_f, &state.ned_pos_f);
}
else if (bit_is_set(state.pos_status, POS_NED_I)) {
//TODO
struct LlaCoor_i _lla_i2;
//lla_of_ned_point_i(&_lla_i2, &state.ned_origin_i, &state.ned_pos_i);
LLA_FLOAT_OF_BFP(state.lla_pos_f, _lla_i2);
}
else {
/* could not get this representation, set errno */
struct LlaCoor_f _lla_zero = {0.0};
return _lla_zero;
}
/* set bit to indicate this representation is computed */
SetBit(state.pos_status, POS_LLA_F);
}
return state.lla_pos_f;
}
/** @}*/
/******************************************************************************
* *
* Set and Get functions for the SPEED representations *
* *
*****************************************************************************/
/** @addtogroup SpeedGroup
* @{ */
/************************ Set functions ****************************/
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 StateSetSpeedEcef_i(struct EcefCoor_i* ecef_speed) {
INT32_VECT3_COPY(state.ecef_speed_i, *ecef_speed);
/* clear bits for all speed representations and only set the new one */
state.speed_status = (1 << SPEED_ECEF_I);
}
inline void StateSetSpeedNed_f(struct NedCoor_f* ned_speed) {
VECT3_COPY(state.ned_speed_f, *ned_speed);
/* clear bits for all speed representations and only set the new one */
state.speed_status = (1 << SPEED_NED_F);
}
inline void StateSetSpeedEcef_f(struct EcefCoor_f* ecef_speed) {
VECT3_COPY(state.ecef_speed_f, *ecef_speed);
/* clear bits for all speed representations and only set the new one */
state.speed_status = (1 << SPEED_ECEF_F);
}
/************************ Get functions ****************************/
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 EcefCoor_i StateGetSpeedEcef_i(void) {
if (!bit_is_set(state.speed_status, SPEED_ECEF_I)) {
if (bit_is_set(state.speed_status, SPEED_NED_I)) {
if (state.ned_initialised_i) {
//ecef_of_ned_vect_i(&state.ecef_speed_i, &state.ned_origin_i, &state.ned_speed_i);
}
} else {
//try floats....
}
/* set bit to indicate this representation is computed */
SetBit(state.speed_status, SPEED_ECEF_I);
}
return state.ecef_speed_i;
}
inline int32_t StateGetHorizontalSpeedNorm_i(void) {
if (!bit_is_set(state.speed_status, SPEED_HNORM_I)) {
if (bit_is_set(state.speed_status, SPEED_HNORM_F)){
state.h_speed_norm_i = SPEED_BFP_OF_REAL(state.h_speed_norm_f);
} else if (bit_is_set(state.speed_status, SPEED_NED_I)) {
//INT32_VECT2_NORM(state.h_speed_norm_i, state.ned_speed_i); //consider INT32_SPEED_FRAC
}
/* set bit to indicate this representation is computed */
SetBit(state.speed_status, SPEED_HNORM_I);
}
return state.h_speed_norm_i;
}
inline int32_t StateGetHorizontalSpeedDir_i(void) {
if (!bit_is_set(state.speed_status, SPEED_HDIR_I)) {
if (bit_is_set(state.speed_status, SPEED_HDIR_F)){
state.h_speed_dir_i = SPEED_BFP_OF_REAL(state.h_speed_dir_f);
} else if (bit_is_set(state.speed_status, SPEED_NED_I)) {
//foo
}
/* set bit to indicate this representation is computed */
SetBit(state.speed_status, SPEED_HDIR_I);
}
return state.h_speed_dir_i;
}
inline struct NedCoor_f StateGetSpeedNed_f(void) {
if (!bit_is_set(state.speed_status, SPEED_NED_F)) {
if (bit_is_set(state.speed_status, SPEED_ECEF_F)) {
if (state.ned_initialised_f) {
ned_of_ecef_vect_f(&state.ned_speed_f, &state.ned_origin_f, &state.ecef_speed_f);
}
} else {
//try ints....
}
/* set bit to indicate this representation is computed */
SetBit(state.speed_status, SPEED_NED_F);
}
return state.ned_speed_f;
}
inline struct EcefCoor_f StateGetSpeedEcef_f(void) {
if (!bit_is_set(state.speed_status, SPEED_ECEF_F)) {
if (bit_is_set(state.speed_status, SPEED_NED_F)) {
//ecef_of_ned_vect_f(&state.ecef_speed_f, &state.ned_origin_f, &state.ned_speed_f);
} else {
//try floats....
}
/* set bit to indicate this representation is computed */
SetBit(state.speed_status, SPEED_ECEF_F);
}
return state.ecef_speed_f;
}
inline float StateGetHorizontalSpeedNorm_f(void) {
if (!bit_is_set(state.speed_status, SPEED_HNORM_F)) {
if (bit_is_set(state.speed_status, SPEED_HNORM_I)){
state.h_speed_norm_f = SPEED_FLOAT_OF_BFP(state.h_speed_norm_i);
} else if (bit_is_set(state.speed_status, SPEED_NED_F)) {
FLOAT_VECT2_NORM(state.h_speed_norm_f, state.ned_speed_f);
}
/* set bit to indicate this representation is computed */
SetBit(state.speed_status, SPEED_HNORM_F);
}
return state.h_speed_norm_f;
}
inline float StateGetHorizontalSpeedDir_f(void) {
if (!bit_is_set(state.speed_status, SPEED_HDIR_F)) {
if (bit_is_set(state.speed_status, SPEED_HDIR_I)){
state.h_speed_dir_f = SPEED_FLOAT_OF_BFP(state.h_speed_dir_i);
} else if (bit_is_set(state.speed_status, SPEED_NED_F)) {
//foo
}
/* set bit to indicate this representation is computed */
SetBit(state.speed_status, SPEED_HDIR_F);
}
return state.h_speed_dir_f;
}
/** @}*/
/******************************************************************************
* *
* Set and Get functions for the ACCELERATION representations *
* *
*****************************************************************************/
/** @addtogroup AccelGroup
* @{ */
/************************ Set functions ****************************/
inline void StateSetAccelNed_i(struct NedCoor_i* ned_accel) {
INT32_VECT3_COPY(state.ned_accel_i, *ned_accel);
/* clear bits for all accel representations and only set the new one */
state.accel_status = (1 << ACCEL_NED_I);
}
inline void StateSetAccelEcef_i(struct EcefCoor_i* ecef_accel) {
INT32_VECT3_COPY(state.ecef_accel_i, *ecef_accel);
/* clear bits for all accel representations and only set the new one */
state.accel_status = (1 << ACCEL_ECEF_I);
}
inline void StateSetAccelNed_f(struct NedCoor_f* ned_accel) {
VECT3_COPY(state.ned_accel_f, *ned_accel);
/* clear bits for all accel representations and only set the new one */
state.accel_status = (1 << ACCEL_NED_F);
}
inline void StateSetAccelEcef_f(struct EcefCoor_f* ecef_accel) {
VECT3_COPY(state.ecef_accel_f, *ecef_accel);
/* clear bits for all accel representations and only set the new one */
state.accel_status = (1 << ACCEL_ECEF_F);
}
/************************ Get functions ****************************/
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 EcefCoor_i StateGetAccelEcef_i(void) {
if (!bit_is_set(state.accel_status, ACCEL_ECEF_I)) {
if (bit_is_set(state.accel_status, ACCEL_NED_I)) {
if (state.ned_initialised_i) {
//ecef_of_ned_vect_i(&state.ecef_accel_i, &state.ned_origin_i, &state.ned_accel_i);
}
} else {
//try floats....
}
/* set bit to indicate this representation is computed */
SetBit(state.accel_status, ACCEL_ECEF_I);
}
return state.ecef_accel_i;
}
inline struct NedCoor_f StateGetAccelNed_f(void) {
if (!bit_is_set(state.accel_status, ACCEL_NED_F)) {
if (bit_is_set(state.accel_status, ACCEL_ECEF_F)) {
if (state.ned_initialised_f) {
ned_of_ecef_vect_f(&state.ned_accel_f, &state.ned_origin_f, &state.ecef_accel_f);
}
} else {
//try ints....
}
/* set bit to indicate this representation is computed */
SetBit(state.accel_status, ACCEL_NED_F);
}
return state.ned_accel_f;
}
inline struct EcefCoor_f StateGetAccelEcef_f(void) {
if (!bit_is_set(state.accel_status, ACCEL_ECEF_F)) {
if (bit_is_set(state.accel_status, ACCEL_NED_F)) {
//ecef_of_ned_vect_f(&state.ecef_accel_f, &state.ned_origin_f, &state.ned_accel_f);
} else {
//try ints....
}
/* set bit to indicate this representation is computed */
SetBit(state.accel_status, ACCEL_ECEF_F);
}
return state.ecef_accel_f;
}
/** @}*/
/******************************************************************************
* *
* Set and Get functions for the ATTITUDE representations *
* *
*****************************************************************************/
/** @addtogroup AttGroup
* @{ */
/************************ Set functions ****************************/
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 StateSetNedToBodyQuat_f(struct FloatQuat* ned_to_body_quat) {
QUAT_COPY(state.ned_to_body_quat_f, *ned_to_body_quat);
/* clear bits for all attitude representations and only set the new one */
state.att_status = (1 << ATT_QUAT_F);
}
inline void StateSetNedToBodyRMat_f(struct FloatRMat* ned_to_body_rmat) {
RMAT_COPY(state.ned_to_body_rmat_f, *ned_to_body_rmat);
/* clear bits for all attitude representations and only set the new one */
state.att_status = (1 << ATT_RMAT_F);
}
inline void StateSetNedToBodyEulers_f(struct FloatEulers* ned_to_body_eulers) {
EULERS_COPY(state.ned_to_body_eulers_f, *ned_to_body_eulers);
/* clear bits for all attitude representations and only set the new one */
state.att_status = (1 << ATT_EULER_F);
}
/************************ Get functions ****************************/
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 FloatQuat StateGetNedToBodyQuat_f(void) {
if (!bit_is_set(state.att_status, ATT_QUAT_F)) {
if (bit_is_set(state.att_status, ATT_RMAT_F)) {
FLOAT_QUAT_OF_RMAT(state.ned_to_body_quat_f, state.ned_to_body_rmat_f);
} else if (bit_is_set(state.att_status, ATT_EULER_F)) {
FLOAT_QUAT_OF_EULERS(state.ned_to_body_quat_f, state.ned_to_body_eulers_f);
} else {
//try ints....
}
/* set bit to indicate this representation is computed */
SetBit(state.att_status, ATT_QUAT_F);
}
return state.ned_to_body_quat_f;
}
inline struct FloatRMat StateGetNedToBodyRMat_f(void) {
if (!bit_is_set(state.att_status, ATT_RMAT_F)) {
if (bit_is_set(state.att_status, ATT_QUAT_F)) {
FLOAT_RMAT_OF_QUAT(state.ned_to_body_rmat_f, state.ned_to_body_quat_f);
} else if (bit_is_set(state.att_status, ATT_EULER_F)) {
FLOAT_RMAT_OF_EULERS(state.ned_to_body_rmat_f, state.ned_to_body_eulers_f);
} else {
//try floats....
}
/* set bit to indicate this representation is computed */
SetBit(state.att_status, ATT_RMAT_F);
}
return state.ned_to_body_rmat_f;
}
inline struct FloatEulers StateGetNedToBodyEulers_f(void) {
if (!bit_is_set(state.att_status, ATT_EULER_F)) {
if (bit_is_set(state.att_status, ATT_QUAT_F)) {
FLOAT_EULERS_OF_QUAT(state.ned_to_body_eulers_f, state.ned_to_body_quat_f);
} else if (bit_is_set(state.att_status, ATT_RMAT_F)) {
FLOAT_EULERS_OF_RMAT(state.ned_to_body_eulers_f, state.ned_to_body_rmat_f);
} else {
//try floats....
}
/* set bit to indicate this representation is computed */
SetBit(state.att_status, ATT_EULER_F);
}
return state.ned_to_body_eulers_f;
}
/** @}*/
/******************************************************************************
* *
* Set and Get functions for the ANGULAR RATE representations *
* *
*****************************************************************************/
/** @addtogroup RateGroup
* @{ */
/************************ Set functions ****************************/
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);
}
inline void StateSetBodyRates_f(struct FloatRates* body_rate) {
RATES_COPY(state.body_rates_f, *body_rate);
/* clear bits for all attitude representations and only set the new one */
state.rate_status = (1 << RATE_F);
}
/************************ Get functions ****************************/
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_BFP_OF_REAL(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;
}
inline struct FloatRates StateGetBodyRates_f(void) {
if (!bit_is_set(state.rate_status, RATE_F)) {
if (bit_is_set(state.rate_status, RATE_I)) {
RATES_FLOAT_OF_BFP(state.body_rates_f, state.body_rates_i);
}
/* set bit to indicate this representation is computed */
SetBit(state.rate_status, RATE_F);
}
return state.body_rates_f;
}
/** @}*/
/******************************************************************************
* *
* Set and Get functions for the WIND- AND AIRSPEED representations *
* *
*****************************************************************************/
/** @addtogroup WindAirGroup
* @{ */
/************************ Set functions ****************************/
inline void StateSetHorizontalWindspeed_i(struct Int32Vect2* h_windspeed) {
VECT2_COPY(state.h_windspeed_i, *h_windspeed);
/* clear bits for all windspeed representations and only set the new one */
ClearBit(state.wind_air_status, WINDSPEED_F);
SetBit(state.wind_air_status, WINDSPEED_I);
}
inline void StateSetAirspeed_i(int32_t* airspeed) {
state.airspeed_i = *airspeed;
/* clear bits for all windspeed representations and only set the new one */
ClearBit(state.wind_air_status, AIRSPEED_F);
SetBit(state.wind_air_status, AIRSPEED_I);
}
inline void StateSetHorizontalWindspeed_f(struct FloatVect2* h_windspeed) {
VECT2_COPY(state.h_windspeed_f, *h_windspeed);
/* clear bits for all windspeed representations and only set the new one */
ClearBit(state.wind_air_status, WINDSPEED_I);
SetBit(state.wind_air_status, WINDSPEED_F);
}
inline void StateSetAirspeed_f(float* airspeed) {
state.airspeed_f = *airspeed;
/* clear bits for all windspeed representations and only set the new one */
ClearBit(state.wind_air_status, AIRSPEED_I);
SetBit(state.wind_air_status, AIRSPEED_F);
}
/************************ Get functions ****************************/
inline struct Int32Vect2 StateGetHorizontalWindspeed_i(void) {
if (!bit_is_set(state.wind_air_status, WINDSPEED_I)) {
if (bit_is_set(state.wind_air_status, WINDSPEED_F)) {
state.h_windspeed_i.x = SPEED_BFP_OF_REAL(state.h_windspeed_f.x);
state.h_windspeed_i.y = SPEED_BFP_OF_REAL(state.h_windspeed_f.y);
}
/* set bit to indicate this representation is computed */
SetBit(state.rate_status, WINDSPEED_I);
}
return state.h_windspeed_i;
}
inline int32_t StateGetAirspeed_i(void) {
if (!bit_is_set(state.wind_air_status, AIRSPEED_I)) {
if (bit_is_set(state.wind_air_status, AIRSPEED_F)) {
state.airspeed_i = SPEED_BFP_OF_REAL(state.airspeed_f);
}
/* set bit to indicate this representation is computed */
SetBit(state.wind_air_status, AIRSPEED_I);
}
return state.airspeed_i;
}
inline struct FloatVect2 StateGetHorizontalWindspeed_f(void) {
if (!bit_is_set(state.wind_air_status, WINDSPEED_F)) {
if (bit_is_set(state.wind_air_status, WINDSPEED_I)) {
state.h_windspeed_f.x = SPEED_FLOAT_OF_BFP(state.h_windspeed_i.x);
state.h_windspeed_f.x = SPEED_FLOAT_OF_BFP(state.h_windspeed_i.y);
}
/* set bit to indicate this representation is computed */
SetBit(state.rate_status, WINDSPEED_F);
}
return state.h_windspeed_f;
}
inline float StateGetAirspeed_f(void) {
if (!bit_is_set(state.wind_air_status, AIRSPEED_F)) {
if (bit_is_set(state.wind_air_status, AIRSPEED_I)) {
state.airspeed_f = SPEED_FLOAT_OF_BFP(state.airspeed_i);
}
/* set bit to indicate this representation is computed */
SetBit(state.wind_air_status, AIRSPEED_F);
}
return state.airspeed_f;
}
/** @}*/