そのはずなのですが、現実は厳しく、テーブルの足など細い障害物を検知できずに、衝突したり、引っ掛かったりすることがあります。
また、ものに乗り上げてしまうこともあります。
そんなときは、身動きが取れなくなり、結果、ひっくり返ることもあります。
より実用的な自律走行ロボであるためには、そんな異常にも対応できる、ロバストなシステムにしたいと考えました。
そこで導入を考えたのが、「(床)移動検知センサー」です。
といいつつ、実体は光学マウスです。
光学マウスは、赤外線センサーの働きで、デスク面に対するマウスの移動方向と距離を検知する働きがあります。
これをArduinoで利用しようというのです。
ちょうど、手元に使わなくなった古い光学マウスが余っています。
古い規格のPS2マウスです。
これをばらして、赤外線センサーを再利用しようと考えました。
そこで、ネットを検索してみると、Arduino Playgroundに、サンプルプログラムが存在すると分りました。
便利極まりありません。何の苦労もなく、先人の知恵が利用できる訳です。
サンプルプログラムが公開されています。(ps2_mouse)
#include <ps2.h>
/*
* an arduino sketch to interface with a ps/2 mouse.
* Also uses serial protocol to talk back to the host
* and report what it finds.
*/
/*
* Pin 5 is the mouse data pin, pin 6 is the clock pin
* Feel free to use whatever pins are convenient.
*/
PS2 mouse(6, 5);
/*
* initialize the mouse. Reset it, and place it into remote
* mode, so we can get the encoder data on demand.
*/
void mouse_init()
{
mouse.write(0xff); // reset
mouse.read(); // ack byte
mouse.read(); // blank */
mouse.read(); // blank */
mouse.write(0xf0); // remote mode
mouse.read(); // ack
delayMicroseconds(100);
}
void setup()
{
Serial.begin(9600);
mouse_init();
}
/*
* get a reading from the mouse and report it back to the
* host via the serial line.
*/
void loop()
{
char mstat;
char mx;
char my;
/* get a reading from the mouse */
mouse.write(0xeb); // give me data!
mouse.read(); // ignore ack
mstat = mouse.read();
mx = mouse.read();
my = mouse.read();
/* send the data back up */
Serial.print(mstat, BIN);
Serial.print("\tX=");
Serial.print(mx, DEC);
Serial.print("\tY=");
Serial.print(my, DEC);
Serial.println();
// delay(20); /* twiddle */
}
マウスの移動量信号を、シリアル通信で出力するというデモです。
ほぼそのまま、EZ5の制御プログラムに利用できそうです。
X軸、Y軸の移動量を検知して、移動が(ほとんど)なければ、走行異常と判断するというルーチンに利用しようと、考えます。
ArduinoにPS2マウス(の残骸)をつないでやり、上記のスケッチを走らせてみると、ちゃんとマウスの動きに即した数値を返してきます。いけそうです。
あとは、実機でのテストあるのみですね。
実機に組み込んで、走行テストを重ねてみます。