-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCitiGalsV11RobotC.c
306 lines (261 loc) · 9.63 KB
/
CitiGalsV11RobotC.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
#pragma config(Motor, port1, leftBack, tmotorVex393_HBridge, openLoop)
#pragma config(Motor, port2, leftTop, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port3, rightBack, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port4, mobileLift, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port5, leftScissor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port6, rightScissor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port7, arm, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port8, claw, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port10, rightTop, tmotorVex393_HBridge, 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"
#define C1LX vexRT[Ch2]
#define C1LY vexRT[Ch1]
#define C1RX vexRT[Ch4]
#define FULLPWR 127
#define HALFPWR 63
#define QTRPWR 32
//int X2 = 0, Y1 = 0, X1 = 0, threshold = 15;
#define Y1 vexRT[Ch1]
#define X1 vexRT[Ch2]
#define X2 vexRT[Ch4]
void sideDrive(int drivespd_direction, int time)
{
//this function drives to the left or the right at a chosen speed
motor[rightTop] = drivespd_direction;
motor[leftBack] = -drivespd_direction;
wait1Msec(time); //1000 miliseconds is 1 second
stopAllMotors();
}
void sideDriveGoal(int drivespd_direction, int time)
{
//this function drives to the left or the right at a chosen speed
motor[rightTop] = drivespd_direction - 48;
motor[leftBack] = -drivespd_direction;
wait1Msec(time); //1000 miliseconds is 1 second
stopAllMotors();
}
void frontDrive(int drivespd_direction, int time)
{
//this function drives forward of backward at a chosen speed
motor[rightBack] = drivespd_direction;
motor[leftTop] = -drivespd_direction;
wait1Msec(time);
}
void turnNinetyNinety(int drivespd_direction, int time)
{
motor[rightBack] = drivespd_direction - 10;
motor[leftBack] = drivespd_direction;
motor[rightTop] = drivespd_direction - 10;
motor[leftTop] = drivespd_direction - 10;
wait1Msec(time);
}
void scissorLift (int spd)
{
motor[leftScissor] = spd;
motor[rightScissor] = spd;
wait1Msec(1000); //still have to find out how long it takes to lift the scissor lift
}
void mobileLiftOnly (int spd, int time)
{
motor[mobileLift] = spd;
wait1Msec(time);
}
void mobileLiftDrive (int spd, int time)
{
motor[rightBack] = spd;
motor[leftTop] = -spd;
wait1Msec(time);
int count = 0;
while (count <1 && motor[leftTop] == -spd && motor[rightBack] == spd)
{
motor[mobileLift] = FULLPWR;
wait1Msec(time);
count++;
}
}
task mobileHook ()
{
while(1)
{
motor[mobileLift] = FULLPWR;
wait1Msec(9500);
}
}
task mobileHookTwo ()
{
while(1)
{
motor[mobileLift] = -FULLPWR;
wait1Msec(4000);
}
}
/*---------------------------------------------------------------------------*/
/* 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. */
/*---------------------------------------------------------------------------*/
task autonomous()
{
// ..........................................................................
//I
motor [mobileLift] = -FULLPWR;
wait1Msec(550);
frontDrive(HALFPWR, 2990);
//Move Robot forward and lift hook at same time.
int i = 0;
while(i < 10)
{
frontDrive(-HALFPWR, 100);
mobileLiftOnly(HALFPWR, 100);
i += 1;
}
//Next step in program
i = 0;
while(i < 10)
{
frontDrive(-HALFPWR, 100);
mobileLiftOnly(HALFPWR, 100);
i += 1;
}
turnNinetyNinety(HALFPWR, 500); //TEST TIME
//sideDrive(FULLPWR, 1000);
//turnNinetyNinety(-FULLPWR, 250); //should be the same direction turn as one above
//II
// frontDrive(-HALFPWR, 4000);
// move diagonally for abt 2-3 sec
// sideDrive(HALFPWR, 4000);
// ..........................................................................
// Remove this function call once you have "real" code.
AutonomousCodePlaceholderForTesting();
}
/*---------------------------------------------------------------------------*/
/* */
/* 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. */
/*---------------------------------------------------------------------------*/
task usercontrol()
{
// User control code here, inside the loop
while (true)
{
// This is the main execution loop for the user control program.
// Each time through the loop your program should update motor + servo
// values based on feedback from the joysticks.
//motor power levels range from -127 (full reverse) to 0 (stopped) to 127 (full power)
// ........................................................................
//sets each of the wheel/chassis motors to a channel on the joystick
/* motor[leftTop] = -C1LY - C1LX - C1RX;
motor[rightTop] = C1LY - C1LX - C1RX;
motor[rightBack] = C1LY + C1LX - C1RX;
motor[leftBack] = -C1LY + C1LX - C1RX;
*/
motor[leftTop] = C1LX - C1RX;
motor[leftBack] = -C1LY - C1RX;
motor[rightBack] = - C1LX - C1RX;
motor[rightTop] = C1LY - C1RX;
/*motor[leftTop] = Y1 + X2;
motor[leftBack] = X1 - X2;
motor[rightBack] = Y1 - X2;
motor[rightTop] = X1 + X2;
*/
//claw moves one direction when button 7D pressed
if (vexRT[Btn7D] == 1)
{
motor[claw] = HALFPWR; //motor forward for about half power
}
else if (vexRT[Btn7L] == 1)
{
motor[claw] = -HALFPWR; //claw moves in opposite direction when button 7L pressed
}
else
{
motor [claw] = 0;
}
//arm moves one direction when button 7D pressed
if (vexRT[Btn7R] == 1)
{
motor[arm] = HALFPWR; //motor forward for about half power
}
else if (vexRT[Btn7U] == 1)
{
motor[arm] = -HALFPWR; //arm moves in opposite direction when button 7L pressed
}
else
{
motor [arm] = 0;
}
//scissor lift moves up when 6U pressed
if (vexRT [Btn6U] == 1)
{
motor[leftScissor] = HALFPWR;
motor[rightScissor] = -HALFPWR;
}
else if (vexRT[Btn6D] == 1) //if 6D is pressed then scissor lift down
{
motor[leftScissor] = -QTRPWR;
motor[rightScissor] = QTRPWR;
}
else
{
motor[leftScissor] = 0;
motor[rightScissor] = 0;
}
//goal lift moves up when 5U pressed
if (vexRT [Btn5U] == 1)
{
motor[mobileLift] = HALFPWR;
}
else if (vexRT [Btn5D] == 1)
{
motor[mobileLift] = -HALFPWR;
}
else
{
motor[mobileLift] = 0;
}
// ........................................................................
// Remove this function call once you have "real" code.
//UserControlCodePlaceholderForTesting();
}
}