-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDCS.ino
65 lines (55 loc) · 1.63 KB
/
DCS.ino
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
#include "Config.h"
#include "BLE_IMU.h"
#include "Motors.h"
#include "MSP.h"
#include "Debug.h"
extern volatile uint16_t rcValue[];
int16_t fastLoopTiming, slowLoopTiming;
void doMode();
void doPID();
void doMix();
void setup() {
Serial.begin(9600);
initMSP();
initRX();
initIMU();
initMotors();
}
unsigned long fastLoopLength;
unsigned long fastLoopStart = 0;
unsigned long slowLoopLength;
unsigned long slowLoopStart = 0;
void loop() {
// the fast loop for flight control
unsigned long fastLoopEnd = micros();
fastLoopLength = fastLoopEnd - fastLoopStart;
if ((fastLoopLength) > FASTLOOPTARGET)
{
fastLoopStart = fastLoopEnd;
calcIMU(); // calculate current yaw/pitch/roll
Serial.println("IMU CALC Done");
doMode(); // calculate yaw/pitch/roll commands
//Serial.println("Mode Done");
doPID(); // smooth yaw/pitch/roll commands
//Serial.println("PID Done");
doMix(); // converts cmds to motor speeds
//Serial.println("Mixing Done");
writeMotors(); // write to pwm
//Serial.println("WritingMotors Done");
mspRead(); // check for new msp msgs
//Serial.println("Message Read Done");
fastLoopTiming = micros() - fastLoopEnd;
}
// the slow loop for communications
unsigned long slowLoopEnd = millis();
slowLoopLength = slowLoopEnd - slowLoopStart;
if ((slowLoopLength) > SLOWLOOPTARGET)
{
slowLoopStart = slowLoopEnd;
long slowLoopTimingStart = micros();
//debugVals[0] = fastLoopTiming;
//debugVals[1] = slowLoopTiming;
mspWrite();
slowLoopTiming = micros() - slowLoopTimingStart;
}
}