-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTeleOp_TankDrive.c
211 lines (197 loc) · 6.63 KB
/
TeleOp_TankDrive.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
#pragma config(Hubs, S1, HTMotor, HTMotor, HTMotor, HTMotor)
#pragma config(Hubs, S2, HTServo, none, none, none)
#pragma config(Sensor, S1, , sensorI2CMuxController)
#pragma config(Sensor, S2, , sensorI2CMuxController)
#pragma config(Motor, motorA, , tmotorNXT, openLoop, encoder)
#pragma config(Motor, motorB, , tmotorNXT, openLoop)
#pragma config(Motor, motorC, , tmotorNXT, openLoop)
#pragma config(Motor, mtr_S1_C1_1, motorLaunch, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C1_2, motorLaunch2, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C2_1, motorLeft, tmotorTetrix, openLoop, reversed)
#pragma config(Motor, mtr_S1_C2_2, motorRight, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C3_1, motorLeft2, tmotorTetrix, openLoop, reversed)
#pragma config(Motor, mtr_S1_C3_2, motorRight2, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C4_1, motorSweep, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C4_2, motorK, tmotorTetrix, openLoop)
#pragma config(Servo, srvo_S2_C1_1, srvoF1, tServoContinuousRotation)
#pragma config(Servo, srvo_S2_C1_2, srvoF2, tServoStandard)
#pragma config(Servo, srvo_S2_C1_3, servo3, tServoNone)
#pragma config(Servo, srvo_S2_C1_4, servo4, tServoNone)
#pragma config(Servo, srvo_S2_C1_5, servo5, tServoNone)
#pragma config(Servo, srvo_S2_C1_6, servo6, tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
//####################################################################################//
// //
// 2014-2015 3983 TeleOp Code //
// Teams 3983 and 7005 - Highlands Robotics //
// Code by T. Kluge //
// //
//####################################################################################//
// User Config ---------------
bool inDebug = true;
bool needsSpinUp = false;
bool canSpinUp = needsSpinUp;
// End Config ----------------
#include "JoystickDriver.c"
//#include "../GlobalFunctions/debug.h"
bool canSloMo = true, sloMo = false, revDir = false, canRevDir = true;
int srvoVal[] = {103,194};
int ff[] = {490, 613, 640, 750, 640, 750};
task main() {
nVolume = 3;
servo[srvoF2] = srvoVal[0];
PlayImmediateTone(400, 20);
waitForStart();
ClearSounds();
PlayImmediateTone(ff[0], 10);
PlayImmediateTone(ff[1], 10);
PlayImmediateTone(ff[2], 10);
PlayImmediateTone(ff[3], 20);
PlayImmediateTone(ff[4], 10);
PlayImmediateTone(ff[5], 40);
while(true) {
bFloatDuringInactiveMotorPWM = false;
getJoystickSettings(joystick);
if((joystick.joy1_y1 < 10 && joystick.joy1_y1 > -10) && (joystick.joy1_x1 < 10 && joystick.joy1_x1 > -10))
{
joystick.joy1_y1 = 0;
joystick.joy1_x1 = 0;
}
if((joystick.joy1_x2 < 10 && joystick.joy1_x2 > -10) && (joystick.joy1_y2 < 10 && joystick.joy1_y2 > -10))
{
joystick.joy1_x2 = 0;
joystick.joy1_y2 = 0;
}
if (!revDir) {
if (!sloMo) {
motor[motorLeft] = (joystick.joy1_y1 + joystick.joy1_x2);
motor[motorRight] = (joystick.joy1_y1 - joystick.joy1_x2);
motor[motorLeft2] = -(joystick.joy1_y1 - joystick.joy1_x2);
motor[motorRight2] = -(joystick.joy1_y1 + joystick.joy1_x2);
} else {
motor[motorLeft] = 0.16 * (joystick.joy1_y1 + joystick.joy1_x2);
motor[motorRight] = 0.16 * (joystick.joy1_y1 - joystick.joy1_x2);
motor[motorLeft2] = -0.16 * (joystick.joy1_y1 - joystick.joy1_x2);
motor[motorRight2] = -0.16 * (joystick.joy1_y1 + joystick.joy1_x2);
}
} else {
if (!sloMo) {
motor[motorLeft] = -(joystick.joy1_y1 + joystick.joy1_x2);
motor[motorRight] = -(joystick.joy1_y1 - joystick.joy1_x2);
motor[motorLeft2] = (joystick.joy1_y1 - joystick.joy1_x2);
motor[motorRight2] = (joystick.joy1_y1 + joystick.joy1_x2);
} else {
motor[motorLeft] = -0.16 * (joystick.joy1_y1 + joystick.joy1_x2);
motor[motorRight] = -0.16 * (joystick.joy1_y1 - joystick.joy1_x2);
motor[motorLeft2] = 0.16 * (joystick.joy1_y1 - joystick.joy1_x2);
motor[motorRight2] = 0.16 * (joystick.joy1_y1 + joystick.joy1_x2);
}
}
if (canSloMo) {
if (!sloMo) {
if (joy1Btn(12)) {
sloMo = true;
canSloMo = false;
PlayImmediateTone(400, 10);
}
} else {
if (joy1Btn(12)) {
sloMo = false;
canSloMo = false;
PlayImmediateTone(600, 10);
}
}
}
if (!canSloMo) {
if (!joy1Btn(12)) {
canSloMo = true;
}
}
if (canRevDir) {
if (!revDir) {
if (joy1Btn(11)) {
revDir = true;
canRevDir = false;
PlayImmediateTone(300, 10);
}
} else {
if (joy1Btn(11)) {
revDir = false;
canRevDir = false;
PlayImmediateTone(800, 10);
}
}
}
if (!canRevDir) {
if (!joy1Btn(11)) {
canRevDir = true;
}
}
// ------------------------------- End Drive Code -------------------------------
//write spinup code to avoid possible strain on motors
if (joy2Btn(4)) { // Y
if (needsSpinUp) {
for (int i = 0; i < 100; i += 1) {
motor[motorLaunch] = i;
motor[motorLaunch2] = i;
PlayImmediateTone(i + 500, 6);
if (!joy2Btn(4)) break;
wait1Msec(10);
}
needsSpinUp = false;
}
motor[motorLaunch] = 100;
motor[motorLaunch2] = 100;
} else if (joy2Btn(1)) { // X
if (needsSpinUp) {
for (int i = 0; i > -100; i -= 1) {
motor[motorLaunch] = i;
motor[motorLaunch2] = i;
PlayImmediateTone(i + 500, 6);
if (!joy2Btn(1)) break;
wait1Msec(10);
}
needsSpinUp = false;
}
motor[motorLaunch] = -100;
motor[motorLaunch2] = -100;
} else {
//PlayImmediateTone(300, 50);
motor[motorLaunch] = 0;
motor[motorLaunch2] = 0;
if (canSpinUp)
needsSpinUp = true;
}
if (joy2Btn(2))
motor[motorSweep] = -80;
else if (joy2Btn(3))
motor[motorSweep] = 80;
else
motor[motorSweep] = 0;
//control for stand holder
if (joy2Btn(6)) {
servo[srvoF1] = 60;
} else
if (joy2Btn(8)) {
servo[srvoF1] = 187;
} else {
servo[srvoF1] = 127;
}
//precise control for launcher arm thing
if (joy2Btn(5)) {
servo[srvoF2] = ServoValue[srvoF2] + 1;
wait1Msec(10);
}
if (joy2Btn(7)) {
servo[srvoF2] = ServoValue[srvoF2] - 1;
wait1Msec(10);
}
//next to are preset positions for launcher arm thing
if (joy2Btn(9)) {
servo[srvoF2] = srvoVal[0];
}
if (joy2Btn(10)) {
servo[srvoF2] = srvoVal[1];
}
}
}