Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
state.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2011-2012 Felix Ruess <felix.ruess@gmail.com>
3 *
4 * This file is part of paparazzi.
5 *
6 * paparazzi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * paparazzi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with paparazzi; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
19 */
20
34#include "state.h"
35
36struct State state;
37
38#if PREFLIGHT_CHECKS && !defined(AUTOPILOT_DISABLE_AHRS_KILL)
39/* Preflight checks */
41static struct preflight_check_t state_pfc;
42
43static void state_preflight(struct preflight_result_t *result) {
45 preflight_error(result, "State attitude is invalid");
46 } else {
47 preflight_success(result, "State attitude is valid");
48 }
49}
50#endif // PREFLIGHT_CHECKS
51
57void stateInit(void)
58{
59 state.pos_status = 0;
75
76 /* setting to zero forces recomputation of zone using lla when utm uninitialised*/
78
79 /* Register preflight checks */
80#if PREFLIGHT_CHECKS && !defined(AUTOPILOT_DISABLE_AHRS_KILL)
82#endif
83}
84
86{
87 switch (type) {
90 break;
91 case STATE_INPUT_POS:
93 break;
96 break;
99 break;
102 break;
105 break;
108 break;
109 default:
110 break; // nothing to do, wrong type
111 }
112}
113
114/*******************************************************************************
115 * *
116 * transformation functions for the POSITION representations *
117 * *
118 ******************************************************************************/
125{
126 struct LlaCoor_i lla_i = {0};
128 return state.ned_origin_i.lla;
129 } else if (state.ned_initialized_f) {
131 return lla_i;
132 } else if (state.utm_initialized_f) {
133 struct LlaCoor_f lla_f;
135 LLA_BFP_OF_REAL(lla_i, lla_f);
136 return lla_i;
137 } else {
138 return lla_i;
139 }
140}
141
144{
145 struct LlaCoor_f lla_f = {0};
147 return state.ned_origin_f.lla;
148 } else if (state.ned_initialized_i) {
150 return lla_f;
151 } else if (state.utm_initialized_f) {
153 return lla_f;
154 } else {
155 return lla_f;
156 }
157}
158
161{
162 struct EcefCoor_i ecef_i = {0};
164 return state.ned_origin_i.ecef;
165 } else if (state.ned_initialized_f) {
167 return ecef_i;
168 } else {
169 // UTM case is not supported
170 return ecef_i;
171 }
172}
173
176{
177 struct EcefCoor_f ecef_f = {0};
179 return state.ned_origin_f.ecef;
180 } else if (state.ned_initialized_i) {
182 return ecef_f;
183 } else {
184 // UTM case is not supported
185 return ecef_f;
186 }
187}
188
191{
193 return state.ned_origin_i.hmsl;
194 } else if (state.ned_initialized_f) {
196 } else if (state.utm_initialized_f) {
198 } else {
199 return 0;
200 }
201}
202
205{
207 return state.ned_origin_f.hmsl;
208 } else if (state.ned_initialized_i) {
209 return (float) M_OF_MM(state.ned_origin_i.hmsl);
210 } else if (state.utm_initialized_f) {
211 return state.utm_origin_f.alt;
212 } else {
213 return 0.f;
214 }
215}
216
218{
220 return;
221 }
222
228 /* transform ned_f to ecef_f, set status bit, then convert to int */
232 } else if (bit_is_set(state.pos_status, POS_LLA_I)) {
234 } else if (bit_is_set(state.pos_status, POS_LLA_F)) {
235 /* transform lla_f to ecef_f, set status bit, then convert to int */
239 } else {
240 /* could not get this representation, set errno */
241 //struct EcefCoor_i _ecef_zero = {0};
242 //return _ecef_zero;
243 return;
244 }
245 /* set bit to indicate this representation is computed */
247}
248
250{
252 return;
253 }
254
255 int errno = 0;
259 } else if (bit_is_set(state.pos_status, POS_ENU_I)) {
261 } else if (bit_is_set(state.pos_status, POS_ENU_F)) {
265 } else if (bit_is_set(state.pos_status, POS_ECEF_I)) {
267 } else if (bit_is_set(state.pos_status, POS_ECEF_F)) {
268 /* transform ecef_f -> ned_f, set status bit, then convert to int */
272 } else if (bit_is_set(state.pos_status, POS_LLA_F)) {
273 /* transform lla_f -> ecef_f -> ned_f, set status bits, then convert to int */
279 } else if (bit_is_set(state.pos_status, POS_LLA_I)) {
281 } else { /* could not get this representation, set errno */
282 errno = 1;
283 }
284 } else if (state.utm_initialized_f) {
287 } else if (bit_is_set(state.pos_status, POS_ENU_I)) {
289 } else if (bit_is_set(state.pos_status, POS_ENU_F)) {
293 } else if (bit_is_set(state.pos_status, POS_UTM_F)) {
294 /* transform utm_f -> ned_f -> ned_i, set status bits */
298 } else if (bit_is_set(state.pos_status, POS_LLA_F)) {
299 /* transform lla_f -> utm_f -> ned_f -> ned_i, set status bits */
305 } else if (bit_is_set(state.pos_status, POS_LLA_I)) {
306 /* transform lla_i -> lla_f -> utm_f -> ned_f -> ned_i, set status bits */
314 } else { /* could not get this representation, set errno */
315 errno = 2;
316 }
317 } else { /* ned coordinate system not initialized, set errno */
318 errno = 3;
319 }
320 if (errno) {
321 //struct NedCoor_i _ned_zero = {0};
322 //return _ned_zero;
323 return;
324 }
325 /* set bit to indicate this representation is computed */
327}
328
330{
332 return;
333 }
334
335 int errno = 0;
339 } else if (bit_is_set(state.pos_status, POS_ENU_F)) {
341 } else if (bit_is_set(state.pos_status, POS_NED_F)) {
345 } else if (bit_is_set(state.pos_status, POS_ECEF_I)) {
347 } else if (bit_is_set(state.pos_status, POS_ECEF_F)) {
348 /* transform ecef_f -> enu_f, set status bit, then convert to int */
352 } else if (bit_is_set(state.pos_status, POS_LLA_F)) {
353 /* transform lla_f -> ecef_f -> enu_f, set status bits, then convert to int */
359 } else if (bit_is_set(state.pos_status, POS_LLA_I)) {
361 } else { /* could not get this representation, set errno */
362 errno = 1;
363 }
364 } else if (state.utm_initialized_f) {
367 } else if (bit_is_set(state.pos_status, POS_NED_I)) {
369 } else if (bit_is_set(state.pos_status, POS_NED_F)) {
373 } else if (bit_is_set(state.pos_status, POS_UTM_F)) {
374 /* transform utm_f -> enu_f -> enu_i , set status bits */
378 } else if (bit_is_set(state.pos_status, POS_LLA_F)) {
379 /* transform lla_f -> utm_f -> enu_f -> enu_i , set status bits */
385 } else if (bit_is_set(state.pos_status, POS_LLA_I)) {
386 /* transform lla_i -> lla_f -> utm_f -> enu_f -> enu_i , set status bits */
394 } else { /* could not get this representation, set errno */
395 errno = 2;
396 }
397 } else { /* ned coordinate system not initialized, set errno */
398 errno = 3;
399 }
400 if (errno) {
401 //struct EnuCoor_i _enu_zero = {0};
402 //return _enu_zero;
403 return;
404 }
405 /* set bit to indicate this representation is computed */
407}
408
417{
419 return;
420 }
421
422 int errno = 0;
425 } else if (bit_is_set(state.pos_status, POS_ECEF_F)) {
426 /* transform ecef_f -> ecef_i -> lla_i, set status bits */
430 } else if (bit_is_set(state.pos_status, POS_UTM_F)) {
431 /* transform utm_f -> lla_f -> lla_i, set status bits */
435 } else if (state.ned_initialized_i) {
437 /* transform ned_i -> ecef_i -> lla_i, set status bits */
441 } else if (bit_is_set(state.pos_status, POS_ENU_I)) {
442 /* transform enu_i -> ecef_i -> lla_i, set status bits */
446 } else if (bit_is_set(state.pos_status, POS_NED_F)) {
447 /* transform ned_f -> ned_i -> ecef_i -> lla_i, set status bits */
453 } else if (bit_is_set(state.pos_status, POS_ENU_F)) {
454 /* transform enu_f -> enu_i -> ecef_i -> lla_i, set status bits */
460 } else { /* could not get this representation, set errno */
461 errno = 1;
462 }
463 } else if (state.utm_initialized_f) {
465 /* transform ned_i -> ned_f -> utm_f -> lla_f -> lla_i, set status bits */
473 } else if (bit_is_set(state.pos_status, POS_ENU_I)) {
474 /* transform enu_i -> enu_f -> utm_f -> lla_f -> lla_i, set status bits */
482 } else if (bit_is_set(state.pos_status, POS_NED_F)) {
483 /* transform ned_f -> utm_f -> lla_f -> lla_i, set status bits */
489 } else if (bit_is_set(state.pos_status, POS_ENU_F)) {
490 /* transform enu_f -> utm_f -> lla_f -> lla_i, set status bits */
496 } else { /* could not get this representation, set errno */
497 errno = 2;
498 }
499 } else if (bit_is_set(state.pos_status, POS_LLA_F)) {
501 } else { /* ned coordinate system not initialized, set errno */
502 errno = 3;
503 }
504 if (errno) {
505 /* could not get this representation, set errno */
506 //struct LlaCoor_i _lla_zero = {0};
507 //return _lla_zero;
508 return;
509 }
510 /* set bit to indicate this representation is computed */
512}
513
515{
517 return;
518 }
519
522 } else if (bit_is_set(state.pos_status, POS_LLA_I)) {
523 /* transform lla_i -> lla_f -> utm_f, set status bits */
527 } else if (state.utm_initialized_f) {
530 } else if (bit_is_set(state.pos_status, POS_ENU_I)) {
534 } else if (bit_is_set(state.pos_status, POS_NED_F)) {
536 } else if (bit_is_set(state.pos_status, POS_NED_I)) {
540 }
541 } else {
542 /* could not get this representation, set errno */
543 //struct EcefCoor_f _ecef_zero = {0.0f};
544 //return _ecef_zero;
545 return;
546 }
547 /* set bit to indicate this representation is computed */
549}
550
552{
554 return;
555 }
556
562 /* transform ned_i -> ecef_i -> ecef_f, set status bits */
566 } else if (bit_is_set(state.pos_status, POS_LLA_F)) {
568 } else if (bit_is_set(state.pos_status, POS_LLA_I)) {
572 } else {
573 /* could not get this representation, set errno */
574 //struct EcefCoor_f _ecef_zero = {0.0f};
575 //return _ecef_zero;
576 return;
577 }
578 /* set bit to indicate this representation is computed */
580}
581
583{
585 return;
586 }
587
588 int errno = 0;
592 } else if (bit_is_set(state.pos_status, POS_ECEF_F)) {
594 } else if (bit_is_set(state.pos_status, POS_ECEF_I)) {
595 /* transform ecef_i -> ned_i -> ned_f, set status bits */
599 } else if (bit_is_set(state.pos_status, POS_LLA_F)) {
601 } else if (bit_is_set(state.pos_status, POS_LLA_I)) {
602 /* transform lla_i -> ecef_i -> ned_i -> ned_f, set status bits */
603 ecef_of_lla_i(&state.ecef_pos_i, &state.lla_pos_i); /* converts to doubles internally */
608 } else { /* could not get this representation, set errno */
609 errno = 1;
610 }
611 } else if (state.utm_initialized_f) {
614 } else if (bit_is_set(state.pos_status, POS_ENU_I)) {
618 } else if (bit_is_set(state.pos_status, POS_ENU_F)) {
620 } else if (bit_is_set(state.pos_status, POS_UTM_F)) {
622 } else if (bit_is_set(state.pos_status, POS_LLA_F)) {
623 /* transform lla_f -> utm_f -> ned, set status bits */
627 } else if (bit_is_set(state.pos_status, POS_LLA_I)) {
628 /* transform lla_i -> lla_f -> utm_f -> ned, set status bits */
634 } else { /* could not get this representation, set errno */
635 errno = 2;
636 }
637 } else { /* ned coordinate system not initialized, set errno */
638 errno = 3;
639 }
640 if (errno) {
641 //struct NedCoor_f _ned_zero = {0.0f};
642 //return _ned_zero;
643 return;
644 }
645 /* set bit to indicate this representation is computed */
647}
648
650{
652 return;
653 }
654
655 int errno = 0;
659 } else if (bit_is_set(state.pos_status, POS_ENU_I)) {
661 } else if (bit_is_set(state.pos_status, POS_NED_I)) {
665 } else if (bit_is_set(state.pos_status, POS_ECEF_F)) {
667 } else if (bit_is_set(state.pos_status, POS_ECEF_I)) {
668 /* transform ecef_i -> enu_i -> enu_f, set status bits */
672 } else if (bit_is_set(state.pos_status, POS_LLA_F)) {
674 } else if (bit_is_set(state.pos_status, POS_LLA_I)) {
675 /* transform lla_i -> ecef_i -> enu_i -> enu_f, set status bits */
676 ecef_of_lla_i(&state.ecef_pos_i, &state.lla_pos_i); /* converts to doubles internally */
681 } else { /* could not get this representation, set errno */
682 errno = 1;
683 }
684 } else if (state.utm_initialized_f) {
687 } else if (bit_is_set(state.pos_status, POS_NED_F)) {
689 } else if (bit_is_set(state.pos_status, POS_NED_I)) {
693 } else if (bit_is_set(state.pos_status, POS_UTM_F)) {
695 } else if (bit_is_set(state.pos_status, POS_LLA_F)) {
696 /* transform lla_f -> utm_f -> enu, set status bits */
700 } else if (bit_is_set(state.pos_status, POS_LLA_I)) {
701 /* transform lla_i -> lla_f -> utm_f -> enu, set status bits */
707 } else { /* could not get this representation, set errno */
708 errno = 2;
709 }
710 } else { /* ned coordinate system not initialized, set errno */
711 errno = 3;
712 }
713 if (errno) {
714 //struct EnuCoor_f _enu_zero = {0.0f};
715 //return _enu_zero;
716 return;
717 }
718 /* set bit to indicate this representation is computed */
720}
721
723{
725 return;
726 }
727
728 int errno = 0;
731 } else if (bit_is_set(state.pos_status, POS_ECEF_F)) {
733 } else if (bit_is_set(state.pos_status, POS_ECEF_I)) {
734 /* transform ecef_i -> ecef_f -> lla_f, set status bits */
738 } else if (bit_is_set(state.pos_status, POS_UTM_F)) {
740 } else if (state.ned_initialized_f) {
742 /* transform ned_f -> ecef_f -> lla_f, set status bits */
746 } else if (bit_is_set(state.pos_status, POS_NED_I)) {
747 /* transform ned_i -> ned_f -> ecef_f -> lla_f, set status bits */
753 } else if (bit_is_set(state.pos_status, POS_ENU_F)) {
754 /* transform enu_f -> ecef_f -> lla_f, set status bits */
758 } else if (bit_is_set(state.pos_status, POS_ENU_I)) {
759 /* transform enu_i -> enu_f -> ecef_f -> lla_f, set status bits */
765 } else { /* could not get this representation, set errno */
766 errno = 1;
767 }
768 } else if (state.utm_initialized_f) {
770 /* transform ned_i -> ned_f -> utm_f -> lla_f, set status bits */
776 } else if (bit_is_set(state.pos_status, POS_ENU_I)) {
777 /* transform enu_i -> enu_f -> utm_f -> lla_f, set status bits */
783 } else if (bit_is_set(state.pos_status, POS_NED_F)) {
784 /* transform ned_f -> utm_f -> lla_f, set status bits */
788 } else if (bit_is_set(state.pos_status, POS_ENU_F)) {
789 /* transform enu_f -> utm_f -> lla_f, set status bits */
793 } else { /* could not get this representation, set errno */
794 errno = 2;
795 }
796 } else { /* ned coordinate system not initialized, set errno */
797 errno = 3;
798 }
799 if (errno) {
800 /* could not get this representation, set errno */
801 //struct LlaCoor_f _lla_zero = {0.0};
802 //return _lla_zero;
803 return;
804 }
805 /* set bit to indicate this representation is computed */
807}
814/******************************************************************************
815 * *
816 * Transformation functions for the SPEED representations *
817 * *
818 *****************************************************************************/
821/************************ Set functions ****************************/
822
824{
826 return;
827 }
828
829 int errno = 0;
842 /* transform ecef_f -> ecef_i -> ned_i , set status bits */
846 } else { /* could not get this representation, set errno */
847 errno = 1;
848 }
849 } else if (state.utm_initialized_f) {
858 } else { /* could not get this representation, set errno */
859 errno = 2;
860 }
861 } else { /* ned coordinate system not initialized, set errno */
862 errno = 3;
863 }
864 if (errno) {
865 //struct NedCoor_i _ned_zero = {0};
866 //return _ned_zero;
867 return;
868 }
869 /* set bit to indicate this representation is computed */
871}
872
874{
876 return;
877 }
878
879 int errno = 0;
883 }
893 /* transform ecef_f -> ecef_i -> enu_i , set status bits */
897 } else { /* could not get this representation, set errno */
898 errno = 1;
899 }
900 } else if (state.utm_initialized_f) {
903 }
910 } else { /* could not get this representation, set errno */
911 errno = 2;
912 }
913 } else { /* ned coordinate system not initialized, set errno */
914 errno = 3;
915 }
916 if (errno) {
917 //struct EnuCoor_i _enu_zero = {0};
918 //return _enu_zero;
919 return;
920 }
921 /* set bit to indicate this representation is computed */
923}
924
926{
928 return;
929 }
930
936 /* transform ned_f -> ned_i -> ecef_i , set status bits */
940 } else {
941 /* could not get this representation, set errno */
942 //struct EcefCoor_i _ecef_zero = {0};
943 //return _ecef_zero;
944 return;
945 }
946 /* set bit to indicate this representation is computed */
948}
949
951{
953 return;
954 }
955
975 /* transform ecef speed to ned, set status bit, then compute norm */
987 } else {
988 //int32_t _norm_zero = 0;
989 //return _norm_zero;
990 return;
991 }
992 /* set bit to indicate this representation is computed */
994}
995
1026
1028{
1030 return;
1031 }
1032
1033 int errno = 0;
1046 /* transform ecef_i -> ecef_f -> ned_f , set status bits */
1050 } else { /* could not get this representation, set errno */
1051 errno = 1;
1052 }
1053 } else if (state.utm_initialized_f) {
1062 } else { /* could not get this representation, set errno */
1063 errno = 2;
1064 }
1065 } else { /* ned coordinate system not initialized, set errno */
1066 errno = 3;
1067 }
1068 if (errno) {
1069 //struct NedCoor_f _ned_zero = {0.0f};
1070 //return _ned_zero;
1071 return;
1072 }
1073 /* set bit to indicate this representation is computed */
1075}
1076
1078{
1080 return;
1081 }
1082
1083 int errno = 0;
1096 /* transform ecef_I -> ecef_f -> enu_f , set status bits */
1100 } else { /* could not get this representation, set errno */
1101 errno = 1;
1102 }
1103 } else if (state.utm_initialized_f) {
1112 } else { /* could not get this representation, set errno */
1113 errno = 2;
1114 }
1115 } else { /* ned coordinate system not initialized, set errno */
1116 errno = 3;
1117 }
1118 if (errno) {
1119 //struct EnuCoor_f _enu_zero = {0};
1120 //return _enu_zero;
1121 return;
1122 }
1123 /* set bit to indicate this representation is computed */
1125}
1126
1128{
1130 return;
1131 }
1132
1138 /* transform ned_f -> ned_i -> ecef_i , set status bits */
1142 } else {
1143 /* could not get this representation, set errno */
1144 //struct EcefCoor_f _ecef_zero = {0.0f};
1145 //return _ecef_zero;
1146 return;
1147 }
1148 /* set bit to indicate this representation is computed */
1150}
1151
1178
1209/******************************************************************************
1210 * *
1211 * Transformation functions for the ACCELERATION representations *
1212 * *
1213 *****************************************************************************/
1218{
1220 return;
1221 }
1222
1223 int errno = 0;
1226 }
1227 else if (state.ned_initialized_i) {
1231 /* transform ecef_f -> ecef_i -> ned_i , set status bits */
1235 } else { /* could not get this representation, set errno */
1236 errno = 1;
1237 }
1238 } else { /* ned coordinate system not initialized, set errno */
1239 errno = 2;
1240 }
1241 if (errno) {
1242 //struct NedCoor_i _ned_zero = {0};
1243 //return _ned_zero;
1244 return;
1245 }
1246 /* set bit to indicate this representation is computed */
1248}
1249
1251{
1253 return;
1254 }
1255
1256 int errno = 0;
1259 }
1260 else if (state.ned_initialized_i) {
1264 /* transform ned_f -> ned_i -> ecef_i , set status bits */
1268 } else {
1269 /* could not get this representation, set errno */
1270 errno = 1;
1271 }
1272 } else { /* ned coordinate system not initialized, set errno */
1273 errno = 2;
1274 }
1275 if (errno) {
1276 return;
1277 }
1278 /* set bit to indicate this representation is computed */
1280}
1281
1283{
1285 return;
1286 }
1287
1288 int errno = 0;
1291 }
1292 else if (state.ned_initialized_f) {
1296 /* transform ecef_i -> ecef_f -> ned_f , set status bits */
1300 } else { /* could not get this representation, set errno */
1301 errno = 1;
1302 }
1303 } else { /* ned coordinate system not initialized, set errno */
1304 errno = 2;
1305 }
1306 if (errno) {
1307 //struct NedCoor_f _ned_zero = {0.0f};
1308 //return _ned_zero;
1309 return;
1310 }
1311 /* set bit to indicate this representation is computed */
1313}
1314
1316{
1318 return;
1319 }
1320
1321 int errno = 0;
1324 }
1325 else if (state.ned_initialized_f) {
1329 /* transform ned_f -> ned_i -> ecef_i , set status bits */
1333 } else {
1334 /* could not get this representation, set errno */
1335 errno = 1;
1336 }
1337 } else { /* ned coordinate system not initialized, set errno */
1338 errno = 2;
1339 }
1340 if (errno) {
1341 return;
1342 }
1343 /* set bit to indicate this representation is computed */
1345}
1348/******************************************************************************
1349 * *
1350 * Transformation functions for the ANGULAR RATE representations *
1351 * *
1352 *****************************************************************************/
1357{
1359 return;
1360 }
1361
1364 } else {
1365 return;
1366 }
1367 /* set bit to indicate this representation is computed */
1369}
1370
1372{
1374 return;
1375 }
1376
1379 } else {
1380 return;
1381 }
1382 /* set bit to indicate this representation is computed */
1384}
1385
1389/******************************************************************************
1390 * *
1391 * Transformation functions for the WIND- AND AIRSPEED representations *
1392 * *
1393 *****************************************************************************/
1398{
1400 return;
1401 }
1402
1406 } else {
1407 return;
1408 }
1409 /* set bit to indicate this representation is computed */
1411}
1412
1414{
1416 return;
1417 }
1418
1421 } else {
1422 return;
1423 }
1424 /* set bit to indicate this representation is computed */
1426}
1427
1429{
1431 return;
1432 }
1433
1436 } else {
1437 return;
1438 }
1439 /* set bit to indicate this representation is computed */
1441}
1442
1444{
1446 return;
1447 }
1448
1452 } else {
1453 return;
1454 }
1455 /* set bit to indicate this representation is computed */
1457}
1458
1460{
1462 return;
1463 }
1464
1467 } else {
1468 return;
1469 }
1470 /* set bit to indicate this representation is computed */
1472}
1473
1475{
1477 return;
1478 }
1479
1482 } else {
1483 return;
1484 }
1485 /* set bit to indicate this representation is computed */
1487}
#define STATE_INPUT_RATES
Definition state.h:145
#define STATE_INPUT_SPEED
Definition state.h:142
#define STATE_INPUT_POS
Definition state.h:141
#define STATE_INPUT_ACCEL
Definition state.h:143
#define STATE_INPUT_ORIGIN
Definition state.h:140
#define STATE_INPUT_ANY
default
Definition state.h:139
#define STATE_INPUT_WIND_AIR
Definition state.h:146
#define STATE_INPUT_ATTITUDE
Definition state.h:144
#define FLOAT_VECT2_NORM(_v)
#define RATES_BFP_OF_REAL(_ri, _rf)
#define SPEEDS_BFP_OF_REAL(_ef, _ei)
#define ACCELS_BFP_OF_REAL(_ef, _ei)
#define RATES_FLOAT_OF_BFP(_rf, _ri)
#define SPEEDS_FLOAT_OF_BFP(_ef, _ei)
#define ACCELS_FLOAT_OF_BFP(_ef, _ei)
uint32_t int32_sqrt(uint32_t in)
#define INT32_SPEED_FRAC
#define INT32_COURSE_NORMALIZE(_a)
#define SPEED_FLOAT_OF_BFP(_ai)
#define SPEED_BFP_OF_REAL(_af)
#define UTM_OF_NED_ADD(_utm, _pos, _utm0)
#define ENU_OF_UTM_DIFF(_pos, _utm1, _utm2)
#define NED_OF_UTM_DIFF(_pos, _utm1, _utm2)
#define UTM_OF_ENU_ADD(_utm, _pos, _utm0)
int32_t y
North.
int32_t hmsl
Height above mean sea level in mm.
struct LlaCoor_i lla
Reference point in lla.
int32_t y
East.
struct EcefCoor_i ecef
Reference point in ecef.
int32_t x
East.
int32_t x
North.
void ned_of_lla_pos_i(struct NedCoor_i *ned, struct LtpDef_i *def, struct LlaCoor_i *lla)
Convert a point from LLA to local NED.
#define ECEF_FLOAT_OF_BFP(_o, _i)
void ecef_of_lla_i(struct EcefCoor_i *out, struct LlaCoor_i *in)
Convert a LLA to ECEF.
#define ENU_FLOAT_OF_BFP(_o, _i)
#define ECEF_BFP_OF_REAL(_o, _i)
#define ENU_BFP_OF_REAL(_o, _i)
#define LLA_BFP_OF_REAL(_o, _i)
#define NED_BFP_OF_REAL(_o, _i)
void ned_of_ecef_pos_i(struct NedCoor_i *ned, struct LtpDef_i *def, struct EcefCoor_i *ecef)
Convert a ECEF position to local NED.
#define NED_FLOAT_OF_BFP(_o, _i)
void enu_of_ecef_pos_i(struct EnuCoor_i *enu, struct LtpDef_i *def, struct EcefCoor_i *ecef)
Convert a ECEF position to local ENU.
#define INT32_VECT3_ENU_OF_NED(_o, _i)
#define VECT3_ENU_OF_NED(_o, _i)
void ecef_of_enu_pos_i(struct EcefCoor_i *ecef, struct LtpDef_i *def, struct EnuCoor_i *enu)
Convert a local ENU position to ECEF.
#define VECT3_NED_OF_ENU(_o, _i)
void ecef_of_ned_vect_i(struct EcefCoor_i *ecef, struct LtpDef_i *def, struct NedCoor_i *ned)
Rotate a vector from NED to ECEF.
void ned_of_ecef_vect_i(struct NedCoor_i *ned, struct LtpDef_i *def, struct EcefCoor_i *ecef)
Rotate a vector from ECEF to NED.
#define MM_OF_M(_m)
#define LLA_FLOAT_OF_BFP(_o, _i)
#define INT32_VECT3_NED_OF_ENU(_o, _i)
#define M_OF_MM(_mm)
void enu_of_lla_pos_i(struct EnuCoor_i *enu, struct LtpDef_i *def, struct LlaCoor_i *lla)
Convert a point from LLA to local ENU.
void lla_of_ecef_i(struct LlaCoor_i *out, struct EcefCoor_i *in)
Convert a ECEF to LLA.
void enu_of_ecef_vect_i(struct EnuCoor_i *enu, struct LtpDef_i *def, struct EcefCoor_i *ecef)
Rotate a vector from ECEF to ENU.
void ecef_of_ned_pos_i(struct EcefCoor_i *ecef, struct LtpDef_i *def, struct NedCoor_i *ned)
Convert a local NED position to ECEF.
vector in EarthCenteredEarthFixed coordinates
vector in Latitude, Longitude and Altitude
uint8_t status
Holds the status bits for all orientation representations.
#define ACCEL_ECEF_I
Definition state.h:106
struct EcefCoor_f ecef_accel_f
Acceleration in EarthCenteredEarthFixed coordinates.
Definition state.h:400
struct NedCoor_i ned_accel_i
Acceleration in North East Down coordinates.
Definition state.h:382
#define ACCEL_NED_F
Definition state.h:109
uint8_t accel_status
Holds the status bits for all acceleration representations.
Definition state.h:365
void stateCalcAccelNed_i(void)
Definition state.c:1217
void stateCalcAccelEcef_i(void)
Definition state.c:1250
struct EcefCoor_i ecef_accel_i
Acceleration in EarthCenteredEarthFixed coordinates.
Definition state.h:388
#define ACCEL_ECEF_F
Definition state.h:108
void stateCalcAccelEcef_f(void)
Definition state.c:1315
uint16_t accel_input_filter
Holds the input filter id for acceleration.
Definition state.h:370
struct NedCoor_f ned_accel_f
Acceleration in North East Down coordinates.
Definition state.h:394
#define ACCEL_NED_I
Definition state.h:107
void stateCalcAccelNed_f(void)
Definition state.c:1282
static bool stateIsAttitudeValid(void)
Test if attitudes are valid.
Definition state.h:1224
uint16_t attitude_input_filter
Holds the input filter id for attitude.
Definition state.h:411
struct OrientationReps ned_to_body_orientation
Definition state.h:406
void stateSetInputFilter(uint8_t type, uint16_t flag)
set the input filter for a specified type of data.
Definition state.c:85
struct State state
Definition state.c:36
void stateInit(void)
Definition state.c:57
Structure holding vehicle state data.
Definition state.h:152
#define POS_LLA_F
Definition state.h:79
struct NedCoor_i ned_pos_i
Position in North East Down coordinates.
Definition state.h:206
#define POS_UTM_F
Definition state.h:80
#define POS_LLA_I
Definition state.h:74
struct NedCoor_f ned_pos_f
Position in North East Down coordinates.
Definition state.h:271
#define POS_ENU_F
Definition state.h:78
struct EnuCoor_f enu_pos_f
Position in East North Up coordinates.
Definition state.h:278
#define POS_ECEF_F
Definition state.h:76
struct UtmCoor_f utm_pos_f
Position in UTM coordinates.
Definition state.h:220
void stateCalcPositionNed_f(void)
Definition state.c:582
struct LtpDef_f ned_origin_f
Definition of the local (flat earth) coordinate system.
Definition state.h:248
struct LtpDef_i ned_origin_i
Definition of the local (flat earth) coordinate system.
Definition state.h:194
bool ned_initialized_f
True if local float coordinate frame is initialsed.
Definition state.h:251
struct EcefCoor_f stateGetEcefOrigin_f(void)
Get the ECEF position of the frame origin (float)
Definition state.c:175
uint16_t pos_status
Holds the status bits for all position representations.
Definition state.h:167
struct LlaCoor_i lla_pos_i
Position in Latitude, Longitude and Altitude.
Definition state.h:185
void stateCalcPositionUtm_f(void)
Definition state.c:514
void stateCalcPositionEnu_f(void)
Definition state.c:649
struct EcefCoor_f ecef_pos_f
Position in EarthCenteredEarthFixed coordinates.
Definition state.h:239
bool utm_initialized_f
True if utm origin (float) coordinate frame is initialsed.
Definition state.h:264
#define POS_ENU_I
Definition state.h:73
uint16_t origin_input_filter
Holds the input filter id for state origin.
Definition state.h:160
#define POS_ECEF_I
Definition state.h:71
void stateCalcPositionEcef_f(void)
Definition state.c:551
struct EnuCoor_i enu_pos_i
Position in East North Up coordinates.
Definition state.h:213
bool ned_initialized_i
true if local int coordinate frame is initialsed
Definition state.h:199
#define POS_NED_F
Definition state.h:77
void stateCalcPositionLla_f(void)
Definition state.c:722
int32_t stateGetHmslOrigin_i(void)
Get the HMSL of the frame origin (int)
Definition state.c:190
void stateCalcPositionEcef_i(void)
Definition state.c:217
float stateGetHmslOrigin_f(void)
Get the HMSL of the frame origin (float)
Definition state.c:204
struct UtmCoor_f utm_origin_f
Definition of the origin of Utm coordinate system.
Definition state.h:261
struct LlaCoor_i stateGetLlaOrigin_i(void)
Get the LLA position of the frame origin (int)
Definition state.c:124
void stateCalcPositionNed_i(void)
Definition state.c:249
void stateCalcPositionLla_i(void)
Calculate LLA (int) from any other available representation.
Definition state.c:416
struct LlaCoor_f stateGetLlaOrigin_f(void)
Get the LLA position of the frame origin (float)
Definition state.c:143
struct LlaCoor_f lla_pos_f
Position in Latitude, Longitude and Altitude.
Definition state.h:233
uint16_t pos_input_filter
Holds the input filter id for position.
Definition state.h:172
struct EcefCoor_i ecef_pos_i
Position in EarthCenteredEarthFixed coordinates.
Definition state.h:178
#define POS_NED_I
Definition state.h:72
struct EcefCoor_i stateGetEcefOrigin_i(void)
Get the ECEF position of the frame origin (int)
Definition state.c:160
void stateCalcPositionEnu_i(void)
Definition state.c:329
uint16_t rates_input_filter
Holds the input filter id for rates.
Definition state.h:426
void stateCalcBodyRates_f(void)
Definition state.c:1371
#define RATE_F
Definition state.h:117
struct FloatRates body_rates_f
Angular rates in body frame.
Definition state.h:438
#define RATE_I
Definition state.h:116
void stateCalcBodyRates_i(void)
Definition state.c:1356
struct Int32Rates body_rates_i
Angular rates in body frame.
Definition state.h:432
uint8_t rate_status
Holds the status bits for all angular rate representations.
Definition state.h:421
#define SPEED_ENU_F
Definition state.h:96
#define SPEED_ENU_I
Definition state.h:91
void stateCalcSpeedEnu_f(void)
Definition state.c:1077
struct NedCoor_f ned_speed_f
speed in North East Down coordinates
Definition state.h:336
#define SPEED_ECEF_F
Definition state.h:94
void stateCalcSpeedNed_f(void)
Definition state.c:1027
uint16_t speed_input_filter
Holds the input filter id for speed.
Definition state.h:294
#define SPEED_ECEF_I
Definition state.h:89
void stateCalcHorizontalSpeedDir_i(void)
Definition state.c:996
#define SPEED_NED_F
Definition state.h:95
struct NedCoor_i ned_speed_i
Velocity in North East Down coordinates.
Definition state.h:306
float h_speed_norm_f
Norm of horizontal ground speed.
Definition state.h:348
int32_t h_speed_dir_i
Direction of horizontal ground speed.
Definition state.h:325
float h_speed_dir_f
Direction of horizontal ground speed.
Definition state.h:354
void stateCalcHorizontalSpeedNorm_f(void)
Definition state.c:1152
void stateCalcHorizontalSpeedNorm_i(void)
Definition state.c:950
struct EcefCoor_f ecef_speed_f
Velocity in EarthCenteredEarthFixed coordinates.
Definition state.h:331
void stateCalcSpeedEcef_f(void)
Definition state.c:1127
#define SPEED_HDIR_I
Definition state.h:93
void stateCalcSpeedEnu_i(void)
Definition state.c:873
#define SPEED_HNORM_F
Definition state.h:97
#define SPEED_NED_I
Definition state.h:90
struct EcefCoor_i ecef_speed_i
Velocity in EarthCenteredEarthFixed coordinates.
Definition state.h:300
void stateCalcHorizontalSpeedDir_f(void)
Definition state.c:1179
struct EnuCoor_i enu_speed_i
Velocity in East North Up coordinates.
Definition state.h:312
uint16_t speed_status
Holds the status bits for all ground speed representations.
Definition state.h:289
void stateCalcSpeedNed_i(void)
Definition state.c:823
#define SPEED_HNORM_I
Definition state.h:92
uint32_t h_speed_norm_i
Norm of horizontal ground speed.
Definition state.h:318
#define SPEED_HDIR_F
Definition state.h:98
struct EnuCoor_f enu_speed_f
Velocity in East North Up coordinates.
Definition state.h:342
void stateCalcSpeedEcef_i(void)
Definition state.c:925
#define WINDSPEED_I
Definition state.h:124
int32_t airspeed_i
Norm of relative wind speed.
Definition state.h:469
#define DOWNWIND_F
Definition state.h:128
union State::@356 windspeed_f
Horizontal windspeed.
#define WINDSPEED_F
Definition state.h:127
float airspeed_f
Norm of relative air speed.
Definition state.h:484
uint8_t wind_air_status
Holds the status bits for all wind- and airspeed representations.
Definition state.h:449
#define AIRSPEED_I
Definition state.h:126
void stateCalcAirspeed_i(void)
Definition state.c:1428
void stateCalcVerticalWindspeed_i(void)
Definition state.c:1413
void stateCalcAirspeed_f(void)
Definition state.c:1474
#define AIRSPEED_F
Definition state.h:129
uint16_t wind_air_input_filter
Holds the input filter id for air data.
Definition state.h:454
void stateCalcHorizontalWindspeed_f(void)
Definition state.c:1443
void stateCalcHorizontalWindspeed_i(void)
Definition state.c:1397
union State::@355 windspeed_i
Horizontal windspeed in north/east/down.
#define DOWNWIND_I
Definition state.h:125
void stateCalcVerticalWindspeed_f(void)
Definition state.c:1459
uint16_t foo
Definition main_demo5.c:58
void ecef_of_enu_point_f(struct EcefCoor_f *ecef, struct LtpDef_f *def, struct EnuCoor_f *enu)
void enu_of_ecef_point_f(struct EnuCoor_f *enu, struct LtpDef_f *def, struct EcefCoor_f *ecef)
void ned_of_ecef_point_f(struct NedCoor_f *ned, struct LtpDef_f *def, struct EcefCoor_f *ecef)
void lla_of_utm_f(struct LlaCoor_f *lla, struct UtmCoor_f *utm)
void ecef_of_ned_vect_f(struct EcefCoor_f *ecef, struct LtpDef_f *def, struct NedCoor_f *ned)
void ecef_of_lla_f(struct EcefCoor_f *out, struct LlaCoor_f *in)
void ecef_of_ned_point_f(struct EcefCoor_f *ecef, struct LtpDef_f *def, struct NedCoor_f *ned)
void enu_of_lla_point_f(struct EnuCoor_f *enu, struct LtpDef_f *def, struct LlaCoor_f *lla)
void ned_of_lla_point_f(struct NedCoor_f *ned, struct LtpDef_f *def, struct LlaCoor_f *lla)
void ned_of_ecef_vect_f(struct NedCoor_f *ned, struct LtpDef_f *def, struct EcefCoor_f *ecef)
void enu_of_ecef_vect_f(struct EnuCoor_f *enu, struct LtpDef_f *def, struct EcefCoor_f *ecef)
void lla_of_ecef_f(struct LlaCoor_f *out, struct EcefCoor_f *in)
void utm_of_lla_f(struct UtmCoor_f *utm, struct LlaCoor_f *lla)
float y
in meters
float x
in meters
void lla_of_utm_f(struct LlaCoor_f *lla, struct UtmCoor_f *utm)
float alt
in meters (above WGS84 reference ellipsoid or above MSL)
uint8_t zone
UTM zone number.
float x
in meters
float hmsl
Height above mean sea level in meters.
struct EcefCoor_f ecef
origin of local frame in ECEF
struct LlaCoor_f lla
origin of local frame in LLA
float y
in meters
vector in EarthCenteredEarthFixed coordinates
vector in Latitude, Longitude and Altitude
int32_t int32_atan2(int32_t y, int32_t x)
void preflight_error(struct preflight_result_t *result, const char *fmt,...)
Register a preflight error used inside the preflight checking functions.
void preflight_success(struct preflight_result_t *result, const char *fmt,...)
Register a preflight success used inside the preflight checking functions.
void preflight_check_register(struct preflight_check_t *check, preflight_check_f func)
Register a preflight check and add it to the linked list.
API to get/set the generic vehicle states.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
int int32_t
Typedef defining 32 bit int type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.