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_chimu_uart.c
Go to the documentation of this file.
1 /*
2  C code to connect a CHIMU using uart
3 */
4 
5 
6 #include <stdbool.h>
7 
8 // Output
9 #include "state.h"
10 
11 // For centripedal corrections
12 #include "subsystems/gps.h"
13 #include "subsystems/ahrs.h"
14 
15 #include "generated/airframe.h"
16 
17 #if CHIMU_DOWNLINK_IMMEDIATE
18 #include "mcu_periph/uart.h"
19 #include "messages.h"
21 #endif
22 
23 #include "ins_module.h"
24 #include "imu_chimu.h"
25 
26 #include "led.h"
27 
29 
32 
34 
36 
37 static bool_t ahrs_chimu_enable_output(bool_t enable)
38 {
39  ahrs_chimu.is_enabled = enable;
40  return ahrs_chimu.is_enabled;
41 }
42 
44 {
47 }
48 
49 void ahrs_chimu_init(void)
50 {
53 
54  uint8_t ping[7] = {CHIMU_STX, CHIMU_STX, 0x01, CHIMU_BROADCAST, MSG00_PING, 0x00, 0xE6 };
55  uint8_t rate[12] = {CHIMU_STX, CHIMU_STX, 0x06, CHIMU_BROADCAST, MSG10_UARTSETTINGS, 0x05, 0xff, 0x79, 0x00, 0x00, 0x01, 0x76 }; // 50Hz attitude only + SPI
56  uint8_t quaternions[7] = {CHIMU_STX, CHIMU_STX, 0x01, CHIMU_BROADCAST, MSG09_ESTIMATOR, 0x01, 0x39 }; // 25Hz attitude only + SPI
57  // uint8_t rate[12] = {CHIMU_STX, CHIMU_STX, 0x06, CHIMU_BROADCAST, MSG10_UARTSETTINGS, 0x04, 0xff, 0x79, 0x00, 0x00, 0x01, 0xd3 }; // 25Hz attitude only + SPI
58  // uint8_t euler[7] = {CHIMU_STX, CHIMU_STX, 0x01, CHIMU_BROADCAST, MSG09_ESTIMATOR, 0x00, 0xaf }; // 25Hz attitude only + SPI
59 
60  new_ins_attitude = 0;
61 
64 
65  CHIMU_Init(&CHIMU_DATA);
66 
67  // Request Software version
68  for (int i = 0; i < 7; i++) {
69  InsUartSend1(ping[i]);
70  }
71 
72  // Quat Filter
73  for (int i = 0; i < 7; i++) {
74  InsUartSend1(quaternions[i]);
75  }
76 
77  // 50Hz
78  CHIMU_Checksum(rate, 12);
79  InsSend(rate, 12);
80 }
81 
82 
83 void parse_ins_msg(void)
84 {
85  struct link_device *dev = InsLinkDevice;
86  while (dev->char_available(dev->periph)) {
87  uint8_t ch = dev->get_byte(dev->periph);
88 
89  if (CHIMU_Parse(ch, 0, &CHIMU_DATA)) {
90  if (CHIMU_DATA.m_MsgID == 0x03) {
91  new_ins_attitude = 1;
92  RunOnceEvery(25, LED_TOGGLE(3));
93  if (CHIMU_DATA.m_attitude.euler.phi > M_PI) {
94  CHIMU_DATA.m_attitude.euler.phi -= 2 * M_PI;
95  }
96 
98 
99  if (ahrs_chimu.is_enabled) {
100  struct FloatEulers att = {
101  CHIMU_DATA.m_attitude.euler.phi,
102  CHIMU_DATA.m_attitude.euler.theta,
103  CHIMU_DATA.m_attitude.euler.psi
104  };
106  }
107 
108 #if CHIMU_DOWNLINK_IMMEDIATE
109  DOWNLINK_SEND_AHRS_EULER(DefaultChannel, DefaultDevice,
110  &CHIMU_DATA.m_attitude.euler.phi,
111  &CHIMU_DATA.m_attitude.euler.theta,
112  &CHIMU_DATA.m_attitude.euler.psi,
113  &ahrs_chimu_id);
114 #endif
115 
116  }
117  }
118  }
119 }
static void stateSetNedToBodyEulers_f(struct FloatEulers *ned_to_body_eulers)
Set vehicle body attitude from euler angles (float).
Definition: state.h:1076
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
Dispatcher to register actual AHRS implementations.
CHIMU_attitude_data m_attitude
Definition: imu_chimu.h:168
#define AHRS_COMP_ID_CHIMU
Definition: ahrs.h:42
INS_FORMAT ins_roll_neutral
float phi
Definition: imu_chimu.h:118
float theta
Definition: imu_chimu.h:119
struct AhrsChimu ahrs_chimu
#define MSG10_UARTSETTINGS
Definition: imu_chimu.h:67
#define CHIMU_STX
Definition: imu_chimu.h:47
unsigned char m_MsgID
Definition: imu_chimu.h:162
#define INS_ROLL_NEUTRAL_DEFAULT
Definition: ahrs_sim.c:43
void CHIMU_Checksum(unsigned char *data, unsigned char buflen)
Definition: imu_chimu.c:82
void parse_ins_msg(void)
#define FALSE
Definition: std.h:5
bool_t is_aligned
Definition: ahrs_chimu.h:34
euler angles
#define LED_TOGGLE(i)
Definition: led_hw.h:44
#define InsLinkDevice
Definition: ins_module.h:76
#define TRUE
Definition: std.h:4
void ahrs_register_impl(AhrsEnableOutput enable)
Register an AHRS implementation.
Definition: ahrs.c:57
void ahrs_chimu_register(void)
#define MSG00_PING
Definition: imu_chimu.h:51
void CHIMU_Init(CHIMU_PARSER_DATA *pstData)
Definition: imu_chimu.c:108
Device independent GPS code (interface)
CHIMU_Euler euler
Definition: imu_chimu.h:135
unsigned char CHIMU_Parse(unsigned char btData, unsigned char bInputType, CHIMU_PARSER_DATA *pstData)
Definition: imu_chimu.c:149
#define InsSend(_dat, _len)
Definition: ins_module.h:84
#define INS_PITCH_NEUTRAL_DEFAULT
Definition: ahrs_sim.c:46
#define INS_FORMAT
Definition: ins_module.h:35
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:69
static bool_t ahrs_chimu_enable_output(bool_t enable)
unsigned char uint8_t
Definition: types.h:14
API to get/set the generic vehicle states.
volatile uint8_t new_ins_attitude
#define CHIMU_BROADCAST
Definition: imu_chimu.h:48
static uint8_t ahrs_chimu_id
CHIMU_PARSER_DATA CHIMU_DATA
void ahrs_chimu_init(void)
arch independent LED (Light Emitting Diodes) API
#define MSG09_ESTIMATOR
Definition: imu_chimu.h:60
float psi
Definition: imu_chimu.h:120
#define InsUartSend1(c)
Definition: ins_module.h:83
bool_t is_enabled
Definition: ahrs_chimu.h:33
Device independent INS code.
INS_FORMAT ins_pitch_neutral