-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhonban.nxc
More file actions
executable file
·243 lines (202 loc) · 6.01 KB
/
honban.nxc
File metadata and controls
executable file
·243 lines (202 loc) · 6.01 KB
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
231
232
233
234
235
236
237
238
239
240
241
242
243
//本番環境 黒:30 白:70 P:4.6 -> 1.84
//部室環境 43 73
#define BLACK 45 //ラインの色の値
#define WHITE 75 //コースの色の値
#define P_GAIN 2.34 //比例制御のパラメーター
#define D_GAIN 0.11 //微分制御のパラメーター
#define B_MIN 2 //黒判定 最大旋回
#define W_MIN 7 //白判定 最大旋回
#define CSET 450 //脱線検知 探索モード しきい値
#define turn_left OnRev(OUT_A,100);OnRev(OUT_C,slow); //左回転
#define turn_right OnRev(OUT_C,100);OnRev(OUT_A,slow); //右回転
#define LIGHT Sensor(IN_1)
int music = 0; //音楽を流すかの変数
#define DO 262
#define RE 294
#define MI 330
#define FA 349
#define SO 359
#define RA 440
#define SI 494
#define HDO 523
#define HRE 587
#define SDO 277
#define SRE 311
#define SFA 370
#define SSO 415
#define SRA 466
task play_music() //ゴジラの音楽を流す
{
while(true){
if(music==0)
PlayTone(HDO,200);Wait(250);if(music==0)
PlayTone(SI,200);Wait(250);if(music==0)
PlayTone(RA,200);Wait(500);if(music==0)
PlayTone(HDO,200);Wait(250);if(music==0)
PlayTone(SI,200);Wait(250);if(music==0)
PlayTone(RA,200);Wait(500);if(music==0)
PlayTone(HDO,200);Wait(250);if(music==0)
PlayTone(SI,200);Wait(250);if(music==0)
PlayTone(RA,200);Wait(250);if(music==0)
PlayTone(SO,200);Wait(250);if(music==0)
PlayTone(RA,200);Wait(250);if(music==0)
PlayTone(SI,200);Wait(250);if(music==0)
PlayTone(HDO,200);Wait(250);if(music==0)
PlayTone(SI,200);Wait(250);if(music==0)
PlayTone(RA,200);Wait(500);if(music==0)
PlayTone(HDO,200);Wait(250);if(music==0)
PlayTone(SI,200);Wait(250);if(music==0)
PlayTone(RA,200);Wait(500);if(music==0)
PlayTone(HDO,200);Wait(250);if(music==0)
PlayTone(SI,200);Wait(250);if(music==0)
PlayTone(RA,200);Wait(500);if(music==0)
PlayTone(HDO,200);Wait(250);if(music==0)
PlayTone(SI,200);Wait(250);if(music==0)
PlayTone(RA,200);Wait(250);if(music==0)
PlayTone(SO,200);Wait(250);if(music==0)
PlayTone(RA,200);Wait(250);if(music==0)
PlayTone(SI,200);Wait(250);if(music==0)
PlayTone(HDO,200);Wait(250);if(music==0)
PlayTone(SI,200);Wait(250);if(music==0)
PlayTone(RA,200);Wait(500);if(music==0)
PlayTone(HRE,200);Wait(250);if(music==0)
PlayTone(HDO,200);Wait(250);if(music==0)
PlayTone(SI,200);Wait(500);if(music==0)
PlayTone(HRE,200);Wait(250);if(music==0)
PlayTone(HDO,200);Wait(250);if(music==0)
PlayTone(SI,200);Wait(500);if(music==0)
PlayTone(HRE,200);Wait(250);if(music==0)
PlayTone(HDO,200);Wait(250);if(music==0)
PlayTone(SI,200);Wait(250);if(music==0)
PlayTone(RA,200);Wait(250);if(music==0)
PlayTone(SI,200);Wait(250);if(music==0)
PlayTone(HDO,200);Wait(250);if(music==0)
PlayTone(HRE,200);Wait(250);if(music==0)
PlayTone(HDO,200);Wait(250);if(music==0)
PlayTone(SI,200);Wait(500);if(music==0)
PlayTone(HRE,200);Wait(250);if(music==0)
PlayTone(HDO,200);Wait(250);if(music==0)
PlayTone(SI,200);Wait(500);if(music==0)
PlayTone(HRE,200);Wait(250);if(music==0)
PlayTone(HDO,200);Wait(250);if(music==0)
PlayTone(SI,200);Wait(500);if(music==0)
PlayTone(HRE,200);Wait(250);if(music==0)
PlayTone(HDO,200);Wait(250);if(music==0)
PlayTone(SI,200);Wait(250);if(music==0)
PlayTone(RA,200);Wait(250);if(music==0)
PlayTone(SI,200);Wait(250);if(music==0)
PlayTone(HDO,200);Wait(250);if(music==0)
PlayTone(HRE,200);Wait(250);if(music==0)
PlayTone(HDO,200);Wait(250);if(music==0)
PlayTone(SI,200);Wait(500);if(music==0)
}
}
task main(){
start play_music; //音楽開始
int black = BLACK;
int white = WHITE;
int w_min = W_MIN;
int b_min = B_MIN;
int wset = 100 - w_min;
int bset = b_min - 100;
int cset = CSET;
float p_gain = P_GAIN;
float d_gain = D_GAIN;
int gray = (black + white) / 2;
float turn; //回転値
float slow; //回転方向の制御値
int L_forward; //過去のセンサーの値
int L_present; //現在センサーの値
int counter = 0; //white制御の連続回数 -> 探索モードへ移行
SetSensorLight(IN_1);
while(true){
L_present = LIGHT;
//反時計回りライントレース
music = 0;
while(counter < cset){
L_forward = L_present;
L_present = LIGHT;
if(L_present - L_forward < -2){ //黒の急な回転に対応
OnRev(OUT_C,100); OnFwd(OUT_A,100);Wait(10);
L_forward = L_present;
L_present = LIGHT;
}
turn = (p_gain * (L_present - gray) + d_gain * (L_present - L_forward))*100.0/(white - black); //旋回値計算
//black -> turn right
if(turn < 0.0){
if(turn < bset){
slow = b_min;
}
else{
slow = 100.0 + turn;
}
turn_right;
counter = 0;
}
//white -> turn left
else{
if(turn > wset){
slow = w_min;
}
else{
slow = 100 - turn;
}
turn_left;
counter = counter + 1; //右回転判断を数え上げる
}
Wait(3);
}
counter = 0;
//脱線検知 & 探索モード
music = 1; //音楽停止
OnRev(OUT_C,100); OnFwd(OUT_A,100);Wait(20); //車体向き調整
while(LIGHT > gray){
OnRev(OUT_C,50); OnRev(OUT_A,17); //時計回りに探索
}
OnRev(OUT_A,100); OnFwd(OUT_C,100);Wait(50); //車体向き調整
L_present = LIGHT;
//時計回りライントレース
music = 0;
while(counter < cset){
L_forward = L_present;
L_present = LIGHT;
if(L_present - L_forward < -2){
OnRev(OUT_A,100); OnFwd(OUT_C,100);Wait(10);
L_forward = L_present;
L_present = LIGHT;
}
turn = (p_gain * (L_present - gray) + d_gain * (L_present - L_forward))*100.0/(white - black);
//black -> turn left
if(turn < 0.0){
if(turn < bset){
slow = b_min;
}
else{
slow = 100.0 + turn;
}
turn_left;
counter = 0;
}
//white -> turn right
else{
if(turn > wset){
slow = w_min;
}
else{
slow = 100.0 - turn;
}
turn_right;
counter = counter + 1;
}
Wait(3);
}
counter = 0;
//脱線検知 & 探索モード
music = 1;
OnRev(OUT_A,100); OnFwd(OUT_C,100);Wait(20); //車体向き調整
while(LIGHT > gray){
OnRev(OUT_A,50); OnRev(OUT_C,17);
}
OnRev(OUT_C,100); OnFwd(OUT_A,100);Wait(50);
}
}