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
ins_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 //#include "modules/ins/ins_chimu_uart.h"
9 
10 
11 
12 // Output
13 #include "estimator.h"
14 
15 // For centripedal corrections
16 #include "subsystems/gps.h"
17 
18 // Telemetry
19 #ifndef DOWNLINK_DEVICE
20 #define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
21 #endif
22 
23 #include "mcu_periph/uart.h"
24 #include "messages.h"
26 
27 #include "ins_module.h"
28 #include "imu_chimu.h"
29 
31 
34 
36 
37 void ins_init( void )
38 {
39  uint8_t ping[7] = {CHIMU_STX, CHIMU_STX, 0x01, CHIMU_BROADCAST, MSG00_PING, 0x00, 0xE6 };
40  uint8_t rate[12] = {CHIMU_STX, CHIMU_STX, 0x06, CHIMU_BROADCAST, MSG10_UARTSETTINGS, 0x05, 0xff, 0x79, 0x00, 0x00, 0x01, 0x76 }; // 50Hz attitude only + SPI
41  uint8_t quaternions[7] = {CHIMU_STX, CHIMU_STX, 0x01, CHIMU_BROADCAST, MSG09_ESTIMATOR, 0x01, 0x39 }; // 25Hz attitude only + SPI
42  // uint8_t rate[12] = {CHIMU_STX, CHIMU_STX, 0x06, CHIMU_BROADCAST, MSG10_UARTSETTINGS, 0x04, 0xff, 0x79, 0x00, 0x00, 0x01, 0xd3 }; // 25Hz attitude only + SPI
43  // uint8_t euler[7] = {CHIMU_STX, CHIMU_STX, 0x01, CHIMU_BROADCAST, MSG09_ESTIMATOR, 0x00, 0xaf }; // 25Hz attitude only + SPI
44 
45 
46  new_ins_attitude = 0;
47 
48  ins_roll_neutral = INS_ROLL_NEUTRAL_DEFAULT;
49  ins_pitch_neutral = INS_PITCH_NEUTRAL_DEFAULT;
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 
59  // Quat Filter
60  for (int i=0;i<7;i++) {
61  InsUartSend1(quaternions[i]);
62  }
63 
64 
65  // 50Hz
66  CHIMU_Checksum(rate,12);
67  InsSend(rate,12);
68 
69 }
70 
71 void parse_ins_msg( void )
72 {
73  while (InsLink(ChAvailable())) {
74  uint8_t ch = InsLink(Getch());
75 
76  if (CHIMU_Parse(ch, 0, &CHIMU_DATA)) {
77  if(CHIMU_DATA.m_MsgID==0x03) {
78  new_ins_attitude = 1;
79  RunOnceEvery(25, LED_TOGGLE(3) );
80  if (CHIMU_DATA.m_attitude.euler.phi > M_PI) {
81  CHIMU_DATA.m_attitude.euler.phi -= 2 * M_PI;
82  }
83 
84  EstimatorSetAtt(CHIMU_DATA.m_attitude.euler.phi, CHIMU_DATA.m_attitude.euler.psi, CHIMU_DATA.m_attitude.euler.theta);
85  //EstimatorSetRate(ins_p,ins_q,ins_r);
86 
87  DOWNLINK_SEND_AHRS_EULER(DefaultChannel, DefaultDevice, &CHIMU_DATA.m_attitude.euler.phi, &CHIMU_DATA.m_attitude.euler.theta, &CHIMU_DATA.m_attitude.euler.psi);
88 
89  }
90  }
91  }
92 }
93 
94 
95 //Frequency defined in conf *.xml
96 void ins_periodic_task( void )
97 {
98  // Downlink Send
99 }
100 
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
CHIMU_PARSER_DATA CHIMU_DATA
CHIMU_Euler euler
Definition: imu_chimu.h:136
#define EstimatorSetAtt(phi, psi, theta)
Definition: estimator.h:131
INS_FORMAT ins_pitch_neutral
INS_FORMAT ins_roll_neutral
#define MSG10_UARTSETTINGS
Definition: imu_chimu.h:67
#define CHIMU_STX
Definition: imu_chimu.h:47
void CHIMU_Checksum(unsigned char *data, unsigned char buflen)
Definition: imu_chimu.c:83
void ins_periodic_task(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)
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:89
volatile uint8_t new_ins_attitude
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
#define InsLink(_x)
Definition: ins_module.h:83
#define INS_FORMAT
Definition: ins_module.h:38
unsigned char uint8_t
Definition: types.h:14
float psi
Definition: imu_chimu.h:121
#define CHIMU_BROADCAST
Definition: imu_chimu.h:48
void ins_init(void)
State estimation, fusioning sensors.
float theta
Definition: imu_chimu.h:120
void parse_ins_msg(void)
#define MSG09_ESTIMATOR
Definition: imu_chimu.h:60
#define InsUartSend1(c)
Definition: ins_module.h:88
unsigned char m_MsgID
Definition: imu_chimu.h:163