-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathRX.cpp
77 lines (58 loc) · 1.61 KB
/
RX.cpp
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
#include <Arduino.h>
#include "config.h"
#include "SBUS.h"
#include "RX.h"
int throttleRx, rollRx, pitchRx, yawRx, swA, swB, swC, swD, failsafe;
// y = ((varRate*x)^3)/180^varRate
SBUS sBus;
void initSbus(){
sBus.begin();
}
void readRx(){
sBus.FeedLine();
if (sBus.toChannels == 1){
sBus.UpdateChannels();
sBus.toChannels = 0;
//assign receieved remote controller values to variables
throttleRx = sBus.channels[0];
rollRx = sBus.channels[1];
pitchRx = sBus.channels[2];
yawRx = sBus.channels[3];
swA = sBus.channels[4];
swB = sBus.channels[5];
swC = sBus.channels[6];
swD = sBus.channels[7];
failsafe = sBus.failsafe_status;
// Map gimbals values to desired outputs
throttleRx = map(throttleRx, MINTHROTTLE, MAXTHROTTLE, ESC_MIN, (ESC_MAX * ESC_TOLERANCE));
rollRx = map(rollRx, MINTHROTTLE, MAXTHROTTLE, (RC_RATES*-1), RC_RATES);
pitchRx = map(pitchRx, MINTHROTTLE, MAXTHROTTLE, (RC_RATES*-1), RC_RATES);
yawRx = map(yawRx, MINTHROTTLE, MAXTHROTTLE, (RC_RATES*-1), RC_RATES);
// map switches to appropriate values
swA = map(swA, MINTHROTTLE, MAXTHROTTLE, 0, 2);
// swB = map(swB, MINTHROTTLE, MAXTHROTTLE, 0, 2);
// swC = map(swC, MINTHROTTLE, MAXTHROTTLE, 0, 2);
// swD = map(swD, MINTHROTTLE, MAXTHROTTLE, 0, 2);
}
}
float chThrottle(){
return throttleRx;
}
int chRoll() {
return rollRx;
}
int chPitch() {
return pitchRx;
}
int chYaw() {
return yawRx;
}
int chAux1() {
return swA;
}
int chAux2() {
return swB;
}
int failsafeState(){
return failsafe;
}