ロボカップジュニアサッカー IRM2121を用いた専用パルスボールを検知するためのライブラリ
Dependents: BallCheck_IRM2121_InterrputInAdd CatPot_SensorRight
Pingのライブラリを参考にしました。 RoboCupJuniorSoccerにおけるボール検知をまとめて行うために作成したライブラリ。
距離に応じて微妙に値が変わるようになりました。 まともに使えます。
なお、このライブラリには、interruptinの機能を拡張するためのライブラリが含まれています。 そのため、必要なときだけピン変化割り込みに入ることが可能となっています。
値に応じて関数ポインタとかすれば距離によって値かわるようにできるかも if文で十分かもしれません
Diff: IRM2121.cpp
- Revision:
- 1:b25c8ac20d5b
- Parent:
- 0:fd5c1ea78a7c
- Child:
- 2:40101fcb6d44
--- a/IRM2121.cpp Sun Nov 09 11:11:37 2014 +0000 +++ b/IRM2121.cpp Fri Dec 05 14:51:05 2014 +0000 @@ -1,53 +1,53 @@ -/* mbed Ping Library +/* mbed Ping Library respected Library !! * - * + * make interruptin_mod by bousiya03 + * */ #include "IRM2121.h" +#include "interruptin_mod.h" #include "mbed.h" IRM2121::IRM2121(PinName IRM_PIN) : _event(IRM_PIN) , _timer() - { - _event.rise(this,&IRM2121::_Stop ); - _event.fall(this,&IRM2121::_Start ); - _event.disable_irq(); - _Flag = false; + { } void IRM2121::_Start(void) { - _Flag = true; - _Valid = false; // start the timere, and invalidate the current time. - _Busy = true; - _timer.start(); - _Time = _timer.read_us(); + _timer.start(); + _Time = _timer.read_us(); + _Valid = false; + _Busy = true; + _event.fall_disable(this,&IRM2121::_Start); + _event.rise(this,&IRM2121::_Stop); } void IRM2121::_Stop(void) { - if(_Flag == true){ - _Flag = false; + if(~_Valid && _Busy){ _Valid = true; // When it stops, update the time _Busy = false; _Time = _timer.read_us()-_Time; - _event.disable_irq(); - } + _event.rise_disable(this,&IRM2121::_Stop); + } } void IRM2121::Set() { - _event.enable_irq(); - + _event.fall(this,&IRM2121::_Start ); } int IRM2121::Read() -// -1 means not valid. +// 1 means not valid. { - if(_Valid && ~_Busy) + if(_Valid && ~_Busy){ return (_Time); - else - return -1; -} \ No newline at end of file + }else{ + _event.fall_disable(this,&IRM2121::_Start); + _event.rise_disable(this,&IRM2121::_Stop); + return 1; + } +}