Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
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 
36 struct State state;
37 
38 #if PREFLIGHT_CHECKS && !defined(AUTOPILOT_DISABLE_AHRS_KILL)
39 /* Preflight checks */
41 static struct preflight_check_t state_pfc;
42 
43 static void state_preflight(struct preflight_result_t *result) {
44  if(!stateIsAttitudeValid()) {
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 
57 void stateInit(void)
58 {
59  state.pos_status = 0;
60  state.speed_status = 0;
61  state.accel_status = 0;
63  state.rate_status = 0;
65  state.ned_initialized_i = false;
66  state.ned_initialized_f = false;
67  state.utm_initialized_f = false;
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)
81  preflight_check_register(&state_pfc, state_preflight);
82 #endif
83 }
84 
86 {
87  switch (type) {
88  case STATE_INPUT_ORIGIN:
90  break;
91  case STATE_INPUT_POS:
92  state.pos_input_filter = flag;
93  break;
94  case STATE_INPUT_SPEED:
96  break;
97  case STATE_INPUT_ACCEL:
99  break;
102  break;
103  case STATE_INPUT_RATES:
104  state.rates_input_filter = flag;
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  ******************************************************************************/
124 struct LlaCoor_i stateGetLlaOrigin_i(void)
125 {
126  struct LlaCoor_i lla_i = {0};
127  if (state.ned_initialized_i) {
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;
134  lla_of_utm_f(&lla_f, &state.utm_origin_f);
135  LLA_BFP_OF_REAL(lla_i, lla_f);
136  return lla_i;
137  } else {
138  return lla_i;
139  }
140 }
141 
143 struct LlaCoor_f stateGetLlaOrigin_f(void)
144 {
145  struct LlaCoor_f lla_f = {0};
146  if (state.ned_initialized_f) {
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) {
152  lla_of_utm_f(&lla_f, &state.utm_origin_f);
153  return lla_f;
154  } else {
155  return lla_f;
156  }
157 }
158 
160 struct EcefCoor_i stateGetEcefOrigin_i(void)
161 {
162  struct EcefCoor_i ecef_i = {0};
163  if (state.ned_initialized_i) {
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 
175 struct EcefCoor_f stateGetEcefOrigin_f(void)
176 {
177  struct EcefCoor_f ecef_f = {0};
178  if (state.ned_initialized_f) {
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 {
192  if (state.ned_initialized_i) {
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 {
206  if (state.ned_initialized_f) {
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 {
219  if (bit_is_set(state.pos_status, POS_ECEF_I)) {
220  return;
221  }
222 
223  if (bit_is_set(state.pos_status, POS_ECEF_F)) {
225  } else if (bit_is_set(state.pos_status, POS_NED_I) && state.ned_initialized_i) {
227  } else if (bit_is_set(state.pos_status, POS_NED_F) && state.ned_initialized_f) {
228  /* transform ned_f to ecef_f, set status bit, then convert to int */
230  SetBit(state.pos_status, POS_ECEF_F);
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 */
237  SetBit(state.pos_status, POS_ECEF_F);
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 */
246  SetBit(state.pos_status, POS_ECEF_I);
247 }
248 
250 {
251  if (bit_is_set(state.pos_status, POS_NED_I)) {
252  return;
253  }
254 
255  int errno = 0;
256  if (state.ned_initialized_i) {
257  if (bit_is_set(state.pos_status, POS_NED_F)) {
259  } else if (bit_is_set(state.pos_status, POS_ENU_I)) {
261  } else if (bit_is_set(state.pos_status, POS_ENU_F)) {
263  SetBit(state.pos_status, POS_ENU_I);
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 */
270  SetBit(state.pos_status, POS_NED_F);
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 */
275  SetBit(state.pos_status, POS_ECEF_F);
277  SetBit(state.pos_status, POS_NED_F);
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) {
285  if (bit_is_set(state.pos_status, POS_NED_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)) {
291  SetBit(state.pos_status, POS_ENU_I);
293  } else if (bit_is_set(state.pos_status, POS_UTM_F)) {
294  /* transform utm_f -> ned_f -> ned_i, set status bits */
296  SetBit(state.pos_status, POS_NED_F);
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 */
301  SetBit(state.pos_status, POS_UTM_F);
303  SetBit(state.pos_status, POS_NED_F);
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 */
308  SetBit(state.pos_status, POS_LLA_F);
310  SetBit(state.pos_status, POS_UTM_F);
312  SetBit(state.pos_status, POS_NED_F);
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 */
326  SetBit(state.pos_status, POS_NED_I);
327 }
328 
330 {
331  if (bit_is_set(state.pos_status, POS_ENU_I)) {
332  return;
333  }
334 
335  int errno = 0;
336  if (state.ned_initialized_i) {
337  if (bit_is_set(state.pos_status, POS_NED_I)) {
339  } else if (bit_is_set(state.pos_status, POS_ENU_F)) {
341  } else if (bit_is_set(state.pos_status, POS_NED_F)) {
343  SetBit(state.pos_status, POS_NED_I);
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 */
350  SetBit(state.pos_status, POS_ENU_F);
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 */
355  SetBit(state.pos_status, POS_ECEF_F);
357  SetBit(state.pos_status, POS_ENU_F);
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) {
365  if (bit_is_set(state.pos_status, POS_ENU_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)) {
371  SetBit(state.pos_status, POS_NED_I);
373  } else if (bit_is_set(state.pos_status, POS_UTM_F)) {
374  /* transform utm_f -> enu_f -> enu_i , set status bits */
376  SetBit(state.pos_status, POS_ENU_F);
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 */
381  SetBit(state.pos_status, POS_UTM_F);
383  SetBit(state.pos_status, POS_ENU_F);
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 */
388  SetBit(state.pos_status, POS_LLA_F);
390  SetBit(state.pos_status, POS_UTM_F);
392  SetBit(state.pos_status, POS_ENU_F);
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 */
406  SetBit(state.pos_status, POS_ENU_I);
407 }
408 
417 {
418  if (bit_is_set(state.pos_status, POS_LLA_I)) {
419  return;
420  }
421 
422  int errno = 0;
423  if (bit_is_set(state.pos_status, POS_ECEF_I)) {
425  } else if (bit_is_set(state.pos_status, POS_ECEF_F)) {
426  /* transform ecef_f -> ecef_i -> lla_i, set status bits */
428  SetBit(state.pos_status, POS_ECEF_I);
430  } else if (bit_is_set(state.pos_status, POS_UTM_F)) {
431  /* transform utm_f -> lla_f -> lla_i, set status bits */
433  SetBit(state.pos_status, POS_LLA_F);
435  } else if (state.ned_initialized_i) {
436  if (bit_is_set(state.pos_status, POS_NED_I)) {
437  /* transform ned_i -> ecef_i -> lla_i, set status bits */
439  SetBit(state.pos_status, POS_ECEF_I);
441  } else if (bit_is_set(state.pos_status, POS_ENU_I)) {
442  /* transform enu_i -> ecef_i -> lla_i, set status bits */
444  SetBit(state.pos_status, POS_ECEF_I);
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 */
449  SetBit(state.pos_status, POS_NED_I);
451  SetBit(state.pos_status, POS_ECEF_I);
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 */
456  SetBit(state.pos_status, POS_ENU_I);
458  SetBit(state.pos_status, POS_ECEF_I);
460  } else { /* could not get this representation, set errno */
461  errno = 1;
462  }
463  } else if (state.utm_initialized_f) {
464  if (bit_is_set(state.pos_status, POS_NED_I)) {
465  /* transform ned_i -> ned_f -> utm_f -> lla_f -> lla_i, set status bits */
467  SetBit(state.pos_status, POS_NED_F);
469  SetBit(state.pos_status, POS_UTM_F);
471  SetBit(state.pos_status, POS_LLA_F);
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 */
476  SetBit(state.pos_status, POS_ENU_F);
478  SetBit(state.pos_status, POS_UTM_F);
480  SetBit(state.pos_status, POS_LLA_F);
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 */
485  SetBit(state.pos_status, POS_UTM_F);
487  SetBit(state.pos_status, POS_LLA_F);
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 */
492  SetBit(state.pos_status, POS_UTM_F);
494  SetBit(state.pos_status, POS_LLA_F);
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 */
511  SetBit(state.pos_status, POS_LLA_I);
512 }
513 
515 {
516  if (bit_is_set(state.pos_status, POS_UTM_F)) {
517  return;
518  }
519 
520  if (bit_is_set(state.pos_status, POS_LLA_F)) {
522  } else if (bit_is_set(state.pos_status, POS_LLA_I)) {
523  /* transform lla_i -> lla_f -> utm_f, set status bits */
525  SetBit(state.pos_status, POS_LLA_F);
527  } else if (state.utm_initialized_f) {
528  if (bit_is_set(state.pos_status, POS_ENU_F)) {
530  } else if (bit_is_set(state.pos_status, POS_ENU_I)) {
532  SetBit(state.pos_status, POS_ENU_F);
534  } else if (bit_is_set(state.pos_status, POS_NED_F)) {
536  } else if (bit_is_set(state.pos_status, POS_NED_I)) {
538  SetBit(state.pos_status, POS_NED_F);
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 */
548  SetBit(state.pos_status, POS_UTM_F);
549 }
550 
552 {
553  if (bit_is_set(state.pos_status, POS_ECEF_F)) {
554  return;
555  }
556 
557  if (bit_is_set(state.pos_status, POS_ECEF_I)) {
559  } else if (bit_is_set(state.pos_status, POS_NED_F) && state.ned_initialized_f) {
561  } else if (bit_is_set(state.pos_status, POS_NED_I) && state.ned_initialized_i) {
562  /* transform ned_i -> ecef_i -> ecef_f, set status bits */
564  SetBit(state.pos_status, POS_ECEF_F);
566  } else if (bit_is_set(state.pos_status, POS_LLA_F)) {
568  } else if (bit_is_set(state.pos_status, POS_LLA_I)) {
570  SetBit(state.pos_status, POS_LLA_F);
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 */
579  SetBit(state.pos_status, POS_ECEF_F);
580 }
581 
583 {
584  if (bit_is_set(state.pos_status, POS_NED_F)) {
585  return;
586  }
587 
588  int errno = 0;
589  if (state.ned_initialized_f) {
590  if (bit_is_set(state.pos_status, POS_NED_I)) {
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 */
597  SetBit(state.pos_status, POS_NED_I);
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 */
604  SetBit(state.pos_status, POS_ECEF_I);
606  SetBit(state.pos_status, POS_NED_I);
608  } else { /* could not get this representation, set errno */
609  errno = 1;
610  }
611  } else if (state.utm_initialized_f) {
612  if (bit_is_set(state.pos_status, POS_NED_I)) {
614  } else if (bit_is_set(state.pos_status, POS_ENU_I)) {
616  SetBit(state.pos_status, POS_ENU_F);
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 */
625  SetBit(state.pos_status, POS_UTM_F);
627  } else if (bit_is_set(state.pos_status, POS_LLA_I)) {
628  /* transform lla_i -> lla_f -> utm_f -> ned, set status bits */
630  SetBit(state.pos_status, POS_LLA_F);
632  SetBit(state.pos_status, POS_UTM_F);
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 */
646  SetBit(state.pos_status, POS_NED_F);
647 }
648 
650 {
651  if (bit_is_set(state.pos_status, POS_ENU_F)) {
652  return;
653  }
654 
655  int errno = 0;
656  if (state.ned_initialized_f) {
657  if (bit_is_set(state.pos_status, POS_NED_F)) {
659  } else if (bit_is_set(state.pos_status, POS_ENU_I)) {
661  } else if (bit_is_set(state.pos_status, POS_NED_I)) {
663  SetBit(state.pos_status, POS_NED_F);
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 */
670  SetBit(state.pos_status, POS_ENU_I);
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 */
677  SetBit(state.pos_status, POS_ECEF_I);
679  SetBit(state.pos_status, POS_ENU_I);
681  } else { /* could not get this representation, set errno */
682  errno = 1;
683  }
684  } else if (state.utm_initialized_f) {
685  if (bit_is_set(state.pos_status, POS_ENU_I)) {
687  } else if (bit_is_set(state.pos_status, POS_NED_F)) {
689  } else if (bit_is_set(state.pos_status, POS_NED_I)) {
691  SetBit(state.pos_status, POS_NED_F);
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 */
698  SetBit(state.pos_status, POS_UTM_F);
700  } else if (bit_is_set(state.pos_status, POS_LLA_I)) {
701  /* transform lla_i -> lla_f -> utm_f -> enu, set status bits */
703  SetBit(state.pos_status, POS_LLA_F);
705  SetBit(state.pos_status, POS_UTM_F);
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 */
719  SetBit(state.pos_status, POS_ENU_F);
720 }
721 
723 {
724  if (bit_is_set(state.pos_status, POS_LLA_F)) {
725  return;
726  }
727 
728  int errno = 0;
729  if (bit_is_set(state.pos_status, POS_LLA_I)) {
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 */
736  SetBit(state.pos_status, POS_ECEF_F);
738  } else if (bit_is_set(state.pos_status, POS_UTM_F)) {
740  } else if (state.ned_initialized_f) {
741  if (bit_is_set(state.pos_status, POS_NED_F)) {
742  /* transform ned_f -> ecef_f -> lla_f, set status bits */
744  SetBit(state.pos_status, POS_ECEF_F);
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 */
749  SetBit(state.pos_status, POS_NED_F);
751  SetBit(state.pos_status, POS_ECEF_F);
753  } else if (bit_is_set(state.pos_status, POS_ENU_F)) {
754  /* transform enu_f -> ecef_f -> lla_f, set status bits */
756  SetBit(state.pos_status, POS_ECEF_F);
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 */
761  SetBit(state.pos_status, POS_ENU_F);
763  SetBit(state.pos_status, POS_ECEF_F);
765  } else { /* could not get this representation, set errno */
766  errno = 1;
767  }
768  } else if (state.utm_initialized_f) {
769  if (bit_is_set(state.pos_status, POS_NED_I)) {
770  /* transform ned_i -> ned_f -> utm_f -> lla_f, set status bits */
772  SetBit(state.pos_status, POS_NED_F);
774  SetBit(state.pos_status, POS_UTM_F);
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 */
779  SetBit(state.pos_status, POS_ENU_F);
781  SetBit(state.pos_status, POS_UTM_F);
783  } else if (bit_is_set(state.pos_status, POS_NED_F)) {
784  /* transform ned_f -> utm_f -> lla_f, set status bits */
786  SetBit(state.pos_status, POS_UTM_F);
788  } else if (bit_is_set(state.pos_status, POS_ENU_F)) {
789  /* transform enu_f -> utm_f -> lla_f, set status bits */
791  SetBit(state.pos_status, POS_UTM_F);
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 */
806  SetBit(state.pos_status, POS_LLA_F);
807 }
814 /******************************************************************************
815  * *
816  * Transformation functions for the SPEED representations *
817  * *
818  *****************************************************************************/
821 /************************ Set functions ****************************/
822 
824 {
825  if (bit_is_set(state.speed_status, SPEED_NED_I)) {
826  return;
827  }
828 
829  int errno = 0;
830  if (state.ned_initialized_i) {
831  if (bit_is_set(state.speed_status, SPEED_NED_F)) {
833  } else if (bit_is_set(state.speed_status, SPEED_ENU_I)) {
835  } else if (bit_is_set(state.speed_status, SPEED_ENU_F)) {
837  SetBit(state.speed_status, SPEED_ENU_I);
839  } else if (bit_is_set(state.speed_status, SPEED_ECEF_I)) {
841  } else if (bit_is_set(state.speed_status, SPEED_ECEF_F)) {
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) {
850  if (bit_is_set(state.speed_status, SPEED_NED_F)) {
852  } else if (bit_is_set(state.speed_status, SPEED_ENU_I)) {
854  } else if (bit_is_set(state.speed_status, SPEED_ENU_F)) {
856  SetBit(state.speed_status, SPEED_ENU_I);
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 */
870  SetBit(state.speed_status, SPEED_NED_I);
871 }
872 
874 {
875  if (bit_is_set(state.speed_status, SPEED_ENU_I)) {
876  return;
877  }
878 
879  int errno = 0;
880  if (state.ned_initialized_i) {
881  if (bit_is_set(state.speed_status, SPEED_NED_I)) {
883  }
884  if (bit_is_set(state.speed_status, SPEED_ENU_F)) {
886  } else if (bit_is_set(state.speed_status, SPEED_NED_F)) {
888  SetBit(state.speed_status, SPEED_NED_I);
890  } else if (bit_is_set(state.speed_status, SPEED_ECEF_I)) {
892  } else if (bit_is_set(state.speed_status, SPEED_ECEF_F)) {
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) {
901  if (bit_is_set(state.speed_status, SPEED_NED_I)) {
903  }
904  if (bit_is_set(state.speed_status, SPEED_ENU_F)) {
906  } else if (bit_is_set(state.speed_status, SPEED_NED_F)) {
908  SetBit(state.speed_status, SPEED_NED_I);
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 */
922  SetBit(state.speed_status, SPEED_ENU_I);
923 }
924 
926 {
927  if (bit_is_set(state.speed_status, SPEED_ECEF_I)) {
928  return;
929  }
930 
931  if (bit_is_set(state.speed_status, SPEED_ECEF_F)) {
933  } else if (bit_is_set(state.speed_status, SPEED_NED_I)) {
935  } else if (bit_is_set(state.speed_status, SPEED_NED_F)) {
936  /* transform ned_f -> ned_i -> ecef_i , set status bits */
938  SetBit(state.speed_status, SPEED_NED_I);
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 {
952  if (bit_is_set(state.speed_status, SPEED_HNORM_I)) {
953  return;
954  }
955 
956  if (bit_is_set(state.speed_status, SPEED_HNORM_F)) {
958  } else if (bit_is_set(state.speed_status, SPEED_NED_I)) {
962  } else if (bit_is_set(state.speed_status, SPEED_NED_F)) {
966  } else if (bit_is_set(state.speed_status, SPEED_ENU_I)) {
970  } else if (bit_is_set(state.speed_status, SPEED_ENU_F)) {
974  } else if (bit_is_set(state.speed_status, SPEED_ECEF_I)) {
975  /* transform ecef speed to ned, set status bit, then compute norm */
977  SetBit(state.speed_status, SPEED_NED_I);
981  } else if (bit_is_set(state.speed_status, SPEED_ECEF_F)) {
983  SetBit(state.speed_status, SPEED_NED_F);
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 
997 {
998  if (bit_is_set(state.speed_status, SPEED_HDIR_I)) {
999  return;
1000  }
1001 
1002  if (bit_is_set(state.speed_status, SPEED_HDIR_F)) {
1004  } else if (bit_is_set(state.speed_status, SPEED_NED_I)) {
1007  } else if (bit_is_set(state.speed_status, SPEED_ENU_I)) {
1010  } else if (bit_is_set(state.speed_status, SPEED_NED_F)) {
1012  SetBit(state.speed_status, SPEED_NED_I);
1015  } else if (bit_is_set(state.speed_status, SPEED_ENU_F)) {
1017  SetBit(state.speed_status, SPEED_ENU_I);
1020  } else {
1021  return;
1022  }
1023  /* set bit to indicate this representation is computed */
1024  SetBit(state.speed_status, SPEED_HDIR_I);
1025 }
1026 
1028 {
1029  if (bit_is_set(state.speed_status, SPEED_NED_F)) {
1030  return;
1031  }
1032 
1033  int errno = 0;
1034  if (state.ned_initialized_f) {
1035  if (bit_is_set(state.speed_status, SPEED_NED_I)) {
1037  } else if (bit_is_set(state.speed_status, SPEED_ENU_F)) {
1039  } else if (bit_is_set(state.speed_status, SPEED_ENU_I)) {
1041  SetBit(state.speed_status, SPEED_ENU_F);
1043  } else if (bit_is_set(state.speed_status, SPEED_ECEF_F)) {
1045  } else if (bit_is_set(state.speed_status, SPEED_ECEF_I)) {
1046  /* transform ecef_i -> ecef_f -> ned_f , set status bits */
1048  SetBit(state.speed_status, SPEED_ECEF_F);
1050  } else { /* could not get this representation, set errno */
1051  errno = 1;
1052  }
1053  } else if (state.utm_initialized_f) {
1054  if (bit_is_set(state.speed_status, SPEED_NED_I)) {
1056  } else if (bit_is_set(state.speed_status, SPEED_ENU_F)) {
1058  } else if (bit_is_set(state.speed_status, SPEED_ENU_I)) {
1060  SetBit(state.speed_status, SPEED_ENU_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 */
1074  SetBit(state.speed_status, SPEED_NED_F);
1075 }
1076 
1078 {
1079  if (bit_is_set(state.speed_status, SPEED_ENU_F)) {
1080  return;
1081  }
1082 
1083  int errno = 0;
1084  if (state.ned_initialized_f) {
1085  if (bit_is_set(state.speed_status, SPEED_NED_F)) {
1087  } else if (bit_is_set(state.speed_status, SPEED_ENU_I)) {
1089  } else if (bit_is_set(state.speed_status, SPEED_NED_I)) {
1091  SetBit(state.speed_status, SPEED_NED_F);
1093  } else if (bit_is_set(state.speed_status, SPEED_ECEF_F)) {
1095  } else if (bit_is_set(state.speed_status, SPEED_ECEF_I)) {
1096  /* transform ecef_I -> ecef_f -> enu_f , set status bits */
1098  SetBit(state.speed_status, SPEED_ECEF_F);
1100  } else { /* could not get this representation, set errno */
1101  errno = 1;
1102  }
1103  } else if (state.utm_initialized_f) {
1104  if (bit_is_set(state.speed_status, SPEED_NED_F)) {
1106  } else if (bit_is_set(state.speed_status, SPEED_ENU_I)) {
1108  } else if (bit_is_set(state.speed_status, SPEED_NED_I)) {
1110  SetBit(state.speed_status, SPEED_NED_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 */
1124  SetBit(state.speed_status, SPEED_ENU_F);
1125 }
1126 
1128 {
1129  if (bit_is_set(state.speed_status, SPEED_ECEF_F)) {
1130  return;
1131  }
1132 
1133  if (bit_is_set(state.speed_status, SPEED_ECEF_I)) {
1135  } else if (bit_is_set(state.speed_status, SPEED_NED_F)) {
1137  } else if (bit_is_set(state.speed_status, SPEED_NED_I)) {
1138  /* transform ned_f -> ned_i -> ecef_i , set status bits */
1140  SetBit(state.speed_status, SPEED_NED_F);
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 */
1149  SetBit(state.speed_status, SPEED_ECEF_F);
1150 }
1151 
1153 {
1154  if (bit_is_set(state.speed_status, SPEED_HNORM_F)) {
1155  return;
1156  }
1157 
1158  if (bit_is_set(state.speed_status, SPEED_HNORM_I)) {
1160  } else if (bit_is_set(state.speed_status, SPEED_NED_F)) {
1162  } else if (bit_is_set(state.speed_status, SPEED_ENU_F)) {
1164  } else if (bit_is_set(state.speed_status, SPEED_NED_I)) {
1166  SetBit(state.speed_status, SPEED_NED_F);
1168  } else if (bit_is_set(state.speed_status, SPEED_ENU_I)) {
1170  SetBit(state.speed_status, SPEED_ENU_F);
1172  } else {
1173  return;
1174  }
1175  /* set bit to indicate this representation is computed */
1176  SetBit(state.speed_status, SPEED_HNORM_F);
1177 }
1178 
1180 {
1181  if (bit_is_set(state.speed_status, SPEED_HDIR_F)) {
1182  return;
1183  }
1184 
1185  if (bit_is_set(state.speed_status, SPEED_HDIR_I)) {
1187  } else if (bit_is_set(state.speed_status, SPEED_NED_F)) {
1189  } else if (bit_is_set(state.speed_status, SPEED_ENU_F)) {
1191  } else if (bit_is_set(state.speed_status, SPEED_NED_I)) {
1193  SetBit(state.speed_status, SPEED_NED_F);
1195  } else if (bit_is_set(state.speed_status, SPEED_ENU_I)) {
1197  SetBit(state.speed_status, SPEED_ENU_F);
1199  } else {
1200  return;
1201  }
1202  /* set bit to indicate this representation is computed */
1203  SetBit(state.speed_status, SPEED_HDIR_F);
1204 }
1209 /******************************************************************************
1210  * *
1211  * Transformation functions for the ACCELERATION representations *
1212  * *
1213  *****************************************************************************/
1218 {
1219  if (bit_is_set(state.accel_status, ACCEL_NED_I)) {
1220  return;
1221  }
1222 
1223  int errno = 0;
1224  if (bit_is_set(state.accel_status, ACCEL_NED_F)) {
1226  }
1227  else if (state.ned_initialized_i) {
1228  if (bit_is_set(state.accel_status, ACCEL_ECEF_I)) {
1230  } else if (bit_is_set(state.accel_status, ACCEL_ECEF_F)) {
1231  /* transform ecef_f -> ecef_i -> ned_i , set status bits */
1233  SetBit(state.accel_status, ACCEL_ECEF_I);
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 */
1247  SetBit(state.accel_status, ACCEL_NED_I);
1248 }
1249 
1251 {
1252  if (bit_is_set(state.accel_status, ACCEL_ECEF_I)) {
1253  return;
1254  }
1255 
1256  int errno = 0;
1257  if (bit_is_set(state.accel_status, ACCEL_ECEF_F)) {
1259  }
1260  else if (state.ned_initialized_i) {
1261  if (bit_is_set(state.accel_status, ACCEL_NED_I)) {
1263  } else if (bit_is_set(state.accel_status, ACCEL_NED_F)) {
1264  /* transform ned_f -> ned_i -> ecef_i , set status bits */
1266  SetBit(state.accel_status, ACCEL_NED_I);
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 */
1279  SetBit(state.accel_status, ACCEL_ECEF_I);
1280 }
1281 
1283 {
1284  if (bit_is_set(state.accel_status, ACCEL_NED_F)) {
1285  return;
1286  }
1287 
1288  int errno = 0;
1289  if (bit_is_set(state.accel_status, ACCEL_NED_I)) {
1291  }
1292  else if (state.ned_initialized_f) {
1293  if (bit_is_set(state.accel_status, ACCEL_ECEF_F)) {
1295  } else if (bit_is_set(state.accel_status, ACCEL_ECEF_I)) {
1296  /* transform ecef_i -> ecef_f -> ned_f , set status bits */
1298  SetBit(state.accel_status, ACCEL_ECEF_F);
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 */
1312  SetBit(state.accel_status, ACCEL_NED_F);
1313 }
1314 
1316 {
1317  if (bit_is_set(state.accel_status, ACCEL_ECEF_F)) {
1318  return;
1319  }
1320 
1321  int errno = 0;
1322  if (bit_is_set(state.accel_status, ACCEL_ECEF_I)) {
1324  }
1325  else if (state.ned_initialized_f) {
1326  if (bit_is_set(state.accel_status, ACCEL_NED_F)) {
1328  } else if (bit_is_set(state.accel_status, ACCEL_NED_I)) {
1329  /* transform ned_f -> ned_i -> ecef_i , set status bits */
1331  SetBit(state.accel_status, ACCEL_NED_F);
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 */
1344  SetBit(state.accel_status, ACCEL_ECEF_F);
1345 }
1348 /******************************************************************************
1349  * *
1350  * Transformation functions for the ANGULAR RATE representations *
1351  * *
1352  *****************************************************************************/
1357 {
1358  if (bit_is_set(state.rate_status, RATE_I)) {
1359  return;
1360  }
1361 
1362  if (bit_is_set(state.rate_status, RATE_F)) {
1364  } else {
1365  return;
1366  }
1367  /* set bit to indicate this representation is computed */
1368  SetBit(state.rate_status, RATE_I);
1369 }
1370 
1372 {
1373  if (bit_is_set(state.rate_status, RATE_F)) {
1374  return;
1375  }
1376 
1377  if (bit_is_set(state.rate_status, RATE_I)) {
1379  } else {
1380  return;
1381  }
1382  /* set bit to indicate this representation is computed */
1383  SetBit(state.rate_status, RATE_F);
1384 }
1385 
1389 /******************************************************************************
1390  * *
1391  * Transformation functions for the WIND- AND AIRSPEED representations *
1392  * *
1393  *****************************************************************************/
1398 {
1399  if (bit_is_set(state.wind_air_status, WINDSPEED_I)) {
1400  return;
1401  }
1402 
1403  if (bit_is_set(state.wind_air_status, WINDSPEED_F)) {
1406  } else {
1407  return;
1408  }
1409  /* set bit to indicate this representation is computed */
1410  SetBit(state.wind_air_status , WINDSPEED_I);
1411 }
1412 
1414 {
1415  if (bit_is_set(state.wind_air_status, DOWNWIND_I)) {
1416  return;
1417  }
1418 
1419  if (bit_is_set(state.wind_air_status, DOWNWIND_F)) {
1421  } else {
1422  return;
1423  }
1424  /* set bit to indicate this representation is computed */
1425  SetBit(state.wind_air_status, DOWNWIND_I);
1426 }
1427 
1429 {
1430  if (bit_is_set(state.wind_air_status, AIRSPEED_I)) {
1431  return;
1432  }
1433 
1434  if (bit_is_set(state.wind_air_status, AIRSPEED_F)) {
1436  } else {
1437  return;
1438  }
1439  /* set bit to indicate this representation is computed */
1440  SetBit(state.wind_air_status, AIRSPEED_I);
1441 }
1442 
1444 {
1445  if (bit_is_set(state.wind_air_status, WINDSPEED_F)) {
1446  return;
1447  }
1448 
1449  if (bit_is_set(state.wind_air_status, WINDSPEED_I)) {
1452  } else {
1453  return;
1454  }
1455  /* set bit to indicate this representation is computed */
1457 }
1458 
1460 {
1461  if (bit_is_set(state.wind_air_status, DOWNWIND_F)) {
1462  return;
1463  }
1464 
1465  if (bit_is_set(state.wind_air_status, DOWNWIND_I)) {
1467  } else {
1468  return;
1469  }
1470  /* set bit to indicate this representation is computed */
1471  SetBit(state.wind_air_status, DOWNWIND_F);
1472 }
1473 
1475 {
1476  if (bit_is_set(state.wind_air_status, AIRSPEED_F)) {
1477  return;
1478  }
1479 
1480  if (bit_is_set(state.wind_air_status, AIRSPEED_I)) {
1482  } else {
1483  return;
1484  }
1485  /* set bit to indicate this representation is computed */
1486  SetBit(state.wind_air_status, AIRSPEED_F);
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)
Definition: pprz_algebra.h:765
#define SPEEDS_BFP_OF_REAL(_ef, _ei)
Definition: pprz_algebra.h:789
#define ACCELS_BFP_OF_REAL(_ef, _ei)
Definition: pprz_algebra.h:801
#define RATES_FLOAT_OF_BFP(_rf, _ri)
Definition: pprz_algebra.h:759
#define SPEEDS_FLOAT_OF_BFP(_ef, _ei)
Definition: pprz_algebra.h:783
#define ACCELS_FLOAT_OF_BFP(_ef, _ei)
Definition: pprz_algebra.h:795
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)
Definition: pprz_geodetic.h:96
#define ENU_OF_UTM_DIFF(_pos, _utm1, _utm2)
Definition: pprz_geodetic.h:78
#define NED_OF_UTM_DIFF(_pos, _utm1, _utm2)
Definition: pprz_geodetic.h:84
#define UTM_OF_ENU_ADD(_utm, _pos, _utm0)
Definition: pprz_geodetic.h:90
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
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
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.
Definition: vl53l1_types.h:88
int int32_t
Typedef defining 32 bit int type.
Definition: vl53l1_types.h:83
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98