-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClawBotCompetition.c
191 lines (150 loc) · 3.28 KB
/
ClawBotCompetition.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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#pragma config(Motor, port1, rightMotor, tmotorVex393_HBridge, openLoop, reversed)
#pragma config(Motor, port6, clawMotor, tmotorVex269_MC29, openLoop, reversed)
#pragma config(Motor, port7, armMotor, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port10, leftMotor, tmotorVex393_HBridge, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
//short movingForward = false; //Should be zero
short holdArm = false; //Should be zero
short movingArm = false;
// double speedMultiplier = 1;
void resetMotor()
{
motor[rightMotor] = 0;
motor[leftMotor] = 0;
if (holdArm == false)
{
motor[armMotor] = 0;
}
}
void moveArmUp(int speed)
{
if (movingArm == false) {
motor[armMotor] = speed;
}
}
void freezeArm() {
holdArm = true;
motor[armMotor] = 10;
}
void unfreezeArm() {
holdArm = false;
resetMotor();
}
void holdArmAt(int speed, int waitTime)
{
holdArm = true;
moveArmUp(speed);
wait1Msec(waitTime);
// motor[armMotor] = 20;
}
void turnLeft(int speed, int waitTime)
{
//movingForward = 1;
wait1Msec(1000);
motor[rightMotor] = speed * -1;
motor[leftMotor] = speed;
wait1Msec(waitTime);
resetMotor();
}
void turnRight(int speed, int waitTime)
{
//movingForward = 1;
wait1Msec(1000);
motor[rightMotor] = speed;
motor[leftMotor] = speed * -1;
wait1Msec(waitTime);
resetMotor();
}
void moveArmDown(int speed)
{
if (movingArm == false) {
motor[armMotor] = -1 * speed;
}
}
void closeClawFor()
{
wait1Msec(1000);
motor[clawMotor] = 70;
}
void openClawFor()
{
wait1Msec(750);
motor[clawMotor] = -70;
wait1Msec(800);
resetMotor();
}
void closeClaw(int speed) {
motor[clawMotor] = 70;
}
void openClaw(int speed) {
motor[clawMotor] = -70;
}
void stopArm() {
motor[armMotor] = 0;
}
void stopClaw() {
motor[clawMotor] = 0;
}
void moveForward(int speed, int waitTime)
{
//movingForward = 1;
wait1Msec(3000);
motor[rightMotor] = speed;
motor[leftMotor] = speed;
wait1Msec(waitTime);
resetMotor();
//movingForward = 0;
}
void driveControl(int leftStick, int rightStick) {
//movingForward = true;
motor[rightMotor] = rightStick;
motor[leftMotor] = leftStick;
}
//These are multiplied, put in seconds not milliseconds
void autonomous1() {
moveForward(40, 10000);
}
void autonomous2() {
moveForward(40, 10000);
}
task main {
while() {
if (vexRT[Btn7U] && vexRT[Btn8U]) {
// autonomous1();
}
if (vexRT[Btn7D] && vexRT[Btn8D]) {
// autonomous2();
}
driveControl(vexRT[Ch2], vexRT[Ch3]);
//motor[rightMotor] = vexRT[Ch2];
//motor[leftMotor] = vexRT[Ch3];
//Move Arm
if (vexRT[Btn5D]) {
//unfreezeArm();
moveArmDown(30);
//
//movingArm = true;
} else if (vexRT[Btn5U]) {
//unfreezeArm();
moveArmUp(50);
//movingArm = true;
} else if (vexRT[Btn5U] == false) {
stopArm();
} else if (vexRT[Btn5D] == false) {
stopArm();
}
//Move Claw
if (vexRT[Btn6D])
{
closeClaw(30);
}
else if (vexRT[Btn6U])
{
openClaw(30);
} else if (vexRT[Btn6D] == false) {
stopClaw();
} else if (vexRT[Btn6U] == false) {
stopClaw();
}
}
}