Paparazzi UAS  v5.14.0_stable-0-g3f680d1
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
imu_chimu.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011 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 /*---------------------------------------------------------------------------
23  Copyright (c) Ryan Mechatronics 2008. All Rights Reserved.
24 
25  File: *.c
26 
27  Description: CHIMU Protocol Parser
28 
29 
30  Public Functions:
31  CHIMU_Init Create component instance
32  CHIMU_Done Free component instance
33  CHIMU_Parse Parse the RX byte stream message
34 
35  Applicable Documents:
36  CHIMU parsing documentation
37 
38 
39  ---------------------------------------------------------------------------*/
40 
41 #include "paparazzi.h"
42 
43 //---[Defines]------------------------------------------------------
44 #ifndef CHIMU_DEFINED_H
45 #define CHIMU_DEFINED_H
46 
47 #define CHIMU_STX 0xae
48 #define CHIMU_BROADCAST 0xaa
49 
50 // Message ID's that go TO the CHIMU
51 #define MSG00_PING 0x00
52 #define MSG01_BIAS 0x01
53 #define MSG02_DACMODE 0x02
54 #define MSG03_CALACC 0x03
55 #define MSG04_CALMAG 0x04
56 #define MSG05_CALRATE 0x05
57 #define MSG06_CONFIGCLR 0x06
58 #define MSG07_CONFIGSET 0x07
59 #define MSG08_SAVEGYROBIAS 0x08
60 #define MSG09_ESTIMATOR 0x09
61 #define MSG0A_SFCHECK 0x0A
62 #define MSG0B_CENTRIP 0x0B
63 #define MSG0C_INITGYROS 0x0C
64 #define MSG0D_DEVICEID 0x0D
65 #define MSG0E_REFVECTOR 0x0E
66 #define MSG0F_RESET 0x0F
67 #define MSG10_UARTSETTINGS 0x10
68 #define MSG11_SERIALNUMBER 0x11
69 
70 // Output message identifiers from the CHIMU unit
71 #define CHIMU_Msg_0_Ping 0
72 #define CHIMU_Msg_1_IMU_Raw 1
73 #define CHIMU_Msg_2_IMU_FP 2
74 #define CHIMU_Msg_3_IMU_Attitude 3
75 #define CHIMU_Msg_4_BiasSF 4
76 #define CHIMU_Msg_5_BIT 5
77 #define CHIMU_Msg_6_MagCal 6
78 #define CHIMU_Msg_7_GyroBias 7
79 #define CHIMU_Msg_8_TempCal 8
80 #define CHIMU_Msg_9_DAC_Offsets 9
81 #define CHIMU_Msg_10_Res 10
82 #define CHIMU_Msg_11_Res 11
83 #define CHIMU_Msg_12_Res 12
84 #define CHIMU_Msg_13_Res 13
85 #define CHIMU_Msg_14_RefVector 14
86 #define CHIMU_Msg_15_SFCheck 15
87 
88 
89 /***************************************************************************
90  * Endianness Swapping Functions
91  */
92 
93 #ifdef CHIMU_BIG_ENDIAN
94 
95 static inline float FloatSwap(float f)
96 {
97  union {
98  float f;
99  unsigned char b[4];
100  } dat1, dat2;
101 
102  dat1.f = f;
103  dat2.b[0] = dat1.b[3];
104  dat2.b[1] = dat1.b[2];
105  dat2.b[2] = dat1.b[1];
106  dat2.b[3] = dat1.b[0];
107  return dat2.f;
108 }
109 
110 #else
111 
112 #define FloatSwap(X) (X)
113 
114 #endif
115 
116 
117 typedef struct {
118  float phi;
119  float theta;
120  float psi;
121 } CHIMU_Euler;
122 
123 typedef struct {
124  float x;
125  float y;
126  float z;
127 } CHIMU_Vector;
128 
129 typedef struct {
130  float s;
133 
134 typedef struct {
138 
139 #ifndef FALSE
140 #define FALSE (1==0)
141 #endif
142 #ifndef TRUE
143 #define TRUE (1==1)
144 #endif
145 
146 typedef struct {
147  float cputemp;
148  float acc[3];
149  float rate[3];
150  float mag[3];
151  float spare1;
153 
154 #define CHIMU_RX_BUFFERSIZE 128
155 
156 typedef struct {
157  unsigned char m_State; // Current state protocol parser is in
158  unsigned char m_Checksum; // Calculated CHIMU sentence checksum
159  unsigned char m_ReceivedChecksum; // Received CHIMU sentence checksum (if exists)
160  unsigned char m_Index; // Index used for command and data
161  unsigned char m_PayloadIndex;
162  unsigned char m_MsgID;
163  unsigned char m_MsgLen;
164  unsigned char m_TempDeviceID;
165  unsigned char m_DeviceID;
166  unsigned char m_Payload[CHIMU_RX_BUFFERSIZE]; // CHIMU data
167  unsigned char m_FullMessage[CHIMU_RX_BUFFERSIZE]; // CHIMU data
171 
172  // Ping data
177 
178  // Config
182 
184 
185 /*---------------------------------------------------------------------------
186  Name: CHIMU_Init
187  ---------------------------------------------------------------------------*/
188 void CHIMU_Init(CHIMU_PARSER_DATA *pstData);
189 
190 /*---------------------------------------------------------------------------
191  Name: CHIMU_Parse
192  Abstract: Parse message input test mode, returns TRUE if new data.
193  ---------------------------------------------------------------------------*/
194 unsigned char CHIMU_Parse(unsigned char btData, unsigned char bInputType, CHIMU_PARSER_DATA *pstData);
195 
196 unsigned char CHIMU_ProcessMessage(unsigned char *pMsgID, unsigned char *pPayloadData, CHIMU_PARSER_DATA *pstData);
197 
198 void CHIMU_Checksum(unsigned char *data, unsigned char buflen);
199 
200 #endif // CHIMU_DEFINED
unsigned short uint16_t
Definition: types.h:16
CHIMU_Quaternion q
Definition: imu_chimu.h:136
#define CHIMU_RX_BUFFERSIZE
Definition: imu_chimu.h:154
#define FloatSwap(X)
Definition: imu_chimu.h:112
void CHIMU_Init(CHIMU_PARSER_DATA *pstData)
Definition: imu_chimu.c:108
CHIMU_attitude_data m_attitude
Definition: imu_chimu.h:168
float phi
Definition: imu_chimu.h:118
unsigned char m_PayloadIndex
Definition: imu_chimu.h:161
float theta
Definition: imu_chimu.h:119
unsigned char m_ReceivedChecksum
Definition: imu_chimu.h:159
unsigned char m_MsgID
Definition: imu_chimu.h:162
uint8_t gCHIMU_SW_Major
Definition: imu_chimu.h:174
unsigned char m_TempDeviceID
Definition: imu_chimu.h:164
unsigned char m_Index
Definition: imu_chimu.h:160
uint8_t gConfigInfo
Definition: imu_chimu.h:181
CHIMU_Vector v
Definition: imu_chimu.h:131
CHIMU_Euler euler
Definition: imu_chimu.h:135
void CHIMU_Checksum(unsigned char *data, unsigned char buflen)
Definition: imu_chimu.c:82
uint8_t gCHIMU_BIT
Definition: imu_chimu.h:180
CHIMU_sensor_data m_sensor
Definition: imu_chimu.h:170
unsigned char m_DeviceID
Definition: imu_chimu.h:165
uint16_t gCHIMU_SW_SerialNumber
Definition: imu_chimu.h:176
uint8_t gCHIMU_SW_Exclaim
Definition: imu_chimu.h:173
unsigned char CHIMU_ProcessMessage(unsigned char *pMsgID, unsigned char *pPayloadData, CHIMU_PARSER_DATA *pstData)
Definition: imu_chimu.c:288
uint8_t gCHIMU_SW_Minor
Definition: imu_chimu.h:175
unsigned char uint8_t
Definition: types.h:14
unsigned char m_Checksum
Definition: imu_chimu.h:158
unsigned char m_MsgLen
Definition: imu_chimu.h:163
CHIMU_attitude_data m_attrates
Definition: imu_chimu.h:169
float psi
Definition: imu_chimu.h:120
uint8_t gCalStatus
Definition: imu_chimu.h:179
unsigned char CHIMU_Parse(unsigned char btData, unsigned char bInputType, CHIMU_PARSER_DATA *pstData)
Definition: imu_chimu.c:149
unsigned char m_State
Definition: imu_chimu.h:157