Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros 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  {
99  float f;
100  unsigned char b[4];
101  } dat1, dat2;
102 
103  dat1.f = f;
104  dat2.b[0] = dat1.b[3];
105  dat2.b[1] = dat1.b[2];
106  dat2.b[2] = dat1.b[1];
107  dat2.b[3] = dat1.b[0];
108  return dat2.f;
109 }
110 
111 #else
112 
113 #define FloatSwap(X) (X)
114 
115 #endif
116 
117 
118 typedef struct {
119  float phi;
120  float theta;
121  float psi;
122 } CHIMU_Euler;
123 
124 typedef struct {
125  float x;
126  float y;
127  float z;
128 } CHIMU_Vector;
129 
130 typedef struct {
131  float s;
134 
135 typedef struct {
139 
140 #ifndef FALSE
141 #define FALSE (1==0)
142 #endif
143 #ifndef TRUE
144 #define TRUE (1==1)
145 #endif
146 
147 typedef struct {
148  float cputemp;
149  float acc[3];
150  float rate[3];
151  float mag[3];
152  float spare1;
154 
155 #define CHIMU_RX_BUFFERSIZE 128
156 
157 typedef struct {
158  unsigned char m_State; // Current state protocol parser is in
159  unsigned char m_Checksum; // Calculated CHIMU sentence checksum
160  unsigned char m_ReceivedChecksum; // Received CHIMU sentence checksum (if exists)
161  unsigned char m_Index; // Index used for command and data
162  unsigned char m_PayloadIndex;
163  unsigned char m_MsgID;
164  unsigned char m_MsgLen;
165  unsigned char m_TempDeviceID;
166  unsigned char m_DeviceID;
167  unsigned char m_Payload[CHIMU_RX_BUFFERSIZE]; // CHIMU data
168  unsigned char m_FullMessage[CHIMU_RX_BUFFERSIZE]; // CHIMU data
172 
173  // Ping data
178 
179  // Config
183 
185 
186 /*---------------------------------------------------------------------------
187  Name: CHIMU_Init
188  ---------------------------------------------------------------------------*/
189 void CHIMU_Init(CHIMU_PARSER_DATA *pstData);
190 
191 /*---------------------------------------------------------------------------
192  Name: CHIMU_Parse
193  Abstract: Parse message input test mode, returns TRUE if new data.
194  ---------------------------------------------------------------------------*/
195 unsigned char CHIMU_Parse(unsigned char btData, unsigned char bInputType, CHIMU_PARSER_DATA *pstData);
196 
197 unsigned char CHIMU_ProcessMessage(unsigned char *pMsgID, unsigned char *pPayloadData, CHIMU_PARSER_DATA *pstData);
198 
199 void CHIMU_Checksum(unsigned char *data, unsigned char buflen);
200 
201 #endif // CHIMU_DEFINED
unsigned short uint16_t
Definition: types.h:16
#define CHIMU_RX_BUFFERSIZE
Definition: imu_chimu.h:155
#define FloatSwap(X)
Definition: imu_chimu.h:113
void CHIMU_Init(CHIMU_PARSER_DATA *pstData)
Definition: imu_chimu.c:109
unsigned char m_State
Definition: imu_chimu.h:158
CHIMU_Euler euler
Definition: imu_chimu.h:136
unsigned char m_ReceivedChecksum
Definition: imu_chimu.h:160
CHIMU_sensor_data m_sensor
Definition: imu_chimu.h:171
CHIMU_Quaternion q
Definition: imu_chimu.h:137
CHIMU_attitude_data m_attrates
Definition: imu_chimu.h:170
uint8_t gConfigInfo
Definition: imu_chimu.h:182
uint16_t gCHIMU_SW_SerialNumber
Definition: imu_chimu.h:177
unsigned char m_TempDeviceID
Definition: imu_chimu.h:165
void CHIMU_Checksum(unsigned char *data, unsigned char buflen)
Definition: imu_chimu.c:83
uint8_t gCHIMU_SW_Major
Definition: imu_chimu.h:175
CHIMU_attitude_data m_attitude
Definition: imu_chimu.h:169
float phi
Definition: imu_chimu.h:119
unsigned char CHIMU_ProcessMessage(unsigned char *pMsgID, unsigned char *pPayloadData, CHIMU_PARSER_DATA *pstData)
Definition: imu_chimu.c:290
unsigned char m_PayloadIndex
Definition: imu_chimu.h:162
CHIMU_Vector v
Definition: imu_chimu.h:132
unsigned char m_Index
Definition: imu_chimu.h:161
unsigned char uint8_t
Definition: types.h:14
uint8_t gCHIMU_BIT
Definition: imu_chimu.h:181
float psi
Definition: imu_chimu.h:121
unsigned char m_Checksum
Definition: imu_chimu.h:159
float theta
Definition: imu_chimu.h:120
unsigned char m_MsgLen
Definition: imu_chimu.h:164
uint8_t gCalStatus
Definition: imu_chimu.h:180
uint8_t gCHIMU_SW_Exclaim
Definition: imu_chimu.h:174
unsigned char m_DeviceID
Definition: imu_chimu.h:166
unsigned char m_MsgID
Definition: imu_chimu.h:163
unsigned char CHIMU_Parse(unsigned char btData, unsigned char bInputType, CHIMU_PARSER_DATA *pstData)
Definition: imu_chimu.c:150
uint8_t gCHIMU_SW_Minor
Definition: imu_chimu.h:176