-
Notifications
You must be signed in to change notification settings - Fork 0
/
4withoutCPF.cpp
66 lines (44 loc) · 1.17 KB
/
4withoutCPF.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
// Do not remove the include below
#include "PlutoPilot.h"
#include "Xshield.h"
#include "Control.h"
#include "Led.h"
#include "Print.h"
float e_1=0;
//The setup function is called once at Pluto's hardware startup
void plutoInit()
{
Xshield.init(); //Initialize the Xshield
// Add your hardware initialization code here
}
//The function is called once before plutoPilot when you activate Developer Mode
void onPilotStart()
{
Xshield.startRanging();
// do your one time stuffs here
}
// The loop function is called in an endless loop
void plutoPilot()
{
Print.monitor(" L RANGE: ", Xshield.getRange(LS_LEFT));
Print.monitor("\n");
Print.monitor(" R RANGE: ", Xshield.getRange(LS_RIGHT));
Print.monitor("\n");
int L = Xshield.getRange(LS_LEFT);
int R = Xshield.getRange(LS_RIGHT);
int kp,kd;
float e_2 = (L-R)/2;
kp= 6;
kd = 6;
float del_e = e_2 - e_1;
e_1 = e_2;
float u = kp*e_2 + kd*del_e;
Control.setRcCommand(RC_ROLL, 1500+u);
//Add your repeated code here
}
//The function is called once after plutoPilot when you deactivate Developer Mode
void onPilotFinish()
{
//Xshield.stopRanging();
// do your cleanup stuffs here
}