-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path2016CWS6.c
158 lines (128 loc) · 3.27 KB
/
2016CWS6.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
#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, I2C_1, , sensorQuadEncoderOnI2CPort, , AutoAssign)
#pragma config(Motor, port1, lmWheel, tmotorVex393TurboSpeed_HBridge, openLoop)
#pragma config(Motor, port2, lbWheel, tmotorVex393TurboSpeed_MC29, openLoop, encoderPort, I2C_1)
#pragma config(Motor, port3, rbWheel, tmotorVex393TurboSpeed_MC29, openLoop, reversed)
#pragma config(Motor, port4, rmWheel, tmotorVex393TurboSpeed_MC29, openLoop, reversed)
#pragma config(Motor, port5, rfWheel, tmotorVex393TurboSpeed_MC29, openLoop, reversed)
#pragma config(Motor, port10, lfWheel, 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!
int velocity;
float flywheelSetpoint;
float motorSpeed;
float flywheelSpeed;
float flywheelKp = .01;
int position1;
int position2;
/*task flywheelVelocity(){
while(true){
position1 = nMotorEncoder(lrFlywheel);
wait1Msec(200);
position2 = nMotorEncoder(lrFlywheel);
wait1Msec(200);
velocity = (position2 - position1)/4;
}
}
task flywheelP(){
float error;
startTask(flywheelVelocity);
while(true){
error = flywheelSetpoint - velocity;
flywheelSpeed += (flywheelKp*error);
if(flywheelSpeed > 127)
flywheelSpeed = 127;
else if (flywheelSpeed < 0)
flywheelSpeed = 0;
motor[urFlywheel] = flywheelSpeed;
motor[lrFlywheel] = flywheelSpeed;
motor[ulFlywheel] = flywheelSpeed;
motor[llFlywheel] = flywheelSpeed;
wait1Msec(30);
}
}
*/
task drive(){
while(true){
motor[rfWheel] = vexRT(Ch2);
motor[rmWheel] = vexRT(Ch2);
motor[rbWheel] = vexRT(Ch2);
motor[lfWheel] = vexRT(Ch3);
motor[lmWheel] = vexRT(Ch3);
motor[lbWheel] = vexRT(Ch3);
wait1Msec(30);
}
}
/*
void speedUpFlywheel(float setpoint){
if(motorSpeed < setpoint)
motorSpeed += 1;
else
motorSpeed = setpoint;
flywheelSetpoint = motorSpeed;
wait1Msec(150);
}
void slowDownFlywheel(){
if(motorSpeed > flywheelSetpoint)
motorSpeed -= 2;
else
motorSpeed = flywheelSetpoint;
motor[urFlywheel] = motorSpeed;
motor[lrFlywheel] = motorSpeed;
motor[ulFlywheel] = motorSpeed;
motor[llFlywheel] = motorSpeed;
wait1Msec(150);
}
task feeder(){
while(true){
if(vexRT(Btn5U)){
if(velocity>flywheelSetpoint-7)
motor[intake2] = 127;
else
motor[intake2] = 0;
}
else if(vexRT(Btn5D))
motor[intake2] = -127;
else
motor[intake2] = 0;
}
wait1Msec(30);
}
task shooter(){
while(true){
if(vexRT(Btn6U)){
while(!vexRT(Btn6D))
flywheelSetpoint = 20;
//flywheelSpeed = 90;
}
else if(vexRT(Btn6D)){
while(!vexRT(Btn6U)){}
//slowDownFlywheel();
}
wait1Msec(30);
}
}
*/
void pre_auton()
{
bStopTasksBetweenModes = true;
}
task autonomous()
{
AutonomousCodePlaceholderForTesting(); // Remove this function call once you have "real" code.
}
task usercontrol()
{
//startTask(shooter);
//startTask(flywheelP);
//startTask(feeder);
startTask(drive);
while (true)
{
}
}