-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtank control.cpp
91 lines (71 loc) · 2.39 KB
/
tank control.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "robot-config.h"
void driveLeft(){
int scaledPower {Controller.Axis3.value()};
if (abs(scaledPower) < 5)
scaledPower = 0;
else
scaledPower = ( (scaledPower^3/100) * scaledPower ) / 100;
if (Controller.Axis3.value() < 0)
scaledPower = scaledPower * -1;
else
scaledPower = scaledPower * 1;
leftDriveFront.spin(directionType::fwd, scaledPower, velocityUnits::pct);
leftDriveBack.spin(directionType::fwd, scaledPower, velocityUnits::pct);
}
void driveRight(){
int scaledPower {Controller.Axis2.value()};
if (abs(scaledPower) < 5)
scaledPower = 0;
else
scaledPower = ( (scaledPower^3/100) * scaledPower ) / 100;
if (Controller.Axis2.value() < 0)
scaledPower = scaledPower * -1;
else
scaledPower = scaledPower * 1;
rightDriveFront.spin(directionType::fwd, scaledPower, velocityUnits::pct);
rightDriveBack.spin(directionType::fwd, scaledPower, velocityUnits::pct);
}
static bool reverse {false};
static bool toggle {false};
static int mode {1};
void toggleIntake()
{
toggle = !toggle;
if (toggle)
ballIntake.spin(directionType::fwd, 100, velocityUnits::pct);
else
ballIntake.spin(directionType::fwd, 0, velocityUnits::pct);
}
void puIntake()
{ballIntake.spin(directionType::fwd, 100, velocityUnits::pct);}
void pdIntake()
{
ballIntake.spin(directionType::fwd, 0, velocityUnits::pct);
reverse = false;
}
void rIntake()
{
ballIntake.spin(directionType::fwd, -100, velocityUnits::pct);
reverse = true;
}
void puIndexer()
{indexer.spin(directionType::fwd, 100, velocityUnits::pct);}
void pdIndexer()
{indexer.spin(directionType::fwd, 0, velocityUnits::pct);}
void rIndexer()
{indexer.spin(directionType::fwd, -100, velocityUnits::pct);}
int main() {
Controller.ButtonR1.pressed(puIndexer); //> indexer
Controller.ButtonR1.released(pdIndexer);
Controller.ButtonR2.pressed(toggleIntake); //> intake toggle
Controller.ButtonL2.pressed(rIntake); //> reverse
Controller.ButtonL2.pressed(rIndexer);
Controller.ButtonL2.released(pdIntake);
Controller.ButtonL2.released(pdIndexer);
while(1){
//flywheel.spin(directionType::fwd, 170, velocityUnits::rpm);
driveLeft();
driveRight();
}
/************* Ball Intake & Indexer *************/
}