Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
imu_analog.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 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 
22 #ifndef IMU_ANALOG_H
23 #define IMU_ANALOG_H
24 
25 
26 #define NB_ANALOG_IMU_ADC 6
27 
28 // if not all gyros are used, override the ImuScaleGyro handler
29 #if defined ADC_CHANNEL_GYRO_P && defined ADC_CHANNEL_GYRO_Q && ! defined ADC_CHANNEL_GYRO_R
30 
31 #define IMU_GYRO_R_NEUTRAL 0
32 #define ImuScaleGyro(_imu) { \
33  _imu.gyro.p = ((_imu.gyro_unscaled.p - _imu.gyro_neutral.p)*IMU_GYRO_P_SIGN*IMU_GYRO_P_SENS_NUM)/IMU_GYRO_P_SENS_DEN; \
34  _imu.gyro.q = ((_imu.gyro_unscaled.q - _imu.gyro_neutral.q)*IMU_GYRO_Q_SIGN*IMU_GYRO_Q_SENS_NUM)/IMU_GYRO_Q_SENS_DEN; \
35  }
36 
37 #elif defined ADC_CHANNEL_GYRO_P && ! defined ADC_CHANNEL_GYRO_Q && ! defined ADC_CHANNEL_GYRO_R
38 
39 #define IMU_GYRO_Q_NEUTRAL 0
40 #define IMU_GYRO_R_NEUTRAL 0
41 #define ImuScaleGyro(_imu) { \
42  _imu.gyro.p = ((_imu.gyro_unscaled.p - _imu.gyro_neutral.p)*IMU_GYRO_P_SIGN*IMU_GYRO_P_SENS_NUM)/IMU_GYRO_P_SENS_DEN; \
43  }
44 
45 #endif
46 
47 // if we don't have any accelerometers, set an empty ImuScaleAccel handler
48 #if ! defined ADC_CHANNEL_ACCEL_X && ! defined ADC_CHANNEL_ACCEL_Z && ! defined ADC_CHANNEL_ACCEL_Z
49 #define ImuScaleAccel(_imu) {}
50 #endif
51 
52 /*
53  * we include imh.h after the definitions of ImuScale so we can override the default handlers
54  */
55 #include "subsystems/imu.h"
56 
57 
58 extern volatile bool_t analog_imu_available;
59 extern int imu_overrun;
60 
61 #define ImuEvent(_gyro_handler, _accel_handler, _mag_handler) { \
62  if (analog_imu_available) { \
63  analog_imu_available = FALSE; \
64  _gyro_handler(); \
65  _accel_handler(); \
66  } \
67  ImuMagEvent(_mag_handler); \
68  }
69 
70 #define ImuMagEvent(_mag_handler) { \
71  if (0) { \
72  _mag_handler(); \
73  } \
74  }
75 
76 
77 
78 
79 #endif /* IMU_ANALOG_H */
int imu_overrun
Definition: imu_analog.c:26
Inertial Measurement Unit interface.
volatile bool_t analog_imu_available
Definition: imu_analog.c:25