Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures 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 #ifndef DOWNLINK_DEVICE
19 #define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
20 #endif
21 #include "mcu_periph/uart.h"
22 #include "messages.h"
24 #endif
25 
26 #include "ins_module.h"
27 #include "imu_chimu.h"
28 
29 #include "led.h"
30 
32 
35 
36 void ahrs_init(void)
37 {
39 
40  uint8_t ping[7] = {CHIMU_STX, CHIMU_STX, 0x01, CHIMU_BROADCAST, MSG00_PING, 0x00, 0xE6 };
41  uint8_t rate[12] = {CHIMU_STX, CHIMU_STX, 0x06, CHIMU_BROADCAST, MSG10_UARTSETTINGS, 0x05, 0xff, 0x79, 0x00, 0x00, 0x01, 0x76 }; // 50Hz attitude only + SPI
42  uint8_t quaternions[7] = {CHIMU_STX, CHIMU_STX, 0x01, CHIMU_BROADCAST, MSG09_ESTIMATOR, 0x01, 0x39 }; // 25Hz attitude only + SPI
43  // uint8_t rate[12] = {CHIMU_STX, CHIMU_STX, 0x06, CHIMU_BROADCAST, MSG10_UARTSETTINGS, 0x04, 0xff, 0x79, 0x00, 0x00, 0x01, 0xd3 }; // 25Hz attitude only + SPI
44  // uint8_t euler[7] = {CHIMU_STX, CHIMU_STX, 0x01, CHIMU_BROADCAST, MSG09_ESTIMATOR, 0x00, 0xaf }; // 25Hz attitude only + SPI
45 
46  new_ins_attitude = 0;
47 
50 
51  CHIMU_Init(&CHIMU_DATA);
52 
53  // Request Software version
54  for (int i=0;i<7;i++) {
55  InsUartSend1(ping[i]);
56  }
57 
58  // Quat Filter
59  for (int i=0;i<7;i++) {
60  InsUartSend1(quaternions[i]);
61  }
62 
63  // 50Hz
64  CHIMU_Checksum(rate,12);
65  InsSend(rate,12);
66 }
67 void ahrs_align(void)
68 {
70 }
71 
72 
73 void parse_ins_msg( void )
74 {
75  while (InsLink(ChAvailable())) {
76  uint8_t ch = InsLink(Getch());
77 
78  if (CHIMU_Parse(ch, 0, &CHIMU_DATA)) {
79  if(CHIMU_DATA.m_MsgID==0x03) {
80  new_ins_attitude = 1;
81  RunOnceEvery(25, LED_TOGGLE(3) );
82  if (CHIMU_DATA.m_attitude.euler.phi > M_PI) {
83  CHIMU_DATA.m_attitude.euler.phi -= 2 * M_PI;
84  }
85 
86  struct FloatEulers att = {
87  CHIMU_DATA.m_attitude.euler.phi,
88  CHIMU_DATA.m_attitude.euler.theta,
89  CHIMU_DATA.m_attitude.euler.psi
90  };
92 #if CHIMU_DOWNLINK_IMMEDIATE
93  DOWNLINK_SEND_AHRS_EULER(DefaultChannel, DefaultDevice, &CHIMU_DATA.m_attitude.euler.phi, &CHIMU_DATA.m_attitude.euler.theta, &CHIMU_DATA.m_attitude.euler.psi);
94 #endif
95 
96  }
97  }
98  }
99 }
100 
101 void ahrs_update_gps( void )
102 {
103 }
static void stateSetNedToBodyEulers_f(struct FloatEulers *ned_to_body_eulers)
Set vehicle body attitude from euler angles (float).
Definition: state.h:995
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
Attitude and Heading Reference System interface.
CHIMU_Euler euler
Definition: imu_chimu.h:136
INS_FORMAT ins_roll_neutral
struct Ahrs ahrs
global AHRS state
Definition: ahrs.c:30
#define INS_ROLL_NEUTRAL_DEFAULT
#define MSG10_UARTSETTINGS
Definition: imu_chimu.h:67
#define CHIMU_STX
Definition: imu_chimu.h:47
void ahrs_init(void)
AHRS initialization.
euler angles
void CHIMU_Checksum(unsigned char *data, unsigned char buflen)
Definition: imu_chimu.c:83
void parse_ins_msg(void)
#define MSG00_PING
Definition: imu_chimu.h:51
void CHIMU_Init(CHIMU_PARSER_DATA *pstData)
Definition: imu_chimu.c:109
Device independent GPS code (interface)
uint8_t status
status of the AHRS, AHRS_UNINIT or AHRS_RUNNING
Definition: ahrs.h:45
#define INS_PITCH_NEUTRAL_DEFAULT
unsigned char CHIMU_Parse(unsigned char btData, unsigned char bInputType, CHIMU_PARSER_DATA *pstData)
Definition: imu_chimu.c:150
#define InsSend(_dat, _len)
Definition: ins_module.h:85
CHIMU_attitude_data m_attitude
Definition: imu_chimu.h:169
float phi
Definition: imu_chimu.h:119
#define LED_TOGGLE(i)
Definition: led_hw.h:30
void ahrs_align(void)
Aligns the AHRS.
#define InsLink(_x)
Definition: ins_module.h:79
#define INS_FORMAT
Definition: ins_module.h:35
#define AHRS_UNINIT
Definition: ahrs.h:35
void ahrs_update_gps(void)
Update AHRS state with GPS measurements.
unsigned char uint8_t
Definition: types.h:14
API to get/set the generic vehicle states.
volatile uint8_t new_ins_attitude
float psi
Definition: imu_chimu.h:121
#define CHIMU_BROADCAST
Definition: imu_chimu.h:48
CHIMU_PARSER_DATA CHIMU_DATA
float theta
Definition: imu_chimu.h:120
arch independent LED (Light Emitting Diodes) API
#define MSG09_ESTIMATOR
Definition: imu_chimu.h:60
#define InsUartSend1(c)
Definition: ins_module.h:84
Device independent INS code.
unsigned char m_MsgID
Definition: imu_chimu.h:163
#define AHRS_RUNNING
Definition: ahrs.h:36
INS_FORMAT ins_pitch_neutral