-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01-First tournament teleop
187 lines (173 loc) · 5.68 KB
/
01-First tournament teleop
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
#pragma config(Hubs, S1, HTMotor, HTMotor, none, none)
#pragma config(Hubs, S3, HTServo, none, none, none)
#pragma config(Hubs, S4, HTMotor, HTMotor, none, none)
#pragma config(Sensor, S1, , sensorI2CMuxController)
#pragma config(Sensor, S2, INF, sensorHiTechnicIRSeeker1200)
#pragma config(Sensor, S3, , sensorI2CMuxController)
#pragma config(Sensor, S4, , sensorI2CMuxController)
#pragma config(Motor, mtr_S1_C1_1, red, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C1_2, yellow, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C2_1, green, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C2_2, blue, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S4_C1_1, arm, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S4_C1_2, whisk, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S4_C2_1, lift, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S4_C2_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(){
servo[autoflipper] = 256;
motor[arm] = 0;
return;
}
float DZ(float input){
if(input > -10 && input < 10){
return 0;
}else{
return input;
}
}
task directionCont(){
while(true){
getJoystickSettings(joystick);
if(joy1Btn(1)){
direction = "blue";
}else if(joy1Btn(2)){
direction = "green";
}else if(joy1Btn(3)){
direction = "red";
}else if(joy1Btn(4)){
direction = "yellow";
}else if(joy2Btn(1)){
direction = "blue";
}else if(joy2Btn(2)){
direction = "green";
}else if(joy2Btn(3)){
direction = "red";
}else if(joy2Btn(4)){
direction = "yellow";
}
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] = -100;
}else if(joystick.joy1_TopHat == 0){
motor[arm] = 100;
}else if(joystick.joy2_TopHat == 0){
motor[arm] = 100;
}else if(joystick.joy2_TopHat == 4){
motor[arm] = -100;
}else{
motor[arm] = 0;
}
if(DZ(joystick.joy1_y2) > 11){
servo[wrist] += ((DZ(joystick.joy1_y2))/50);
}else if(DZ(joystick.joy1_y2) < -11){
servo[wrist] += ((DZ(joystick.joy1_y2))/50);
}else if(DZ(joystick.joy2_y2) > 11){
servo[wrist] += ((DZ(joystick.joy2_y2))/50);
}else if(DZ(joystick.joy2_y2) < -11){
servo[wrist] += ((DZ(joystick.joy2_y2))/50);
}
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(){
initializeRobot();
waitForStart();
StartTask(directionCont);
StartTask(drive);
StartTask(lifter);
StartTask(armer);
StartTask(flagger);
StartTask(whisker);
while(true){
nxtDisplayCenteredTextLine(3,"&f",servo[wrist]);
}
}