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_um6.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Michal Podhradsky
3  * Utah State University, http://aggieair.usu.edu/
4  *
5  * This file is part of paparazzi.
6  *
7  * paparazzi is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * paparazzi is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with paparazzi; see the file COPYING. If not, write to
19  * the Free Software Foundation, 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
33 #ifndef IMU_UM6_H
34 #define IMU_UM6_H
35 
36 #include "generated/airframe.h"
37 #include "subsystems/imu.h"
38 #include "mcu_periph/uart.h"
39 #include "subsystems/ahrs.h"
40 
41 #define __UM6Link(dev, _x) dev##_x
42 #define _UM6Link(dev, _x) __UM6Link(dev, _x)
43 #define UM6Link(_x) _UM6Link(UM6_LINK, _x)
44 
45 #define UM6Buffer() UM6Link(ChAvailable())
46 
47 #ifdef ImuScaleGyro
48 #undef ImuScaleGyro
49 #endif
50 #define ImuScaleGyro(_imu) {}
51 
52 #ifdef ImuScaleAccel
53 #undef ImuScaleAccel
54 #endif
55 #define ImuScaleAccel(_imu) {}
56 
57 #ifdef ImuScaleMag
58 #undef ImuScaleMag
59 #endif
60 #define ImuScaleMag(_imu) {}
61 
62 #define IMU_UM6_BUFFER_LENGTH 32
63 #define IMU_UM6_DATA_OFFSET 5
64 #define IMU_UM6_LONG_DELAY 4000000
65 
66 #define IMU_UM6_COMMUNICATION_REG 0x00
67 #define IMU_UM6_MISC_CONFIG_REG 0x01
68 #define IMU_UM6_GET_FIRMWARE_CMD 0xAA
69 #define IMU_UM6_ZERO_GYROS_CMD 0xAC
70 #define IMU_UM6_RESET_EKF_CMD 0xAD
71 #define IMU_UM6_GET_DATA 0xAE
72 #define IMU_UM6_SET_ACCEL_REF 0xAF
73 #define IMU_UM6_SET_MAG_REF 0xB0
74 
75 #define IMU_UM6_GYRO_PROC 0x5C
76 #define IMU_UM6_ACCEL_PROC 0x5E
77 #define IMU_UM6_MAG_PROC 0x60
78 #define IMU_UM6_EULER 0x62
79 #define IMU_UM6_QUAT 0x64
80 
81 extern void UM6_packet_read_message(void);
82 extern void UM6_packet_parse(uint8_t c);
83 
84 extern struct UM6Packet UM6_packet;
85 
86 extern uint8_t PacketLength;
87 extern uint8_t PacketType;
88 extern uint8_t PacketAddr;
89 
90 extern uint16_t chk_calc;
91 extern uint16_t chk_rec;
92 
93 extern enum UM6Status UM6_status;
94 extern volatile uint8_t UM6_imu_available;
95 
96 extern struct FloatEulers UM6_eulers;
97 extern struct FloatQuat UM6_quat;
98 
99 struct UM6Packet {
106 };
107 
115 };
116 
117 enum UM6Status {
120 };
121 
122 #define imu_um6_event(_callback1, _callback2, _callback3) { \
123  if (UM6Buffer()) { \
124  ReadUM6Buffer(); \
125  } \
126  if (UM6_packet.msg_available) { \
127  UM6_packet.msg_available = FALSE; \
128  UM6_packet_read_message(); \
129  _callback1(); \
130  _callback2(); \
131  _callback3(); \
132  } \
133  }
134 
135 #define ReadUM6Buffer() { \
136  while (UM6Link(ChAvailable())&&!UM6_packet.msg_available) \
137  UM6_packet_parse(UM6Link(Getch())); \
138  }
139 
140 #define ImuEvent(_gyro_handler, _accel_handler, _mag_handler) { \
141  imu_um6_event(_gyro_handler, _accel_handler, _mag_handler); \
142 }
143 
144 #endif /* IMU_UM6_H*/
struct UM6Packet UM6_packet
Definition: imu_um6.c:37
unsigned short uint16_t
Definition: types.h:16
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
Attitude and Heading Reference System interface.
uint8_t msg_buf[IMU_UM6_BUFFER_LENGTH]
Definition: imu_um6.h:103
void UM6_packet_parse(uint8_t c)
Definition: imu_um6.c:282
uint16_t chk_rec
Definition: imu_um6.c:47
UM6PacketStatus
Definition: imu_um6.h:108
uint8_t msg_idx
Definition: imu_um6.h:105
euler angles
UM6Status
Definition: imu_um6.h:117
#define IMU_UM6_BUFFER_LENGTH
Definition: imu_um6.h:62
Roation quaternion.
volatile uint8_t UM6_imu_available
unsigned long uint32_t
Definition: types.h:18
struct FloatEulers UM6_eulers
Definition: imu_um6.c:52
bool_t msg_available
Definition: imu_um6.h:100
struct FloatQuat UM6_quat
Definition: imu_um6.c:53
Inertial Measurement Unit interface.
void UM6_packet_read_message(void)
Definition: imu_um6.c:204
uint8_t PacketLength
Definition: imu_um6.c:41
uint8_t status
Definition: imu_um6.h:104
uint16_t chk_calc
Definition: imu_um6.c:46
enum UM6Status UM6_status
Definition: imu_um6.c:44
unsigned char uint8_t
Definition: types.h:14
uint32_t hdr_error
Definition: imu_um6.h:102
uint8_t PacketAddr
Definition: imu_um6.c:43
uint8_t PacketType
Definition: imu_um6.c:42
uint32_t chksm_error
Definition: imu_um6.h:101