Paparazzi UAS  v4.2.2_stable-4-gcc32f65
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
imu_b2.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Copyright (C) 2008-2009 Antoine Drouin <poinix@gmail.com>
5  *
6  * This file is part of paparazzi.
7  *
8  * paparazzi is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2, or (at your option)
11  * any later version.
12  *
13  * paparazzi is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with paparazzi; see the file COPYING. If not, write to
20  * the Free Software Foundation, 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
24 #ifndef IMU_B2_H
25 #define IMU_B2_H
26 
27 #include "subsystems/imu.h"
28 #include "generated/airframe.h"
29 
30 #include "peripherals/max1168.h"
31 
32 /* type of magnetometer */
33 #define IMU_B2_MAG_NONE 0
34 #define IMU_B2_MAG_MS2100 1
35 #define IMU_B2_MAG_AMI601 2
36 #define IMU_B2_MAG_HMC5843 3
37 #define IMU_B2_MAG_HMC58XX 4
38 
39 
40 #ifdef IMU_B2_VERSION_1_0
41 /* Default IMU b2 sensors connection */
42 #if !defined IMU_GYRO_P_CHAN & !defined IMU_GYRO_Q_CHAN & !defined IMU_GYRO_R_CHAN
43 #define IMU_GYRO_P_CHAN 1
44 #define IMU_GYRO_Q_CHAN 0
45 #define IMU_GYRO_R_CHAN 2
46 #endif
47 #if !defined IMU_ACCEL_X_CHAN & !defined IMU_ACCEL_Y_CHAN & !defined IMU_ACCEL_Z_CHAN
48 #define IMU_ACCEL_X_CHAN 3
49 #define IMU_ACCEL_Y_CHAN 5
50 #define IMU_ACCEL_Z_CHAN 6
51 #endif
52 #if !defined IMU_MAG_X_CHAN & !defined IMU_MAG_Y_CHAN & !defined IMU_MAG_Z_CHAN
53 #define IMU_MAG_X_CHAN 0
54 #define IMU_MAG_Y_CHAN 1
55 #define IMU_MAG_Z_CHAN 2
56 #endif
57 
58 #if !defined IMU_GYRO_P_SIGN & !defined IMU_GYRO_Q_SIGN & !defined IMU_GYRO_R_SIGN
59 #define IMU_GYRO_P_SIGN 1
60 #define IMU_GYRO_Q_SIGN -1
61 #define IMU_GYRO_R_SIGN -1
62 #endif
63 #if !defined IMU_ACCEL_X_SIGN & !defined IMU_ACCEL_Y_SIGN & !defined IMU_ACCEL_Z_SIGN
64 #define IMU_ACCEL_X_SIGN -1
65 #define IMU_ACCEL_Y_SIGN -1
66 #define IMU_ACCEL_Z_SIGN -1
67 #endif
68 #if !defined IMU_MAG_X_SIGN & !defined IMU_MAG_Y_SIGN & !defined IMU_MAG_Z_SIGN
69 #define IMU_MAG_X_SIGN 1
70 #define IMU_MAG_Y_SIGN -1
71 #define IMU_MAG_Z_SIGN -1
72 #endif
73 #endif /* IMU_B2_VERSION_1_0 */
74 
75 
76 #ifdef IMU_B2_VERSION_1_1
77 /* Default IMU b2 sensors connection */
78 #if !defined IMU_GYRO_P_CHAN & !defined IMU_GYRO_Q_CHAN & !defined IMU_GYRO_R_CHAN
79 #define IMU_GYRO_P_CHAN 1
80 #define IMU_GYRO_Q_CHAN 0
81 #define IMU_GYRO_R_CHAN 2
82 #endif
83 #if !defined IMU_ACCEL_X_CHAN & !defined IMU_ACCEL_Y_CHAN & !defined IMU_ACCEL_Z_CHAN
84 #define IMU_ACCEL_X_CHAN 5
85 #define IMU_ACCEL_Y_CHAN 3
86 #define IMU_ACCEL_Z_CHAN 4
87 #endif
88 #if !defined IMU_MAG_X_CHAN & !defined IMU_MAG_Y_CHAN & !defined IMU_MAG_Z_CHAN
89 #define IMU_MAG_X_CHAN 0
90 #define IMU_MAG_Y_CHAN 1
91 #define IMU_MAG_Z_CHAN 2
92 #endif
93 
94 #if !defined IMU_GYRO_P_SIGN & !defined IMU_GYRO_Q_SIGN & !defined IMU_GYRO_R_SIGN
95 #define IMU_GYRO_P_SIGN 1
96 #define IMU_GYRO_Q_SIGN -1
97 #define IMU_GYRO_R_SIGN -1
98 #endif
99 #if !defined IMU_ACCEL_X_SIGN & !defined IMU_ACCEL_Y_SIGN & !defined IMU_ACCEL_Z_SIGN
100 #define IMU_ACCEL_X_SIGN -1
101 #define IMU_ACCEL_Y_SIGN -1
102 #define IMU_ACCEL_Z_SIGN -1
103 #endif
104 #if !defined IMU_MAG_X_SIGN & !defined IMU_MAG_Y_SIGN & !defined IMU_MAG_Z_SIGN
105 #define IMU_MAG_X_SIGN 1
106 #define IMU_MAG_Y_SIGN -1
107 #define IMU_MAG_Z_SIGN -1
108 #endif
109 #endif /* IMU_B2_VERSION_1_1 */
110 
111 #ifdef IMU_B2_VERSION_1_2
112 /* Default IMU b2 sensors connection */
113 #if !defined IMU_GYRO_P_CHAN & !defined IMU_GYRO_Q_CHAN & !defined IMU_GYRO_R_CHAN
114 #define IMU_GYRO_P_CHAN 1
115 #define IMU_GYRO_Q_CHAN 0
116 #define IMU_GYRO_R_CHAN 2
117 #endif
118 #if !defined IMU_ACCEL_X_CHAN & !defined IMU_ACCEL_Y_CHAN & !defined IMU_ACCEL_Z_CHAN
119 #define IMU_ACCEL_X_CHAN 4
120 #define IMU_ACCEL_Y_CHAN 5
121 #define IMU_ACCEL_Z_CHAN 3
122 #endif
123 #if !defined IMU_MAG_X_CHAN & !defined IMU_MAG_Y_CHAN & !defined IMU_MAG_Z_CHAN
124 #define IMU_MAG_X_CHAN 0
125 #define IMU_MAG_Y_CHAN 1
126 #define IMU_MAG_Z_CHAN 2
127 #endif
128 
129 #if !defined IMU_GYRO_P_SIGN & !defined IMU_GYRO_Q_SIGN & !defined IMU_GYRO_R_SIGN
130 #define IMU_GYRO_P_SIGN 1
131 #define IMU_GYRO_Q_SIGN -1
132 #define IMU_GYRO_R_SIGN -1
133 #endif
134 #if !defined IMU_ACCEL_X_SIGN & !defined IMU_ACCEL_Y_SIGN & !defined IMU_ACCEL_Z_SIGN
135 #define IMU_ACCEL_X_SIGN 1
136 #define IMU_ACCEL_Y_SIGN -1
137 #define IMU_ACCEL_Z_SIGN 1
138 #endif
139 #if !defined IMU_MAG_X_SIGN & !defined IMU_MAG_Y_SIGN & !defined IMU_MAG_Z_SIGN
140 #define IMU_MAG_X_SIGN -1
141 #define IMU_MAG_Y_SIGN -1
142 #define IMU_MAG_Z_SIGN 1
143 #endif
144 #endif /* IMU_B2_VERSION_1_2 */
145 
146 
147 #if defined IMU_B2_MAG_TYPE && IMU_B2_MAG_TYPE == IMU_B2_MAG_MS2100
148 #include "peripherals/ms2100.h"
149 #define ImuMagEvent(_mag_handler) { \
150  if (ms2100_status == MS2100_DATA_AVAILABLE) { \
151  imu.mag_unscaled.x = ms2100_values[IMU_MAG_X_CHAN]; \
152  imu.mag_unscaled.y = ms2100_values[IMU_MAG_Y_CHAN]; \
153  imu.mag_unscaled.z = ms2100_values[IMU_MAG_Z_CHAN]; \
154  ms2100_status = MS2100_IDLE; \
155  _mag_handler(); \
156  } \
157  }
158 #elif defined IMU_B2_MAG_TYPE && IMU_B2_MAG_TYPE == IMU_B2_MAG_AMI601
159 #include "peripherals/ami601.h"
160 #define foo_handler() {}
161 #define ImuMagEvent(_mag_handler) { \
162  AMI601Event(foo_handler); \
163  if (ami601_status == AMI601_DATA_AVAILABLE) { \
164  imu.mag_unscaled.x = ami601_values[IMU_MAG_X_CHAN]; \
165  imu.mag_unscaled.y = ami601_values[IMU_MAG_Y_CHAN]; \
166  imu.mag_unscaled.z = ami601_values[IMU_MAG_Z_CHAN]; \
167  ami601_status = AMI601_IDLE; \
168  _mag_handler(); \
169  } \
170  }
171 #elif defined IMU_B2_MAG_TYPE && IMU_B2_MAG_TYPE == IMU_B2_MAG_HMC5843
172 #include "peripherals/hmc5843.h"
173 #define foo_handler() {}
174 #define ImuMagEvent(_mag_handler) { \
175  MagEvent(foo_handler); \
176  if (hmc5843.data_available) { \
177  imu.mag_unscaled.x = hmc5843.data.value[IMU_MAG_X_CHAN]; \
178  imu.mag_unscaled.y = hmc5843.data.value[IMU_MAG_Y_CHAN]; \
179  imu.mag_unscaled.z = hmc5843.data.value[IMU_MAG_Z_CHAN]; \
180  _mag_handler(); \
181  hmc5843.data_available = FALSE; \
182  } \
183  }
184 #elif defined IMU_B2_MAG_TYPE && IMU_B2_MAG_TYPE == IMU_B2_MAG_HMC58XX
185 #include "peripherals/hmc58xx.h"
186 #define foo_handler() {}
187 #define ImuMagEvent(_mag_handler) { \
188  MagEvent(foo_handler); \
189  if (hmc58xx_data_available) { \
190  imu.mag_unscaled.x = hmc58xx_data.x; \
191  imu.mag_unscaled.y = hmc58xx_data.y; \
192  imu.mag_unscaled.z = hmc58xx_data.z; \
193  _mag_handler(); \
194  hmc58xx_data_available = FALSE; \
195  } \
196  }
197 #else
198 #define ImuMagEvent(_mag_handler) {}
199 #define ImuScaleMag(_imu) {}
200 #endif
201 
202 
203 #define ImuEvent(_gyro_handler, _accel_handler, _mag_handler) { \
204  if (max1168_status == STA_MAX1168_DATA_AVAILABLE) { \
205  imu.gyro_unscaled.p = max1168_values[IMU_GYRO_P_CHAN]; \
206  imu.gyro_unscaled.q = max1168_values[IMU_GYRO_Q_CHAN]; \
207  imu.gyro_unscaled.r = max1168_values[IMU_GYRO_R_CHAN]; \
208  imu.accel_unscaled.x = max1168_values[IMU_ACCEL_X_CHAN]; \
209  imu.accel_unscaled.y = max1168_values[IMU_ACCEL_Y_CHAN]; \
210  imu.accel_unscaled.z = max1168_values[IMU_ACCEL_Z_CHAN]; \
211  max1168_status = STA_MAX1168_IDLE; \
212  _gyro_handler(); \
213  _accel_handler(); \
214  } \
215  ImuMagEvent(_mag_handler); \
216  }
217 
218 
219 /* underlying architecture */
220 #include "subsystems/imu/imu_b2_arch.h"
221 /* must be implemented by underlying architecture */
222 extern void imu_b2_arch_init(void);
223 
224 
225 #endif /* IMU_B2_H */
void imu_b2_arch_init(void)
Definition: imu_b2_arch.c:42
Inertial Measurement Unit interface.