-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2013 Spring Proto
185 lines (164 loc) · 6.48 KB
/
2013 Spring Proto
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
#pragma config(Hubs, S3, HTMotor, HTServo, none, none)
#pragma config(Hubs, S4, HTMotor, HTMotor, none, none)
#pragma config(Sensor, S2, touch, sensorTouch)
#pragma config(Motor, mtr_S3_C1_1, LoknLod, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S3_C1_2, height, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S4_C1_1, yellowRed, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S4_C1_2, redGreen, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S4_C2_1, greenBlue, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S4_C2_2, blueYellow, tmotorTetrix, openLoop)
#pragma config(Servo, srvo_S3_C2_1, trigger, tServoStandard)
#pragma config(Servo, srvo_S3_C2_2, RG, tServoStandard)
#pragma config(Servo, srvo_S3_C2_3, YR, tServoNone)
#pragma config(Servo, srvo_S3_C2_4, BY, tServoNone)
#pragma config(Servo, srvo_S3_C2_5, GB, tServoNone)
#pragma config(Servo, srvo_S3_C2_6, servo6, tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
#include "JoystickDriver.c"
#define greenRed redGreen
#define redYellow yellowRed
#define blueGreen greenBlue
#define yellowBlue blueYellow
#define blueBtn joy1Btn(1)
#define greenBtn joy1Btn(2)
#define redBtn joy1Btn(3)
#define yellowBtn joy1Btn(4)
string swerveDirection = "blue";
void initializeRobot(){
servo[trigger] = 256;
return;
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------*/
task control(){
while(true){
getJoystickSettings(joystick);
if(joy1Btn(1)){
swerveDirection = "blue";
}else if(joy1Btn(2)){
swerveDirection = "green";
}else if(joy1Btn(3)){
swerveDirection = "red";
}else if(joy1Btn(4)){
swerveDirection = "yellow";
}else{
}
abortTimeslice();
}
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------*/
task drive(){
while(true){
if(joy1Btn(6)){
swerveDirection = "turn";
motor[yellowRed] = -100;
motor[yellowBlue] = -100;
motor[redGreen] = -100;
motor[greenBlue] = -100;
}else if(joy1Btn(5)){
swerveDirection = "turn";
motor[yellowRed] = 100;
motor[yellowBlue] = 100;
motor[redGreen] = 100;
motor[greenBlue] = 100;
}else if(swerveDirection == "blue"){
motor[redGreen] = -joystick.joy1_y1;
motor[blueGreen] = -joystick.joy1_y1;
motor[yellowRed] = joystick.joy1_y2;
motor[yellowBlue] = joystick.joy1_y2;
}else if(swerveDirection == "green"){
motor[yellowRed] = -joystick.joy1_y1;
motor[blueGreen] = joystick.joy1_y2;
motor[redGreen] = -joystick.joy1_y1;
motor[yellowBlue] = joystick.joy1_y2;
}else if(swerveDirection == "red"){
motor[redGreen] = joystick.joy1_y1;
motor[yellowBlue] = -joystick.joy1_y2;
motor[yellowRed] = -joystick.joy1_y1;
motor[blueGreen] = joystick.joy1_y2;
}else if(swerveDirection == "yellow"){
motor[yellowBlue] = -joystick.joy1_y1;
motor[blueGreen] = -joystick.joy1_y1;
motor[yellowRed] = joystick.joy1_y2;
motor[redGreen] = joystick.joy1_y2;
}else if(swerveDirection == "turn"){
motor[blueGreen] = (((joystick.joy1_y1)-(joystick.joy1_x1))/256.0)*100;
motor[yellowBlue] = (((joystick.joy1_y1)+(joystick.joy1_x1))/256.0)*100;
motor[redGreen] = -(((joystick.joy1_y1)+(joystick.joy1_x1))/256.0)*100;
motor[yellowRed] = (((joystick.joy1_x1)-(joystick.joy1_y1))/256.0)*100;
}
abortTimeslice();
}
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------*/
task launcher(){
int reloadCounter = 0;
while(true){
if(joy1Btn(8)){
servo[trigger] = 240;
wait1Msec(900);
servo[trigger] = 256;
wait10Msec(10);
reloadCounter = 0;
}
if(joy1Btn(7) && reloadCounter != 1){
motor[LoknLod] = -75;
while(SensorValue[touch] != 1){
}
motor[LoknLod] = 100;
wait10Msec(100);
motor[LoknLod] = 0;
reloadCounter = 1;
}
abortTimeslice();
}
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------*/
task servos(){
while(true){
if(swerveDirection == "turn" || swerveDirection == "holo"){
servo[GB] = 160;//Replace with turn angle
servo[YR] = 66;//Replace with turn angle
servo[RG] = 131;//Replace with turn angle
servo[BY] = 191;//Replace with red angle
}else if(swerveDirection == "red" || swerveDirection == "blue"){
servo[GB] = 211;//Replace with red angle
servo[YR] = 118;//Replace with red angle
servo[RG] = 72;//Replace with red angle
servo[BY] = 130;//Replace with red angle
}else{
servo[GB] = 86;//Replace with yellow angle
servo[YR] = 10;//Replace with yellow angle
servo[RG] = 193;//Replace with yellow angle
servo[BY] = 247;//Replace with yellow angle
}
abortTimeslice();
}
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------*/
task heightControl (){
while(true){
if(joystick.joy1_TopHat == 0){
motor[height] = 50;
}else if(joystick.joy1_TopHat == 4){
motor[height] = -50;
}else{
motor[height] = 0;
}
}
}
task main()
{
initializeRobot();
StartTask(launcher);
StartTask(control);
StartTask(drive);
StartTask(servos);
StartTask(heightControl);
while (true){
}
}