forked from HerricksRobotics/Vex2019
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRC_11040A
112 lines (95 loc) · 3.1 KB
/
RC_11040A
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
#include "robot-config.h"
void leftDrive(int speed){
if speed == 0 {
LeftFront.stop();
LeftBack.stop();
}
else {
//Spin motors in fwd direciton; set velocity to 50rpm
LeftFront.spin(directionType::fwd,speed,velocityUnits::rpm);
LeftBack.spin(directionType::fwd,speed,velocityUnits::rpm);
}
}
void rightDrive(int speed){
if speed == 0 {
RightFront.stop();
RightBack.stop();
}
else {
//Spin motors in fwd direciton; set velocity to 50rpm
RightFront.spin(directionType::fwd,speed,velocityUnits::rpm);
RightBack.spin(directionType::fwd,speed,velocityUnits::rpm);
}
}
void armLift(int speed){
if speed == 0{
Arm1.stop();
Arm2.stop();
}
else{
Arm1.spin(directionType::fwd,speed,velocityUnits::rpm);
Arm2.spin(directionType::fwd,speed,velocityUnits::rpm);
}
}
void armDown(int speed){
if speed == 0{
Arm1.stop();
Arm2.stop();
}
else{
Arm1.spin(directionType::rev,speed,velocityUnits::rpm);
Arm2.spin(directionType::rev,speed,velocityUnits::rpm);
}
}
void intakeBall(int speed){
if speed === 0{
Intake.stop();
}
else{
Intake.spin(directionType::fwd,speed,velocityUnits::rpm);
}
}
void shootBall(int speed){
if speed == 0{
Linlaunch.stop();
}
else{
Linlaunch.spin(directionType::fwd,speed,velocityUnits::rpm);
}
}
int main() {
short leftSpeed = 0; //Initializes speed for leftDrive
short rightSpeed = 0; //Intializes speed for rightDrive
//Left and Right Encoder Setup
LeftEncoder.resetRotation();
RightEncoder.resetRotation();
while (true) {
//Controller 1 Functions: drive train
//Sets right drive train speed, based on Controller 1 axis 2 value
if (Controller1.Axis2.value() > -35 && Controller1.Axis2.value() < 35){
rightSpeed = 0;
}
else{
rightSpeed = Controller1.Axis2.value();
}
//Sets left drive train speed, based on controller 1 axis 2
if (Controller1.Axis3.value() > -35 && Controller1.Axis3.value() < 35){
rightSpeed = 0;
}
else{
rightspeed = Controller1.Axis3.value();
}
//Calls leftDrive and rigth Drive funtions with leftSpeed and rightSpeed as parameters, respectively
leftDrive(leftSpeed);
rightDrive(rightDrive);
//---------------------------------------------------------------------------------
//Controller 2 Functions: Arm movement, Intake, Linear Launcher
//Controls arm functionality
Controller2.ButtonL1.pressed(armLift(100)); //Raises arm with a speed of 100 rpm (fwd direction)
Controller2.ButtonR1.pressed(armDown(100)); //Lowers arm with a speed of 100 rpm (rev direction)
//Controls intake functionality
Controller2.ButtonL2.pressed(intakeBall(100));
//Controls linear launcher
Controller2.ButtonL2.pressed(shootBall(100));
}
}