-
Notifications
You must be signed in to change notification settings - Fork 1
/
RightRed10ptWORLDS
343 lines (277 loc) · 8.93 KB
/
RightRed10ptWORLDS
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
#pragma config(Sensor, dgtl2, quadA, sensorQuadEncoder)
#pragma config(Sensor, dgtl4, quadB, sensorQuadEncoder)
#pragma config(Motor, port1, LBdrive, tmotorVex393HighSpeed_HBridge, openLoop)
#pragma config(Motor, port2, Ldr4b, tmotorVex393HighSpeed_MC29, openLoop, reversed)
#pragma config(Motor, port3, Lmobgoal, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port4, L4bar, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port5, LFdrive, tmotorVex393HighSpeed_MC29, openLoop)
#pragma config(Motor, port6, RFdrive, tmotorVex393HighSpeed_MC29, openLoop, reversed)
#pragma config(Motor, port7, intake, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port8, Rmobgoal, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port9, Rdr4b, tmotorVex393HighSpeed_MC29, openLoop)
#pragma config(Motor, port10, RBdrive, tmotorVex393HighSpeed_HBridge, openLoop, reversed)
/*---------------------------------------------------------------------------*/
/* */
/* 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"
/*---------------------------------------------------------------------------*/
/* 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()
{
// 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. */
/*---------------------------------------------------------------------------*/
//autonomous is to get a mobile goal, stack preload on goal, and drop off in 10 point zone
//red right side (hard)
task autonomous()
{
// power to intake
motor[intake] = 40;
// deploying 4bar + dr4b
motor[L4bar] = 127;
motor[Rdr4b] = 127;
motor[Ldr4b] = 127;
wait1Msec(1000);
motor[Rdr4b] = 0;
motor[Ldr4b] = 0;
motor[L4bar] = 0;
// drive forward and deploy mobile goal lift
motor[LFdrive] = 127;
motor[RFdrive] = 127;
motor[RBdrive] = 127;
motor[LBdrive] = 127;
motor[Lmobgoal] = 127;
motor[Rmobgoal] = 127;
wait1Msec(1000);
//stop lowering lift
motor[Lmobgoal] = 0;
motor[Rmobgoal] = 0;
wait1Msec(600);
motor[LFdrive] = 0;
motor[RFdrive] = 0;
motor[RBdrive] = 0;
motor[LBdrive] = 0;
// pick up mobile goal
motor[Lmobgoal] = -127;
motor[Rmobgoal] = -127;
wait1Msec(1000);
motor[Lmobgoal] = 0;
motor[Rmobgoal] = 0;
// driving backwards + pivot
motor[LFdrive] = -75;
motor[RFdrive] = -127;
motor[LBdrive] = -75;
motor[RBdrive] = -127;
// lower lift to drop cone while backing up
motor[Rdr4b] = -127;
motor[Ldr4b] = -127;
motor[L4bar] = 127;
wait1Msec(1000);
motor[Rdr4b] = 0;
motor[Ldr4b] = 0;
motor[L4bar] = 0;
wait1Msec(500);
motor[LFdrive] = 0;
motor[RFdrive] = 0;
motor[RBdrive] = 0;
motor[LBdrive] = 0;
// drop cone
motor[intake] = -127;
wait1Msec(200);
motor[intake] = 0;
wait1Msec(150);
// pivot and raise lift
motor[LFdrive] = 100;
motor[RFdrive] = -100;
motor[LBdrive] = 100;
motor[RBdrive] = -100;
motor[Rdr4b] = 127;
motor[Ldr4b] = 127;
wait1Msec(500);
motor[Rdr4b] = 0;
motor[Ldr4b] = 0;
wait1Msec(500);
//wait1Msec();
motor[LFdrive] = 0;
motor[RFdrive] = 0;
motor[RBdrive] = 0;
motor[LBdrive] = 0;
// put in zone
motor[LFdrive] = 127;
motor[RFdrive] = 127;
motor[LBdrive] = 127;
motor[RBdrive] = 127;
wait1Msec(550);
motor[LFdrive] = 0;
motor[RFdrive] = 0;
motor[RBdrive] = 0;
motor[LBdrive] = 0;
motor[Lmobgoal] = 127;
motor[Rmobgoal] = 127;
wait1Msec(1000);
motor[Lmobgoal] = 0;
motor[Rmobgoal] = 0;
// drive back
motor[LFdrive] = -80;
motor[RFdrive] = -80;
motor[LBdrive] = -80;
motor[RBdrive] = -80;
motor[Rdr4b] = 127;
motor[Ldr4b] = 127;
wait1Msec(400);
motor[Rdr4b] = 0;
motor[Ldr4b] = 0;
motor[LFdrive] = 0;
motor[RFdrive] = 0;
motor[RBdrive] = 0;
motor[LBdrive] = 0;
// raise mobile goal lift
motor[Lmobgoal] = -127;
motor[Rmobgoal] = -127;
wait1Msec(1000);
motor[Lmobgoal] = 0;
motor[Rmobgoal] = 0;
// drive out of zone
//motor[LFdrive] = -80;
//motor[RFdrive] = -80;
//motor[LBdrive] = -80;
//motor[RBdrive] = -80;
motor[Rdr4b] = -127;
motor[Ldr4b] = -127;
wait1Msec(400);
//motor[LFdrive] = 0;
//motor[RFdrive] = 0;
//motor[RBdrive] = 0;
//motor[LBdrive] = 0;
wait1Msec(400);
motor[Rdr4b] = 0;
motor[Ldr4b] = 0;
}
/*---------------------------------------------------------------------------*/
/* */
/* 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. */
/*---------------------------------------------------------------------------*/
//joystick program from JoystickControl_v4 (3-1-18)
task usercontrol()
{
// User control code here, inside the loop
int kD = 2;
int kAB = 2;
// int kD2 = 2;
float kAB2 = 0.5;
int prevErrorAB = 0;
SensorValue[quadA] = 0;
SensorValue[quadB] = 0;
int setpoint = 0;
int errorStaticA = 0;
int errorStaticB = 0;
while(true)
{
// DR4B
int errorAB = SensorValue[quadA] - SensorValue[quadB];
int derivativeAB = errorAB - prevErrorAB;
prevErrorAB = errorAB;
if(vexRT[Btn7U] == 1)
{
motor[Ldr4b] = 127 - errorAB*kAB - derivativeAB*kD;
motor[Rdr4b] = 127 + errorAB*kAB + derivativeAB*kD;
setpoint = (SensorValue[quadA] + SensorValue[quadB])/2;
}
else if(vexRT[Btn7D] == 1)
{
motor[Ldr4b] = -127 - errorAB*kAB - derivativeAB*kD;
motor[Rdr4b] = -127 + errorAB*kAB + derivativeAB*kD;
setpoint = (SensorValue[quadA] + SensorValue[quadB])/2;
}
else
{
errorStaticA = setpoint - SensorValue[quadA];
errorStaticB = setpoint - SensorValue[quadB];
motor[Ldr4b] = errorStaticA*kAB2;
motor[Rdr4b] = errorStaticB*kAB2;
}
//Drive Chain
motor[LFdrive] = vexRT[Ch3];
motor[LBdrive] = vexRT[Ch3];
motor[RFdrive] = vexRT[Ch2];
motor[RBdrive] = vexRT[Ch2];
//mobile goal
if(vexRT[Btn8U] == 1)
{
motor[Lmobgoal] = 127;
motor[Rmobgoal] = 127;
}
else if (vexRT[Btn8D] == 1)
{
motor[Lmobgoal] = -127;
motor[Rmobgoal] = -127;
}
else
{
motor[Lmobgoal] = -20;
motor[Rmobgoal] = -20;
}
// intake
if (vexRT[Btn5U] == 1)
{
motor[intake] = 127;
}
else if (vexRT[Btn5D] == 1)
{
motor[intake] = -127;
}
else
{
motor[intake] = 20;
}
// 4bar
if (vexRT[Btn6U] == 1)
{
motor[L4bar] = 127;
}
else if (vexRT[Btn6D] == 1)
{
motor[L4bar] = -127;
}
else
{
motor[L4bar] = 0;
}
}
}