車型の文字を書くロボットを製作した。
XY方式での製作も考えたが、無限軌道がなかったため断念した。
下にはロボットの写真を載せる
滑り棒で支えるような形のロボットを作ったが、紙の端に引っかかったり、誤差が大きくなってしまうなど色々な課題が発生した
無限軌道があれば、絶対座標を組んで、「A点からB点までの直線を引く」というプログラムを書きたかった
XY方式では、よりきれいなものが書けたであろうが、この車型のものでも、満足のいく結果が得られた。
// タイヤ 1回転で 17.5cm // タイヤ同士の距離 17cm #define PA 75 // Aの規定の出力 #define PB 75 // Bの規定の出力 #define PC 75 // Cの規定の出力 #define CM (750/35) // 1cm進む時に、タイヤが回る角度 #define WT 100 // 1cm進む時の待機時間
前進関数
引数 x で移動距離をcm単位で指定する。
void FWD(int x) { RotateMotorEx(OUT_AC, 30, -x * CM, 0, true, true); Wait(100); }
後退関数
引数 x で移動距離をcm単位で指定する。
void REV(int x) { RotateMotorEx(OUT_AC, 30, x * CM, 0, true, true); Wait(100); }
左に90°回る
void turnL90() { RotateMotorEx(OUT_AC, 30, 235, 100, true, true); Wait(200); }
右に90°回る
void turnR90() { RotateMotorEx(OUT_AC, 30, -235, -100, true, true); Wait(200); }
信地旋回(右)
引数 x で指定した角度だけ右に回る 単位は 度
void turnR(int x) { RotateMotorEx(OUT_AC, 30, x * 235 / 90, -100, true, true); Wait(200); }
信地旋回(左)
引数 x で指定した角度だけ左に回る 単位は 度
void turnL(int x) { RotateMotorEx(OUT_AC, 30, x * 235 / 90, 100, true, true); Wait(200); }
幅寄せ関数
引数 x cm分だけ、右/左に幅寄せする
精度が悪かったため、一般化することが出来なかった。
よって、予め採取した値を使用している
#define HABA1 70 #define HABA2 100 #define HABA3 130 #define HABA4 161 #define HABA5 178 #define HABA6 195 void habayoseR(int x) { int para; if (x == 1) para = HABA1; else if (x == 2) para = HABA2; else if (x == 3) para = HABA3; else if (x == 4) para = HABA4; else if (x == 5) para = HABA5; else if (x == 6) para = HABA6; else return; RotateMotor(OUT_C, 30, para); RotateMotor(OUT_A, 30, para); RotateMotor(OUT_C, 30, -para); RotateMotor(OUT_A, 30, -(para * 103 / 100)); Wait(200); } void habayoseL(int x) { int para; if (x == 1) para = HABA1; else if (x == 2) para = HABA2; else if (x == 3) para = HABA3; else if (x == 4) para = HABA4; else if (x == 5) para = HABA5; else if (x == 6) para = HABA6; else return; RotateMotor(OUT_A, 30, para); RotateMotor(OUT_C, 30, para); RotateMotor(OUT_A, 30, -para); RotateMotor(OUT_C, 30, -para); Wait(200); }
ペンを下げる
void pen_down() { RotateMotor(OUT_B, 40, -20); Wait(100); }
ペンを上げる
void pen_up() { RotateMotor(OUT_B, 40, 20); Wait(100); }
横棒を書く関数(不使用)
ロボットが横移動できないため、半径の大きな弧で、疑似的に横棒を書いている
void yokobou(int x) { RotateMotor(OUT_A, 25, -x * 10); Wait(100); pen_down(); RotateMotor(OUT_A, 25, x * 10); Wait(100); RotateMotor(OUT_C, 25, -x * 10); Wait(100); pen_up(); RotateMotor(OUT_C, 25, x * 10); Wait(100); }
縦棒を書く関数
引数 x cmで移動距離を指定している。
void tatebou(int x) { pen_down(); RotateMotorEx(OUT_AC, 20, x * CM, 0, true, true); Wait(100); pen_up(); }
「信」を書く関数
さきに横線を5本書いて、次に90°回転し、縦線を4本書く。
1画目の斜め線は、この関数では書いていない。
void draw_shin() { tatebou(6); habayoseR(2); FWD(5); tatebou(4); habayoseR(2); FWD(4); tatebou(4); habayoseR(2); FWD(4); tatebou(4); habayoseR(4); FWD(4); tatebou(4); turnL90(); REV(10); turnR90(); FWD(10); turnL90(); tatebou(8); habayoseR(6); FWD(9); tatebou(1); habayoseL(2); REV(4); tatebou(4); FWD(4); habayoseR(4); tatebou(4); }
「州」を書く関数
書き順通りに書いた
void draw_shu() { REV(3); tatebou(2); habayoseR(2); FWD(5); tatebou(8); habayoseR(2); FWD(5); tatebou(2); habayoseR(2); FWD(5); tatebou(8); habayoseR(2); FWD(5); tatebou(2); habayoseR(2); FWD(5); tatebou(8); }
メイン関数
「信」を書いてから、「州」を書くが、「信」の1画目の斜め線は、「州」を書き終わった後に書いている。
これは、回転関数の精度が悪いため、回転関数の呼び出しを少なくしたかったためである。
task main() { pen_up(); draw_shin(); habayoseL(6); REV(5); draw_shu(); FWD(42); turnR(60); REV(22); tatebou(5); }