Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ahrs_gx3.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  */
32 #ifndef AHRS_GX3_H
33 #define AHRS_GX3_H
34 
35 #include "generated/airframe.h"
36 #include "subsystems/imu.h"
37 #include "subsystems/ins.h"
38 #include "subsystems/gps.h"
39 #include "mcu_periph/uart.h"
40 
41 #include "state.h"
42 #include "led.h"
43 
44 #define GX3_MAX_PAYLOAD 128
45 #define GX3_MSG_LEN 67
46 #define GX3_HEADER 0xC8
47 #define GX3_MIN_FREQ 300
48 
49 #define IMU_GX3_LONG_DELAY 4000000
50 
51 extern void gx3_packet_read_message(void);
52 extern void gx3_packet_parse(uint8_t c);
53 
54 struct GX3Packet {
55  bool_t msg_available;
61 };
62 
66 };
67 
68 
69 //AHRS
70 struct AhrsGX3 {
72  float mag_offset;
73 
74  struct GX3Packet packet;
75  float freq;
79  struct FloatVect3 accel;
80  struct FloatRates rate;
81  struct FloatRMat rmat;
82  bool_t is_aligned;
83 };
84 
85 extern struct AhrsGX3 ahrs_gx3;
86 
87 #ifndef PRIMARY_AHRS
88 #define PRIMARY_AHRS ahrs_gx3
89 #endif
90 
91 extern void ahrs_gx3_init(void);
92 extern void ahrs_gx3_align(void);
93 extern void ahrs_gx3_register(void);
94 extern void ahrs_gx3_publish_imu(void);
95 
96 static inline void ReadGX3Buffer(void)
97 {
98  while (uart_char_available(&GX3_PORT) && !ahrs_gx3.packet.msg_available) {
99  gx3_packet_parse(uart_getch(&GX3_PORT));
100  }
101 }
102 
103 static inline void ImuEvent(void)
104 {
105  if (uart_char_available(&GX3_PORT)) {
106  ReadGX3Buffer();
107  }
112  }
113 }
114 
115 #endif /* AHRS_GX3_H*/
unsigned short uint16_t
Definition: types.h:16
void ahrs_gx3_init(void)
Definition: ahrs_gx3.c:327
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
void gx3_packet_read_message(void)
Definition: ahrs_gx3.c:226
float freq
data frequency
Definition: ahrs_gx3.h:75
uint8_t msg_buf[GX3_MAX_PAYLOAD]
Definition: ahrs_gx3.h:58
void ahrs_gx3_align(void)
Definition: ahrs_gx3.c:75
uint16_t uart_char_available(struct uart_periph *p)
Check UART for available chars in receive buffer.
Definition: uart_arch.c:296
uint32_t hdr_error
Definition: ahrs_gx3.h:57
Integrated Navigation System interface.
void ahrs_gx3_publish_imu(void)
Definition: ahrs_gx3.c:353
void gx3_packet_parse(uint8_t c)
Definition: ahrs_gx3.c:294
GX3PacketStatus
Definition: ahrs_gx3.h:63
void ahrs_gx3_register(void)
Definition: ahrs_gx3.c:340
float mag_offset
Difference between true and magnetic north.
Definition: ahrs_gx3.h:72
struct FloatQuat ltp_to_imu_quat
Rotation from LocalTangentPlane to IMU frame as quaternions.
Definition: ahrs_gx3.h:71
#define FALSE
Definition: std.h:5
Roation quaternion.
struct FloatVect3 accel
measured acceleration in IMU frame
Definition: ahrs_gx3.h:79
static void ImuEvent(void)
Definition: ahrs_gx3.h:103
struct AhrsGX3 ahrs_gx3
Axis definition: X axis pointing forward, Y axis pointing to the right and Z axis pointing down...
Definition: ahrs_gx3.c:47
uint8_t status
Definition: ahrs_gx3.h:59
Device independent GPS code (interface)
unsigned long uint32_t
Definition: types.h:18
uint32_t time
GX3 time stamp.
Definition: ahrs_gx3.h:77
uint32_t chksm_error
Definition: ahrs_gx3.h:56
Inertial Measurement Unit interface.
#define GX3_MAX_PAYLOAD
Definition: ahrs_gx3.h:44
uint8_t uart_getch(struct uart_periph *p)
Definition: uart_arch.c:287
unsigned char uint8_t
Definition: types.h:14
API to get/set the generic vehicle states.
struct FloatRMat rmat
measured attitude in IMU frame (rotational matrix)
Definition: ahrs_gx3.h:81
bool_t msg_available
Definition: ahrs_gx3.h:55
bool_t is_aligned
Definition: ahrs_gx3.h:82
rotation matrix
static void ReadGX3Buffer(void)
Definition: ahrs_gx3.h:96
arch independent LED (Light Emitting Diodes) API
struct GX3Packet packet
Packet struct.
Definition: ahrs_gx3.h:74
uint16_t chksm
aux variable for checksum
Definition: ahrs_gx3.h:76
struct FloatRates rate
measured angular rates in IMU frame
Definition: ahrs_gx3.h:80
uint8_t msg_idx
Definition: ahrs_gx3.h:60
uint32_t ltime
aux time stamp
Definition: ahrs_gx3.h:78
angular rates