Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ahrs.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2010 The Paparazzi Team
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, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
28 #include "subsystems/ahrs.h"
29 
30 #ifndef PRIMARY_AHRS
31 #error "PRIMARY_AHRS not set!"
32 #else
33 PRINT_CONFIG_VAR(PRIMARY_AHRS)
34 #endif
35 
36 #ifdef SECONDARY_AHRS
37 PRINT_CONFIG_VAR(SECONDARY_AHRS)
38 #endif
39 
40 #define __RegisterAhrs(_x) _x ## _register()
41 #define _RegisterAhrs(_x) __RegisterAhrs(_x)
42 #define RegisterAhrs(_x) _RegisterAhrs(_x)
43 
45 #ifndef AHRS_NB_IMPL
46 #define AHRS_NB_IMPL 2
47 #endif
48 
50 struct AhrsImpl {
52 };
53 
56 
58 {
59  int i;
60  for (i=0; i < AHRS_NB_IMPL; i++) {
61  if (ahrs_impls[i].enable == NULL) {
63  break;
64  }
65  }
66 }
67 
68 void ahrs_init(void)
69 {
70  int i;
71  for (i=0; i < AHRS_NB_IMPL; i++) {
72  ahrs_impls[i].enable = NULL;
73  }
74 
76 #ifdef SECONDARY_AHRS
77  RegisterAhrs(SECONDARY_AHRS);
78 #endif
79 
80  // enable primary AHRS by default
81  ahrs_switch(0);
82 }
83 
85 {
86  if (idx >= AHRS_NB_IMPL) { return -1; }
87  if (ahrs_impls[idx].enable == NULL) { return -1; }
88  /* first disable other AHRS output */
89  int i;
90  for (i=0; i < AHRS_NB_IMPL; i++) {
91  if (ahrs_impls[i].enable != NULL) {
93  }
94  }
95  /* enable requested AHRS */
96  ahrs_impls[idx].enable(TRUE);
97  ahrs_output_idx = idx;
98  return ahrs_output_idx;
99 }
Dispatcher to register actual AHRS implementations.
AhrsEnableOutput enable
Definition: ahrs.c:51
#define PRIMARY_AHRS
Definition: ahrs_chimu.h:40
#define RegisterAhrs(_x)
Definition: ahrs.c:42
void ahrs_init(void)
AHRS initialization.
Definition: ahrs.c:68
struct AhrsImpl ahrs_impls[AHRS_NB_IMPL]
Definition: ahrs.c:54
#define FALSE
Definition: std.h:5
#define AHRS_NB_IMPL
maximum number of AHRS implementations that can register
Definition: ahrs.c:46
#define TRUE
Definition: std.h:4
int ahrs_switch(uint8_t idx)
Switch to the output of another AHRS impl.
Definition: ahrs.c:84
void ahrs_register_impl(AhrsEnableOutput enable)
Register an AHRS implementation.
Definition: ahrs.c:57
references a registered AHRS implementation
Definition: ahrs.c:50
uint8_t ahrs_output_idx
Definition: ahrs.c:55
bool_t(* AhrsEnableOutput)(bool_t)
Definition: ahrs.h:54
unsigned char uint8_t
Definition: types.h:14