Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
imu_analog.c
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 #include "imu_analog.h"
23 #include "mcu_periph/adc.h"
24 
25 volatile bool_t analog_imu_available;
27 
29 
30 void imu_impl_init(void) {
31 
33  imu_overrun = 0;
34 
35 #ifdef ADC_CHANNEL_GYRO_P
36  adc_buf_channel(ADC_CHANNEL_GYRO_P, &analog_imu_adc_buf[0], ADC_CHANNEL_GYRO_NB_SAMPLES);
37 #endif
38 #ifdef ADC_CHANNEL_GYRO_Q
39  adc_buf_channel(ADC_CHANNEL_GYRO_Q, &analog_imu_adc_buf[1], ADC_CHANNEL_GYRO_NB_SAMPLES);
40 #endif
41 #ifdef ADC_CHANNEL_GYRO_R
42  adc_buf_channel(ADC_CHANNEL_GYRO_R, &analog_imu_adc_buf[2], ADC_CHANNEL_GYRO_NB_SAMPLES);
43 #endif
44 #ifdef ADC_CHANNEL_ACCEL_X
45  adc_buf_channel(ADC_CHANNEL_ACCEL_X, &analog_imu_adc_buf[3], ADC_CHANNEL_ACCEL_NB_SAMPLES);
46 #endif
47 #ifdef ADC_CHANNEL_ACCEL_Y
48  adc_buf_channel(ADC_CHANNEL_ACCEL_Y, &analog_imu_adc_buf[4], ADC_CHANNEL_ACCEL_NB_SAMPLES);
49 #endif
50 #ifdef ADC_CHANNEL_ACCEL_Z
51  adc_buf_channel(ADC_CHANNEL_ACCEL_Z, &analog_imu_adc_buf[5], ADC_CHANNEL_ACCEL_NB_SAMPLES);
52 #endif
53 
54 }
55 
56 void imu_periodic(void) {
57  // Actual Nr of ADC measurements per channel per periodic loop
58  static int last_head = 0;
59 
60  imu_overrun = analog_imu_adc_buf[0].head - last_head;
61  if (imu_overrun < 0)
62  imu_overrun += ADC_CHANNEL_GYRO_NB_SAMPLES;
63  last_head = analog_imu_adc_buf[0].head;
64 
65  // Read All Measurements
66 #ifdef ADC_CHANNEL_GYRO_P
67  imu.gyro_unscaled.p = analog_imu_adc_buf[0].sum / ADC_CHANNEL_GYRO_NB_SAMPLES;
68 #endif
69 #ifdef ADC_CHANNEL_GYRO_Q
70  imu.gyro_unscaled.q = analog_imu_adc_buf[1].sum / ADC_CHANNEL_GYRO_NB_SAMPLES;
71 #endif
72 #ifdef ADC_CHANNEL_GYRO_R
73  imu.gyro_unscaled.r = analog_imu_adc_buf[2].sum / ADC_CHANNEL_GYRO_NB_SAMPLES;
74 #endif
75 #ifdef ADC_CHANNEL_ACCEL_X
76  imu.accel_unscaled.x = analog_imu_adc_buf[3].sum / ADC_CHANNEL_ACCEL_NB_SAMPLES;
77 #endif
78 #ifdef ADC_CHANNEL_ACCEL_Y
79  imu.accel_unscaled.y = analog_imu_adc_buf[4].sum / ADC_CHANNEL_ACCEL_NB_SAMPLES;
80 #endif
81 #ifdef ADC_CHANNEL_ACCEL_Z
82  imu.accel_unscaled.z = analog_imu_adc_buf[5].sum / ADC_CHANNEL_ACCEL_NB_SAMPLES;
83 #endif
84 
86 }
volatile bool_t analog_imu_available
Definition: imu_analog.c:25
int32_t p
in rad/s with INT32_RATE_FRAC
void adc_buf_channel(uint8_t adc_channel, struct adc_buf *s, uint8_t av_nb_sample)
Registers a buffer to be used to store the specified converted channel Usage:
Definition: adc_arch.c:59
int imu_overrun
Definition: imu_analog.c:26
struct Int32Rates gyro_unscaled
unscaled gyroscope measurements
Definition: imu.h:49
arch independent ADC (Analog to Digital Converter) API
uint32_t sum
Definition: adc.h:54
static struct adc_buf analog_imu_adc_buf[NB_ANALOG_IMU_ADC]
Definition: imu_analog.c:28
#define FALSE
Definition: imu_chimu.h:141
struct Int32Vect3 accel_unscaled
unscaled accelerometer measurements
Definition: imu.h:50
struct Imu imu
global IMU state
Definition: imu_aspirin2.c:47
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
Definition: adc.h:53
void imu_impl_init(void)
Definition: imu_analog.c:30
#define TRUE
Definition: imu_chimu.h:144
#define NB_ANALOG_IMU_ADC
Definition: imu_analog.h:26
void imu_periodic(void)
Definition: imu_analog.c:56
int32_t q
in rad/s with INT32_RATE_FRAC
int32_t r
in rad/s with INT32_RATE_FRAC
uint8_t head
Definition: adc.h:56