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