-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02-teleop before break
230 lines (210 loc) · 6.86 KB
/
02-teleop before break
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
#pragma config(Hubs, S1, HTMotor, HTMotor, HTMotor, HTMotor)
#pragma config(Hubs, S3, HTServo, none, none, none)
#pragma config(Sensor, S1, , sensorI2CMuxController)
#pragma config(Sensor, S2, INF, sensorHiTechnicIRSeeker1200)
#pragma config(Sensor, S3, , sensorI2CMuxController)
#pragma config(Sensor, S4, RGB, sensorCOLORFULL)
#pragma config(Motor, mtr_S1_C1_1, yellow, tmotorTetrix, openLoop, encoder)
#pragma config(Motor, mtr_S1_C1_2, red, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C2_1, blue, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C2_2, green, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C3_1, arm, tmotorTetrix, openLoop, encoder)
#pragma config(Motor, mtr_S1_C3_2, whisk, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C4_1, lift, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C4_2, flag, tmotorTetrix, openLoop)
#pragma config(Servo, srvo_S3_C1_1, autoflipper, tServoStandard)
#pragma config(Servo, srvo_S3_C1_2, wrist, tServoStandard)
#pragma config(Servo, srvo_S3_C1_3, servo3, tServoNone)
#pragma config(Servo, srvo_S3_C1_4, servo4, tServoNone)
#pragma config(Servo, srvo_S3_C1_5, servo5, tServoNone)
#pragma config(Servo, srvo_S3_C1_6, servo6, tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
// teleopblockparty001.c
#include "JoystickDriver.c";
string direction = "yellow";
void initializeRobot(){
nNoMessageCounterLimit = 100;
servo[autoflipper] = 20;
motor[arm] = 0;
return;
}
float DZ(float input){
if(input > -10 && input < 10){
return 0;
}else{
return input;
}
}
task autoflip(){
wait10Msec(500);
servo[autoflipper] = 0;
wait10Msec(100);
servo[autoflipper] = 240;
}
task directionCont(){
while(true){
getJoystickSettings(joystick);
if(joy1Btn(1)){
direction = "blue";
}else if(joy1Btn(2)){
direction = "yellow";
}else if(joy1Btn(3)){
direction = "red";
}else if(joy1Btn(4)){
direction = "green";
}
abortTimeslice();
}
}
task drive(){
int turn;
while(true){
if(joystick.joy1_TopHat == 2){
turn = 100;
}else if(joystick.joy1_TopHat == 6){
turn = -100;
}else{
turn = 0;
}
getJoystickSettings(joystick);
if(direction == "red"){
motor[yellow] = (((DZ(joystick.joy1_y1)+DZ(joystick.joy1_x1))/128.0)*100) - turn;
motor[blue] = (((DZ(joystick.joy1_y1)-DZ(joystick.joy1_x1))/128.0)*100) - turn;
motor[green] = -(((DZ(joystick.joy1_y1)+DZ(joystick.joy1_x1))/128.0)*100) - turn;
motor[red] = (((DZ(joystick.joy1_x1)-DZ(joystick.joy1_y1))/128.0)*100) - turn;
}else if(direction == "yellow"){
//default direction
motor[red] = (((DZ(joystick.joy1_y1)+DZ(joystick.joy1_x1))/128.0)*100) - turn;
motor[yellow] = (((DZ(joystick.joy1_y1)-DZ(joystick.joy1_x1))/128.0)*100) - turn;
motor[blue] = -(((DZ(joystick.joy1_y1)+DZ(joystick.joy1_x1))/128.0)*100) - turn;
motor[green] = (((DZ(joystick.joy1_x1)-DZ(joystick.joy1_y1))/128.0)*100) - turn;
}else if(direction == "blue"){
motor[green] = (((DZ(joystick.joy1_y1)+DZ(joystick.joy1_x1))/128.0)*100) - turn;
motor[red] = (((DZ(joystick.joy1_y1)-DZ(joystick.joy1_x1))/128.0)*100) - turn;
motor[yellow] = -(((DZ(joystick.joy1_y1)+DZ(joystick.joy1_x1))/128.0)*100) - turn;
motor[blue] = (((DZ(joystick.joy1_x1)-DZ(joystick.joy1_y1))/128.0)*100) - turn;
}else if(direction == "green"){
motor[blue] = (((DZ(joystick.joy1_y1)+DZ(joystick.joy1_x1))/128.0)*100) - turn;
motor[green] = (((DZ(joystick.joy1_y1)-DZ(joystick.joy1_x1))/128.0)*100) - turn;
motor[red] = -(((DZ(joystick.joy1_y1)+DZ(joystick.joy1_x1))/128.0)*100) - turn;
motor[yellow] = (((DZ(joystick.joy1_x1)-DZ(joystick.joy1_y1))/128.0)*100) - turn;
}
}
}
task lifter(){
while(true){
if(joy1Btn(8)){
motor[lift] = -100;
}else if(joy1Btn(6)){
motor[lift] = 100;
}else if(joy2Btn(8)){
motor[lift] = -100;
}else if(joy2Btn(6)){
motor[lift] = 100;
}else{
motor[lift] = 0;
}
abortTimeslice();
}
}
task flagger(){
while(true){
if(joy1Btn(5)){
motor[flag] = 100;
}else if(joy2Btn(5)){
motor[flag] = 100;
}else{
motor[flag] = 0;
}
abortTimeslice();
}
}
task armer(){
while(true){
if(joystick.joy1_TopHat == 4){
motor[arm] = -60;
}else if(joystick.joy1_TopHat == 0){
motor[arm] = 60;
}else if(joystick.joy2_TopHat == 0){
motor[arm] = 60;
}else if(joystick.joy2_TopHat == 4){
motor[arm] = -60;
}else{
motor[arm] = 0;
}
if(DZ(joystick.joy1_y2) > 15){
servo[wrist] -= ((DZ(joystick.joy1_y2))/100);
}else if(DZ(joystick.joy1_y2) < -15){
servo[wrist] -= ((DZ(joystick.joy1_y2))/100);
}else if(DZ(joystick.joy2_y2) > 15){
servo[wrist] -= ((DZ(joystick.joy2_y2))/100);
}else if(DZ(joystick.joy2_y2) < -15){
servo[wrist] -= ((DZ(joystick.joy2_y2))/100);
}else if(joy1Btn(9)){
//even though it says 8
servo[wrist] = 0;
wait10Msec(50);
while(nMotorEncoder[arm] > 10 && joystick.joy1_TopHat == -1 && joystick.joy2_TopHat == -1){
motor[arm] = -30;
motor[whisk] = 10;
}
motor[arm] = 0;
servo[wrist] = 123;
motor[whisk] = 0;
}else if(joy1Btn(10)){
//enev though it says 9
servo[wrist] = 0;
wait10Msec(70);
while(nMotorEncoder[arm] < 4753 && joystick.joy1_TopHat == -1 && joystick.joy2_TopHat == -1){
motor[arm] = 30;
motor[whisk] = 10;
if(nMotorEncoder[arm] > 1000){
servo[wrist] += 1;
wait1Msec(5);
}
}
motor[arm] = 0;
servo[wrist] = 177;
motor[whisk] = 0;
}else if(joy2Btn(10)){
servo[wrist] = 0;
}else if(joy2Btn(9)){
servo[wrist] = 193;
}
abortTimeslice();
}
}
task whisker(){
while(true){
if(joy1Btn(7)){
motor[whisk] = 100;
}else if(joy2Btn(7)){
motor[whisk] = 100;
}else{
motor[whisk] = 0;
}
abortTimeslice();
}
}
task main(){
SensorType[RGB] = sensorCOLORFULL;
initializeRobot();
nMotorEncoder[arm] = 0;
servo[wrist] = 0;
// make freaking sure the arm is down
waitForStart();
SensorType[RGB] = sensorCOLORGREEN;
StartTask(directionCont);
StartTask(drive);
StartTask(lifter);
StartTask(armer);
StartTask(flagger);
StartTask(whisker);
StartTask(autoflip);
while(true){
nxtDisplayTextLine(1,"%f",servo[wrist]);
nxtDisplayTextLine(2,"%f",nMotorEncoder[arm]);
}
}
//verticle servo: 177 encoder: 4753
//123 is for scooping [servo] 0 encoder