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
hs_gyro.c
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 #include <inttypes.h>
25 
26 #include "std.h"
27 #include "mcu.h"
28 #include "mcu_periph/sys_time.h"
29 #include "led.h"
30 #include "mcu_periph/uart.h"
31 #include "messages.h"
33 
34 #include "subsystems/imu.h"
35 
36 
37 #ifndef MEASURED_SENSOR
38 #define MEASURED_SENSOR gyro_unscaled.p
39 #define MEASURED_SENSOR_NB 0
40 #endif
41 
42 
43 static inline void main_init( void );
44 static inline void main_periodic_task( void );
45 static inline void main_event_task( void );
46 
47 static inline void on_gyro_accel_event(void);
48 static inline void on_accel_event(void);
49 static inline void on_mag_event(void);
50 
51 int main( void ) {
52  main_init();
53  while(1) {
57  }
58  return 0;
59 }
60 
61 static inline void main_init( void ) {
62 
63  mcu_init();
65  imu_init();
66 
68 }
69 
70 static inline void main_periodic_task( void ) {
71  RunOnceEvery(100, {
72  LED_TOGGLE(3);
73  DOWNLINK_SEND_ALIVE(DefaultChannel, DefaultDevice, 16, MD5SUM);
74  });
75  imu_periodic();
76  RunOnceEvery(10, { LED_PERIODIC();});
77 }
78 
79 static inline void main_event_task( void ) {
80 
82 
83 }
84 
85 
86 static inline void on_accel_event(void) {
87 }
88 
89 #define NB_SAMPLES 20
90 
91 static inline void on_gyro_accel_event(void) {
92  ImuScaleGyro();
93  ImuScaleAccel();
94 
95  LED_TOGGLE(2);
96 
97  static uint8_t cnt;
98  static int32_t samples[NB_SAMPLES];
99  const uint8_t axis = MEASURED_SENSOR_NB;
100  cnt++;
101  if (cnt > NB_SAMPLES) cnt = 0;
102  samples[cnt] = imu.MEASURED_SENSOR;
103  if (cnt == NB_SAMPLES-1) {
104  DOWNLINK_SEND_IMU_HS_GYRO(DefaultChannel, DefaultDevice, &axis, NB_SAMPLES, samples);
105  }
106 
107  if (cnt == 10) {
108  DOWNLINK_SEND_IMU_GYRO_RAW(DefaultChannel, DefaultDevice,
111  &imu.gyro_unscaled.r);
112  }
113 
114 
115 }
116 
117 
118 static inline void on_mag_event(void) {
119 
120 }
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
void imu_periodic(void)
Definition: imu_b2_arch.c:83
int32_t p
in rad/s^2 with INT32_RATE_FRAC
struct Int32Rates gyro_unscaled
unscaled gyroscope measurements
Definition: imu.h:48
int main(void)
Definition: hs_gyro.c:51
#define ImuScaleGyro(_imu)
Definition: imu_nps.h:89
#define ImuEvent(_gyro_handler, _accel_handler, _mag_handler)
Definition: imu_navgo.h:58
#define PERIODIC_FREQUENCY
Definition: imu_aspirin2.c:54
#define mcu_int_enable()
Definition: mcu_arch.h:32
#define MEASURED_SENSOR_NB
Definition: hs_gyro.c:39
Architecture independent timing functions.
Inertial Measurement Unit interface.
int sys_time_register_timer(float duration, sys_time_cb cb)
Register a new system timer.
Definition: sys_time.c:35
#define LED_TOGGLE(i)
Definition: led_hw.h:30
static bool_t sys_time_check_and_ack_timer(tid_t id)
Definition: sys_time.h:90
static void main_init(void)
Definition: hs_gyro.c:61
signed long int32_t
Definition: types.h:19
static void on_gyro_accel_event(void)
Definition: hs_gyro.c:91
#define LED_PERIODIC()
Definition: led_hw.h:8
arch independent mcu ( Micro Controller Unit ) utilities
unsigned char uint8_t
Definition: types.h:14
static void main_periodic_task(void)
Definition: hs_gyro.c:70
int32_t q
in rad/s^2 with INT32_RATE_FRAC
arch independent LED (Light Emitting Diodes) API
#define ImuScaleAccel(_imu)
Definition: imu_analog.h:49
struct Imu imu
global IMU state
Definition: imu_aspirin2.c:50
int32_t r
in rad/s^2 with INT32_RATE_FRAC
void imu_init(void)
Definition: imu.c:32
static void main_event_task(void)
Definition: hs_gyro.c:79
void mcu_init(void)
Definition: mcu.c:57
static void on_accel_event(void)
Definition: hs_gyro.c:86
static void on_mag_event(void)
Definition: hs_gyro.c:118
#define NB_SAMPLES
Definition: hs_gyro.c:89