-
Notifications
You must be signed in to change notification settings - Fork 0
/
bat.c
78 lines (67 loc) · 1.46 KB
/
bat.c
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
#ifndef BAT_C
#define BAT_C
/*
BAT.C
Controls the ball-shooting bat
Jeffrey Shen
*/
//Intake
void intakeUp(){
motorReq[M_INTAKE] = 127;
}
void intakeDown(){
motorReq[M_INTAKE] = -127;
}
void intakeStop(){
motorReq[M_INTAKE] = 0;
}
//Catapult
bool catapultInPosition(){ //Is the catapult in the proper position for loading and shooting
return SensorValue(S_TOP_SONAR) != -1 && SensorValue(S_TOP_SONAR) <= 80;
}
void moveCatapult(int CMD){
if(CMD == UP || CMD == DOWN) CMD = CMD * 127;
motorReq[M_CATAPULT] = CMD;
}
void lowerCatapultToIntake(){ //Lower lift to ball loading
if(!catapultInPosition()){
int t0 = time1[T1];
moveCatapult(DOWN);
while(!catapultInPosition() && !isTimedOut(t0 + 4000) && !isBailedOut()){
moveCatapult(DOWN);
wait1Msec(10);
}
moveCatapult(STOP);
}
}
void fireCatapult(){
int t0 = time1[T1];
moveCatapult(DOWN);
while(catapultInPosition() && !isTimedOut(t0 + 1000) && !isBailedOut()){
moveCatapult(DOWN);
wait1Msec(10);
}
moveCatapult(STOP);
}
task catapultTask(){
while(true){
if(CATAPULT_COMMAND == UP) {
moveCatapult(UP);
}
else if(CATAPULT_COMMAND == DOWN){
moveCatapult(DOWN);
///if(vexRT[Btn8R] == 0) CATAPULT_COMMAND = RESET;
}
else if(CATAPULT_COMMAND == SHOOT) {
fireCatapult();
wait1Msec(200);
CATAPULT_COMMAND = RESET;
}
else if(CATAPULT_COMMAND == RESET) {
lowerCatapultToIntake();
}
else if(CATAPULT_COMMAND != MANUAL) moveCatapult(STOP);
wait1Msec(50);
}
}
#endif