-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path285Z_COMP (upload).c
228 lines (194 loc) · 7.73 KB
/
285Z_COMP (upload).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
#pragma config(UART_Usage, UART1, uartVEXLCD, baudRate19200, IOPins, None, None)
#pragma config(UART_Usage, UART2, uartNotUsed, baudRate4800, IOPins, None, None)
#pragma config(Sensor, in1, pot_arm, sensorNone)
#pragma config(Sensor, dgtl1, enc_fw, sensorQuadEncoder)
#pragma config(Sensor, dgtl3, enc_drive, sensorQuadEncoder)
#pragma config(Motor, port1, intake_cap, tmotorVex393_HBridge, openLoop)
#pragma config(Motor, port2, drive_r1, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port3, drive_r2, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port4, drive_r3, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port5, drive_l1, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port6, drive_l2, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port7, drive_l3, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port8, flywheel, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port9, lift, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port10, intake_ball, 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"
/*---------------------------------------------------------------------------*/
/* 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()
{
bStopTasksBetweenModes = true;
SensorValue[enc_fw] = 0;
SensorValue[enc_drive] = 0;
SensorValue[pot_arm] = 0;
}
/*---------------------------------------------------------------------------*/
/* */
/* 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. */
/*---------------------------------------------------------------------------*/
float rpm(){
SensorValue[enc_fw] = 0;
wait1Msec(10);
float curr = SensorValue[enc_fw];
float rpm = (curr / 0.1666667) * 5;
clearLCDLine(0);
clearLCDLine(1);
displayLCDNumber(0, 5, rpm);
return rpm;
}
task autonomous()
{
int counter = 0;
int target = 0;
int high = 0;
int low = 0;
//target = 930; high = 80; low = 30; //FRONT
target = 1100; high = 90; low = 40; //BACK
while(counter < 295)
{
counter++;
if(rpm() < target) {motor[flywheel] = high;}
else if(rpm() > target) {motor[flywheel] = low;}
if(rpm() >= target) {motor[intake_ball] = 127;}
}
/*
motor[flywheel] = motor[intake_ball] = 0;
motor[drive_l1] = motor[drive_l2] = motor[drive_l3] = motor[drive_r1] = motor[drive_r2] = motor[drive_r3] = 127; //RED
//motor[drive_l1] = motor[drive_l2] = motor[drive_l3] = motor[drive_r1] = motor[drive_r2] = motor[drive_r3] = 65; //BLUE
wait1Msec(1500);
motor[drive_l1] = motor[drive_l2] = motor[drive_l3] = 100; motor[drive_r1] = motor[drive_r2] = motor[drive_r3] = 127; //RED
//motor[drive_l1] = motor[drive_l2] = motor[drive_l3] = -27; motor[drive_r1] = motor[drive_r2] = motor[drive_r3] = 127; //BLUE
wait1Msec(750);
motor[drive_l1] = motor[drive_l2] = motor[drive_l3] = -10;
motor[drive_r1] = motor[drive_r2] = motor[drive_r3] = -10;
*/
}
/*---------------------------------------------------------------------------*/
/* */
/* 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. */
/*---------------------------------------------------------------------------*/
const unsigned int TrueSpeed[128] =
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 21, 21, 21, 22, 22, 22, 23, 24, 24,
25, 25, 25, 25, 26, 27, 27, 28, 28, 28,
28, 29, 30, 30, 30, 31, 31, 32, 32, 32,
33, 33, 34, 34, 35, 35, 35, 36, 36, 37,
37, 37, 37, 38, 38, 39, 39, 39, 40, 40,
41, 41, 42, 42, 43, 44, 44, 45, 45, 46,
46, 47, 47, 48, 48, 49, 50, 50, 51, 52,
52, 53, 54, 55, 56, 57, 57, 58, 59, 60,
61, 62, 63, 64, 65, 66, 67, 67, 68, 70,
71, 72, 72, 73, 74, 76, 77, 78, 79, 79,
80, 81, 83, 84, 84, 86, 86, 87, 87, 88,
88, 89, 89, 90, 90, 127, 127, 127
};
/*float jarize(int speed_raw)
{
float speed_temp;
if(speed_raw >= 0)
{speed_temp = (speed_raw * speed_raw) / 127;}
else
{speed_temp = (speed_raw * speed_raw) / -127;}
if(speed_temp <= 122) {speed_temp = speed_temp +5;
return floor(speed_temp);
}*/
task usercontrol()
{
motor[flywheel] = 40;
int target = 0;
int speed_drive_L = 0;
int speed_drive_R = 0;
while (true)
{
if(vexRT[Ch2] <= 0)
{
speed_drive_R = -TrueSpeed[abs(vexRT[Ch2])];
}
else
{
speed_drive_R = TrueSpeed[vexRT[Ch2]];
}
if(vexRT[Ch3] <= 0)
{
speed_drive_L = -TrueSpeed[abs(vexRT[Ch3])];
}
else
{
speed_drive_L = TrueSpeed[vexRT[Ch3]];
}
//tank drive
motor[drive_r1] = motor[drive_r2] = motor[drive_r3] = speed_drive_R;
motor[drive_l1] = motor[drive_l2] = motor[drive_l3] = speed_drive_L;
//bang bang control for flywheel
if(rpm() < target)
{motor[flywheel] = 70;}
else if(rpm() > target)
{motor[flywheel] = 30;}
//Flywheel Target//
if(vexRT[Btn8L]){
target = 920;
}
else if(vexRT[Btn8D]){
target = 720;
motor[flywheel] = 0;
}
//joystick controls for other motors
if(vexRT[Btn5U]){
motor[lift] = 127;
}
else if(vexRT[Btn5D]){
motor[lift] = -127;
}
else{
motor[lift] = 0;
}
if(vexRT[Btn6U]){
motor[intake_ball] = 100;
}
else if(vexRT[Btn6D]){
motor[intake_ball] = -100;
}
else{
motor[intake_ball] = 0;
}
if(vexRT[Btn7L]){
motor[intake_cap] = -60;
}
else if(vexRT[Btn7R]){
motor[intake_cap] = 60;
}
else{
motor[intake_cap] = 0;
}
}
}