-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
160 lines (136 loc) · 3.9 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
* main.c
*
* Created on: 14 ôåâð. 2016 ã.
* Author: kruci_000
*/
#include <Modules/Time/time.h>
#include <Modules/Time/timer.h>
#include <Modules/UART/uart.h>
#include <Modules/I2C/i2c.h>
#include <Modules/MPU6050/mpu6050.h>
#include <Modules/HMC/hmc.h>
#include <Modules/BMP180/bmp180.h>
#include <Modules/MAVLink/common/mavlink.h>
#include <Modules/MAVLink/handlers.h>
#include <Modules/MAVLink/system.h>
#include <Modules/Parameters_Holder/param_holder.h>
#include <Modules/PID/pid.h>
#include <Helpers/sys_helper/sys_helper.h>
#include <hal.h>
#include <MC_hw_platform.h>
#include <m2sxxx.h>
#include <defines.h>
void setup(void);
int main(void) {
// Modules initialisation
setup();
uint8_t rx_c;
float roll, pitch, yaw;
float q[4];
mavlink_message_t msg;
mavlink_status_t status;
while (1) {
delay(1000);
#ifdef MPU6050_ENABLED
MPU6050_getScaledData(
¶ms.param[PARAM_AX],
¶ms.param[PARAM_AY],
¶ms.param[PARAM_AZ],
¶ms.param[PARAM_GX],
¶ms.param[PARAM_GY],
¶ms.param[PARAM_GZ],
¶ms.param[PARAM_T]);
#endif // MPU6050_ENABLED
#ifdef HMC_ENABLED
HMC_get_scaled_Data(
¶ms.param[PARAM_MX],
¶ms.param[PARAM_MY],
¶ms.param[PARAM_MZ]);
#endif // HMC_ENABLED
#ifdef BMP180_ENABLED
params.param[PARAM_AP] = BMP_get_preasure();
params.param[PARAM_AT] = BMP_get_altitude(params.param[PARAM_AP]);
#endif // BMP180_ENABLED
// pid_update(q0, q1, q2, q3,
pid_update(motors_pow);
motors_set();
if (BT_get_rx(&rx_c, 1)) {
if (mavlink_parse_char(MAVLINK_COMM_0, rx_c, &msg, &status)) {
handle_mavlink_message(&msg);
}
param_queued_send_routine();
}
}
return 0;
}
void setup() {
uint8_t retcode = 0;
timers_init();
uart_init();
i2c_init();
motors_init();
mavlink_sys_update(MAV_MODE_AUTO_ARMED, MAV_STATE_STANDBY);
timer_mss1_start();
#ifdef BMP180_ENABLED
retcode = BMP_init();
if (retcode) {
mavlink_message_t msg;
uint8_t text[50];
sprintf(text, "BMP180 initialization failure: %d", retcode);
mavlink_msg_statustext_pack(
mavlink_system.sysid,
mavlink_system.compid,
&msg,
MAV_SEVERITY_CRITICAL,
text);
mavlink_send_msg(&msg);
}
#endif // BMP180_ENABLED
#ifdef MPU6050_ENABLED
MPU6050_init();
#ifdef MPU6050_SELFTEST
retcode = MPU6050_selfTest();
if (retcode) {
mavlink_message_t msg;
uint8_t text[50];
sprintf(text, "MPU6050 SELFTEST FAILED: %d", retcode);
mavlink_msg_statustext_pack(
mavlink_system.sysid,
mavlink_system.compid,
&msg,
MAV_SEVERITY_CRITICAL,
text);
mavlink_send_msg(&msg);
}
#endif // MPU6050_SELFTEST
MPU6050_calibration();
#endif // MPU6050_ENABLED
#ifdef HMC_ENABLED
{
mavlink_message_t msg;
uint8_t text[50];
mavlink_msg_statustext_pack(
mavlink_system.sysid,
mavlink_system.compid,
&msg,
MAV_SEVERITY_INFO,
"HMC SELFTEST STARTED: SHAKE VEHICLE");
mavlink_send_msg(&msg);
HMC_init();
#ifdef HMC_SELFTEST
if (retcode = HMC_self_test()) {
sprintf(text, "HMC SELFTEST FAILED: %d", retcode);
mavlink_msg_statustext_pack(
mavlink_system.sysid,
mavlink_system.compid,
&msg,
MAV_SEVERITY_CRITICAL,
text);
mavlink_send_msg(&msg);
}
}
#endif // HMC_SELFTEST
#endif // HMC_ENABLED
timer_mss2_start();
}