This repository has been archived by the owner on Aug 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.v14.c
322 lines (278 loc) · 9.41 KB
/
code.v14.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#pragma config(Sensor, dgtl1, rightEncoder, sensorQuadEncoder)
#pragma config(Sensor, dgtl3, leftEncoder, sensorQuadEncoder)
#pragma config(Sensor, dgtl5, LSbumper, sensorTouch)
#pragma config(Motor, port2, bottomRight, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port3, bottomLeft, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port4, rightLS, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port5, leftLS, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port6, cone, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port7, topRight, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port8, topLeft, tmotorVex393_MC29, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
/*---------------------------------------------------------------------------*/
/* */
/* Description: Competition template for VEX EDR */
/* */
/*---------------------------------------------------------------------------*/
// This code is for the VEX cortex platform
#pragma platform(VEX2)
// Select Download method as "competition"
#pragma competitionControl(Competition)
//Main competition background code...do not modify!
#include "Vex_Competition_Includes.c"
int threshold = 10;
int LSMAX = 1000;
/*---------------------------------------------------------------------------*/
/* Pre-Autonomous Functions */
/* */
/* You may want to perform some actions before the competition starts. */
/* Do them in the following function. You must return from this function */
/* or the autonomous and usercontrol tasks will not be started. This */
/* function is only called once after the cortex has been powered on and */
/* not every time that the robot is disabled. */
/*---------------------------------------------------------------------------*/
void pre_auton(){
SensorValue(rightEncoder) = 0;
SensorValue(leftEncoder) = 0;
// Set bStopTasksBetweenModes to false if you want to keep user created tasks
// running between Autonomous and Driver controlled modes. You will need to
// manage all user created tasks if set to false.
bStopTasksBetweenModes = true;
// Set bDisplayCompetitionStatusOnLcd to false if you don't want the LCD
// used by the competition include file, for example, you might want
// to display your team name on the LCD in this function.
// bDisplayCompetitionStatusOnLcd = false;
// All activities that occur before the competition starts
// Example: clearing encoders, setting servo positions, ...
}
/*---------------------------------------------------------------------------*/
/* */
/* Autonomous Task */
/* */
/* This task is used to control your robot during the autonomous phase of */
/* a VEX Competition. */
/* */
/* You must modify the code to add your own robot specific commands here. */
/*---------------------------------------------------------------------------*/
void autoLSStop() {
motor[rightLS] = 0;
motor[leftLS] = 0;
}
void autoLSUp(int n) {
//check quadencoders
motor[rightLS] = 90;
motor[leftLS] = 80;
wait1Msec(n);
}
void autoLSDown(int n) {
motor[rightLS] = -90;
motor[leftLS] = -80;
wait1Msec(n);
}
void stopDrive() {
motor[bottomRight] = 0;
motor[bottomLeft] = 0;
motor[topRight] = 0;
motor[topLeft] = 0;
}
void autoRight(int n) {
motor[bottomRight] = -75;
motor[topRight] = 75;
motor[bottomLeft] = 75;
motor[topLeft] = -75;
wait1Msec(n);
stopDrive();
}
void autoLeft(int n) {
motor[bottomRight] = 75;
motor[topRight] = -75;
motor[bottomLeft] = -75;
motor[topLeft] = 75;
wait1Msec(n);
stopDrive();
}
void autoForward(int n) {
motor[bottomRight] = 75;
motor[topRight] = 75;
motor[bottomLeft] = 75;
motor[topLeft] = 75;
wait1Msec(n);
stopDrive();
}
void autoBackward(int n) {
motor[bottomRight] = -75;
motor[topRight] = -75;
motor[bottomLeft] = -75;
motor[topLeft] = -75;
wait1Msec(n);
stopDrive();
}
void shortAutoRightSide() {
//drive forward, pick up a mobile goal, 180 right, drive forward and place it in the 10 point zone
autoForward(1000);
while(SensorValue(LSbumper) == 0) {
autoForward(100);
wait1Msec(10);
}
stopDrive();
autoLSUp(1000);
autoLSStop();
autoBackward(1000);
autoLeft(1800);
autoForward(2500);
stopDrive();
autoLSDown(1000);
autoLSStop();
autoBackward(1000);
}
void shortAutoRightSide5Points() {
autoForward(1000);
while(SensorValue(LSbumper) == 0) {
autoForward(100);
wait1Msec(10);
}
stopDrive();
autoRight(1800);
autoForward(2500);
autoBackward(1000);
}
void shortAutoLeftSide5Points() {
autoForward(1000);
while(SensorValue(LSbumper) == 0) {
autoForward(100);
wait1Msec(10);
}
stopDrive();
autoLeft(1800);
autoForward(2500);
autoBackward(1000);
}
void longAuto() {
shortAutoRightSide();
autoBackward(1000);
autoLeft(1000);
autoForward(3000);
autoLSUp(1000);
autoForward(1000);
}
void oneMinute() {
//drive forward, pick up mobile goal, 180 drive forward and place it in the 10 point zone
//back up, 180, drive forward, pick up mobile goal, place it in the opposite 10 point zone
//back up, 90 left, forward, 90 left, drive forward, pick up mobile goal, 180 drive forward and place it in the 10 point zone
//back up, 180, drive forward, pick up mobile goal, place it in the opposite 10 point zone
longAuto();
autoBackward(1000);
autoLeft(500);
autoForward(1000);
autoLeft(500);
longAuto();
}
task autonomous(){
//shortAutoRightSide();
}
/*---------------------------------------------------------------------------*/
/* */
/* User Control Task */
/* */
/* This task is used to control your robot during the user control phase of */
/* a VEX Competition. */
/* */
/* You must modify the code to add your own robot specific commands here. */
/*---------------------------------------------------------------------------*/
void drive(int y, int x) {
if(abs(x) > threshold) {
//right, bottom right goes backwards, top right goes forward, bottom left goes forward, top left goes backwards
motor[bottomRight] = -x;
motor[topRight] = -x;
motor[bottomLeft] = x;
motor[topLeft] = x;
}
//forward and backward
else if(abs(y) > threshold) {
motor[bottomRight] = y;
motor[topRight] = y;
motor[bottomLeft] = y;
motor[topLeft] = y;
} else {
stopDrive();
}
}
void LS(int extend, int retract) {
//positive LS moves backward
if(extend == 1) {
//if(abs(SensorValue(rightEncoder)) < LSMAX && abs(SensorValue(leftEncoder)) < LSMAX) {
motor[rightLS] = 90;
motor[leftLS] = 80;
//}
}
else if(retract == 1) {
motor[rightLS] = -90;
motor[leftLS] = -80;
}
else {
motor[rightLS] = 0;
motor[leftLS] = 0;
}
}
void claw(int open, int close) {
if(open == 1) {
motor[cone] = 45;
}
else if(close == 1) {
motor[cone] = -45;
}
else {
motor[cone] = 0;
}
}
/*
void clawRotate(int clockwise, int counterclockwise) {
//trigger 8U counter clockwise if looking from the right side of the robot
//trigger 8D clockwise if looking from the right side of the robot
if(clockwise == 1) {
motor[rightCone] = 100;
motor[leftCone] = 100;
}
else if(counterclockwise == 1) {
motor[rightCone] = -100;
motor[leftCone] = -100;
}
else {
motor[rightCone] = 0;
motor[leftCone] = 0;
}
}
*/
int hold = 0;
void rotateStop(int button) {
if(button == 1) {
hold = 1;
}
}
void Riley() {
//drive(vexRT[Ch1], vexRT[Ch3]);
//viking challenge drive
drive(vexRT[Ch3], vexRT[Ch1]);
//for claw
//trigger 5U is claw open
//trigger 5D is claw close
claw(vexRT[Btn5U], vexRT[Btn5D]);
//for LS
//right trigger, button 6D extends
//right trigger, button 6U retracts
LS(vexRT[Btn6D], vexRT[Btn6U]);
//clawRotate(vexRT[Btn8D], vexRT[Btn8U]);
}
void Emily() {
//Ch1 right and left, Ch3 forward and backward
drive(vexRT[Ch1], vexRT[Ch3]);
//5U opens, 5D closes
claw(vexRT[Btn5U], vexRT[Btn5D]);
//6U goes out, 6D comes in
LS(vexRT[Btn6U], vexRT[Btn6D]);
}
task usercontrol() {
while(true) {
Riley();
}
}