-
Notifications
You must be signed in to change notification settings - Fork 0
/
mshuffle.ic
183 lines (162 loc) · 3.21 KB
/
mshuffle.ic
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
/** File: mshuffle.ic
Purpose: Main code. Contains high-evel routines and main().
Parameters: See config.ic
Author: Gabriel Krell
Initial commit date: 9/30
**/
void main() {
int tetris;
if (PLAY_TETRIS) {
tetris = start_process(playTetris(TETRIS_BPM,1));
}
light_on();
shuffleShell();
kill(tetris);
light_off();
}
void mintShuffle() {
int home;
int away;
while (1) {
while (!start_button()) {
if(norm_knob()>50) {
printf("\nhome");
home = 1;
away = 0;
} else {
printf("\naway");
home = 0;
away = 1;
}
sleep(.3);
}
// num1 = (float)knob()/180.;
// // beep();
// // sleep(1.);
// // while (!start_button()) {
// // printf("follow time: %f\n",(float)knob()/40.);
// // sleep(.3);
// // }
// // num2 = (float)knob()/40.;
beep();
sleep(40.);
start_process(playXevious(60,0));
if (away) {
MOTOR_L_SPEED+=5;
}
forwardFor(2.3); // forward to halfway
if (away) {
MOTOR_L_SPEED-=5;
}
// 1st puck in
fastNext();
backwardFor(.75); //leave puck, back up to line
hardRightFor(.7); // turn ~45 degrees
scaleSpeedBy(.5);
followLineForL(2.5); // approach corner
scaleSpeedBy(2.);
leftFor(.05);
fastNextN(2);
scaleSpeedBy(.5);
forwardFor(.5);
rightFor(.25);
forwardFor(2.5);
scaleSpeedBy(2.);
// second puck in
stop();
backwardFor(.5);
// playTetris(TETRIS_BPM,0);
// fastNextN(2);
// if (home) {
// leftFor(.28);
// } else {
// leftFor(.32);
// }
// forwardFor(1.5);
// beep();
// motor(MOTOR_L,MOTOR_L_SPEED/2);
// sleep(.5);
// stop();
// while(!tapeR()) {
// forward();
// }
// stop();
// // should be waiting on the center line here
// backwardFor(.1);
// scaleSpeedBy(.5);
// followLineForL(3.65);
// leftFor(.4);
// forwardFor(1.);
// followLineForL(3.2);
// scaleSpeedBy(2.);
// rightFor(.4);
// forwardFor(.7);
}
}
void shuffleShell() {
int ms = start_process(mintShuffle());
float s = seconds();
while(!stop_button() && s + 85. > seconds()) {
defer();
// wait for early termination
}
kill(ms);
stop();
beep();
printf("\nTimed out: %f", seconds());
}
// follow on a particular side of the line
void followLineForR(float seconds) {
int cached_mode = LINE_FOLLOW_SIDE;
LINE_FOLLOW_SIDE = 1;
followLineFor(seconds);
LINE_FOLLOW_SIDE = cached_mode;
deliberate();
}
void followLineForL(float seconds) {
int cached_mode = LINE_FOLLOW_SIDE;
LINE_FOLLOW_SIDE = 0;
followLineFor(seconds);
LINE_FOLLOW_SIDE = cached_mode;
deliberate();
}
// run followLine for a length of time
void followLineFor(float seconds) {
int pid = start_process(followLine());
sleep(seconds);
kill(pid);
stop();
deliberate();
}
// follow a tape line on the ground
void followLine() {
if (LINE_FOLLOW_SIDE) { // follow on the right side
while(1) {
if (tapeR()) {
hardRight();
} else{
if (tapeL()) {
forward();
} else {
left();
}
}
}
} else { // follow on the left side
while (1) {
if (tapeL()) {
hardLeft();
} else {
if (tapeR()) {
forward();
} else {
right();
}
}
}
}
}
// "stub" utility functions:
int kill(int pid) { // enables laziness
return kill_process(pid);
}