ロボカップジュニアサッカー IRM2121を用いた専用パルスボールを検知するためのライブラリ

Dependents:   BallCheck_IRM2121_InterrputInAdd CatPot_SensorRight

Pingのライブラリを参考にしました。 RoboCupJuniorSoccerにおけるボール検知をまとめて行うために作成したライブラリ。

距離に応じて微妙に値が変わるようになりました。 まともに使えます。

なお、このライブラリには、interruptinの機能を拡張するためのライブラリが含まれています。 そのため、必要なときだけピン変化割り込みに入ることが可能となっています。

値に応じて関数ポインタとかすれば距離によって値かわるようにできるかも if文で十分かもしれません

Files at this revision

API Documentation at this revision

Comitter:
ryuna
Date:
Tue Feb 24 05:34:53 2015 +0000
Parent:
2:40101fcb6d44
Commit message:
aaaaaaaaaaa

Changed in this revision

IRM2121.cpp Show annotated file Show diff for this revision Revisions of this file
IRM2121.h Show annotated file Show diff for this revision Revisions of this file
diff -r 40101fcb6d44 -r 711dde7b4c12 IRM2121.cpp
--- a/IRM2121.cpp	Mon Jan 05 05:51:24 2015 +0000
+++ b/IRM2121.cpp	Tue Feb 24 05:34:53 2015 +0000
@@ -10,14 +10,16 @@
 #include "mbed.h"
 
 IRM2121::IRM2121(PinName IRM_PIN)
-        : _event(IRM_PIN)
-        , _timer()
-        {          
-        } 
+        : _event(IRM_PIN), _timer()
+{          
+
+
+} 
         
 void IRM2121::_Start(void)
 {
     if(_Valid && _Busy ){
+        
         _timer.start();
         _Time  = _timer.read_us();
         _Valid = false;  
@@ -39,6 +41,7 @@
 
 void IRM2121::Set(void)
 {
+    _timer.reset();
     _Valid = true;
     _Busy = true;
     _event.fall(this,&IRM2121::_Start );
@@ -47,17 +50,19 @@
      
 }
 
-int IRM2121::Read(void)
+unsigned long IRM2121::Read(void)
 // 0 means not valid.
 {
     if(_Valid && !_Busy){ 
-        return _Time;
-
-    }else { 
         _event.fall_disable(this,&IRM2121::_Start);
         _event.rise_disable(this,&IRM2121::_Stop);
-        return 0;
-    }
+        return _Time;
+    }    
+    
+    _event.fall_disable(this,&IRM2121::_Start);
+    _event.rise_disable(this,&IRM2121::_Stop);
+    
+    return 0;
 }
 
 
diff -r 40101fcb6d44 -r 711dde7b4c12 IRM2121.h
--- a/IRM2121.h	Mon Jan 05 05:51:24 2015 +0000
+++ b/IRM2121.h	Tue Feb 24 05:34:53 2015 +0000
@@ -47,7 +47,7 @@
       *
       * @param none
       */
-    int Read(void);
+    unsigned long Read(void);
     
     /**
       * Check two flags( _Valid, _Busy )
@@ -57,7 +57,7 @@
     void ReturnVB(bool *valid, bool *busy);
     
     
-  protected:
+  private:
     
     interruptin_mod    _event;
     Timer              _timer;
@@ -65,7 +65,7 @@
     bool _Flag;
     bool _Valid;
     bool _Busy;
-    unsigned int _Time;
+    unsigned long _Time;
       
     void _Start(void);
     void _Stop (void);