-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path2016CWS2.c
181 lines (155 loc) · 4.36 KB
/
2016CWS2.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
#pragma config(UART_Usage, UART2, uartNotUsed, baudRate4800, IOPins, None, None)
#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, in1, , sensorAnalog)
#pragma config(Sensor, dgtl1, shooterL, sensorTouch)
#pragma config(Sensor, dgtl2, topIntakeL, sensorTouch)
#pragma config(Sensor, dgtl3, tiltL, sensorTouch)
#pragma config(Sensor, I2C_1, , sensorQuadEncoderOnI2CPort, , AutoAssign)
#pragma config(Sensor, I2C_2, , sensorQuadEncoderOnI2CPort, , AutoAssign)
#pragma config(Sensor, I2C_3, , sensorQuadEncoderOnI2CPort, , AutoAssign)
#pragma config(Sensor, I2C_4, , sensorQuadEncoderOnI2CPort, , AutoAssign)
#pragma config(Motor, port1, LMbase, tmotorVex393TurboSpeed_HBridge, openLoop, encoderPort, I2C_3)
#pragma config(Motor, port2, LFbase, tmotorVex393TurboSpeed_MC29, openLoop)
#pragma config(Motor, port3, RBbase, tmotorVex393TurboSpeed_MC29, openLoop)
#pragma config(Motor, port4, tilt, tmotorVex393TurboSpeed_MC29, openLoop, encoderPort, I2C_1)
#pragma config(Motor, port5, RMbase, tmotorVex393TurboSpeed_MC29, openLoop, encoderPort, I2C_2)
#pragma config(Motor, port6, RFbase, tmotorVex393TurboSpeed_MC29, openLoop)
#pragma config(Motor, port7, rShooter, tmotorVex393HighSpeed_MC29, openLoop, encoderPort, I2C_4)
#pragma config(Motor, port8, lShooter, tmotorVex393HighSpeed_MC29, openLoop)
#pragma config(Motor, port9, rIntake, tmotorVex393TurboSpeed_MC29, openLoop)
#pragma config(Motor, port10, LBbase, tmotorVex393TurboSpeed_HBridge, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
#pragma platform(VEX)
//Competition Control and Duration Settings
#pragma competitionControl(Competition)
#pragma autonomousDuration(20)
#pragma userControlDuration(120)
#include "Vex_Competition_Includes.c" //Main competition background code...do not modify!
float shooterKp = 0.3;
float tiltKp = 0.5;
int shooterSetpoint;
int tiltSetpoint;
task drive(){
while(true){
motor[RFbase] = -vexRT[Ch2];
motor[RMbase] = -vexRT[Ch2];
motor[RBbase] = -vexRT[Ch2];
motor[LFbase] = vexRT[Ch3];
motor[LMbase] = vexRT[Ch3];
motor[LBbase] = vexRT[Ch3];
wait1Msec(25);
}
}
bool isBallInShooter(){
return((bool)(SensorValue(shooterL)));
}
bool isBallInIntake(){
return((bool)SensorValue(topIntakeL));
}
task intake(){
while(true){
if(!isBallInShooter()){
if(vexRT[Btn5U])
motor[rIntake] = 127;
else if(vexRT[Btn5D])
motor[rIntake] = -127;
else
motor[rIntake] = 0;
}
else if(isBallInIntake()){
if(vexRT[Btn5D])
motor[rIntake] = -127;
else
motor[rIntake] = 0;
}
else{
if(vexRT[Btn5U])
motor[rIntake] = 127;
else if(vexRT[Btn5D])
motor[rIntake] = -127;
else
motor[rIntake] = 0;
}
wait1Msec(25);
}
}
task shooterP(){
float encoderValue;
float error;
float drive;
while(true){
encoderValue = nMotorEncoder(rShooter);
error = shooterSetpoint - encoderValue;
drive = (shooterKp*error);
if(drive > 127)
drive = 127;
motor[rShooter] = drive;
motor[lShooter] = drive;
wait1Msec(25);
}
}
task tiltP(){
float encoderValue;
float error;
float drive;
while(true){
encoderValue = SensorValue(I2C_1);
error = tiltSetpoint - encoderValue;
drive = (tiltKp*error);
if(drive > 127)
drive = 127;
else if(drive < -127)
drive = -127;
motor[tilt] = drive;
wait1Msec(25);
}
}
task tilting(){
startTask(tiltP);
while(true){
if(tiltL)
nMotorEncoder(tilt) = 0;
if(vexRT(Btn8D))
tiltSetpoint = 0;
else if(vexRT(Btn8L))
tiltSetpoint = -800;
else if(vexRT(Btn8U))
tiltSetpoint = -2800;
wait1Msec(25);
}
}
void shootCycle(){
shooterSetpoint += 1175;
}
task shooter(){
startTask(shooterP);
while(true){
if(isBallInShooter() && vexRT[Btn6U]){
shootCycle();
while(isBallInShooter() && vexRT[Btn6U])
wait1Msec(25);
}
wait1Msec(300);
}
}
void pre_auton()
{
shooterSetpoint = 0;
while(!SensorValue(tiltL))
motor[tilt] = 127;
motor[tilt] = -10;
SensorValue(I2C_1) = 0;
nMotorEncoder(tilt) = 0;
wait1Msec(2000);
motor[tilt] = 0;
}
task autonomous()
{
}
task usercontrol()
{
startTask(drive);
startTask(shooter);
startTask(tilting);
startTask(intake);
}