2002-10-04 [金]
_ 卒研
光センサー使って黒いラインを追尾するプログラムをさくっと組んでみる。
#define LEFT 0
#define RIGHT 1
#define LightSensor SENSOR_2
#define THRESHOLD 32
#define TURN_QUARTER_TIME 10
#define LINE_WIDTH 4
int last_turn,now_turn;
task main(){
SetSensor(LightSensor,SENSOR_LIGHT);
last_turn = RIGHT;
start run;
}
task run(){
stop turn;
OnFwd(OUT_A+OUT_C);
while(true){
if (LightSensor > THRESHOLD){
start turn;
}
}
}
task turn(){
stop run;
now_turn = last_turn;
if (now_turn == LEFT){
Rev(OUT_A);
Fwd(OUT_C);
}
else{
Fwd(OUT_A);
Rev(OUT_C);
}
On(OUT_A+OUT_C);
repeat(2){
ClearTimer(0);
while (Timer(0) < TURN_QUARTER_TIME){
if (LightSensor <= THRESHOLD){
last_turn = now_turn;
Wait(LINE_WIDTH);
start run;
}
}
Toggle(OUT_A+OUT_C);
ClearTimer(0);
while(Timer(0) < TURN_QUARTER_TIME);
now_turn = 1 - now_turn;
}
OnRev(OUT_A+OUT_C);
Wait(50);
start run;
}
_ きょうのうりあげ
- タラフロッグc(朝奈) 70k
- 鋼鉄 23k×8
- s3クロスボウ 20k
hermes evelyne bag red たわごと(2002-10-04)