Files at this revision

API Documentation at this revision

Comitter:
inst
Date:
Wed Oct 14 06:04:26 2015 +0000
Parent:
0:bb84da068c45
Commit message:

Changed in this revision

YMotorDriverSupplier.cpp Show annotated file Show diff for this revision Revisions of this file
YMotorDriverSupplier.h Show annotated file Show diff for this revision Revisions of this file
diff -r bb84da068c45 -r 9d8fe1f0ee36 YMotorDriverSupplier.cpp
--- a/YMotorDriverSupplier.cpp	Sun Aug 23 15:17:57 2015 +0000
+++ b/YMotorDriverSupplier.cpp	Wed Oct 14 06:04:26 2015 +0000
@@ -2,59 +2,28 @@
 #include "YMotorDriverSupplier.h"
 #include "mbed.h"
 
-const float YMotorDriverSupplier::mDuty = 0.30f;
-const PinName YMotorDriverSupplier::mDinPinName[] = {
-    dp2,    // lazer
-    dp4     // photointerrupter
-};
-const float YMotorDriverSupplier::mTimeout_sec = 2.5f;
+const float YMotorDriverSupplier::mDuty = 0.20f;
+const PinName YMotorDriverSupplier::mLazerPinName = dp2;
+//const uint32_t YMotorDriverSupplier::mValidSignalWidth_us = 40 * 1000;
+//const uint32_t YMotorDriverSupplier::mValidSignalWidth_us = 17 * 1000;
+const uint32_t YMotorDriverSupplier::mValidSignalWidth_us = 10;
 
-YMotorDriverSupplier::YMotorDriverSupplier( char address ) : YMotorDriverBase( address ){
-    mLazerDin           = new DigitalIn( mDinPinName[ LAZER ] );
-    mPhotointerrupter   = new InterruptIn( mDinPinName[ PHOTOINTERRUPTER ] );
-    mPhotointerrupter->fall( this, &YMotorDriverSupplier::itr );
-    mPhotointerrupter->rise( this, &YMotorDriverSupplier::itr );
-    mTimer = new Timer;
-    mTimer->stop();
-    mTimer->reset();
-    mLazerTimer = new Timer;
+YMotorDriverSupplier::YMotorDriverSupplier( char address ) : YMotorDriverBase( address, /* id = */ 5 ){
+    mLazer = new InterruptIn( mLazerPinName );
+    mLazer->rise( this, &YMotorDriverSupplier::itr );
+    mTimer      = new Timer;
     mIsWorking  = false;
-    mIsMayStoppable = false;
-    mHasFinished    = false;
-    mPrevInterrupterState = mPhotointerrupter->read();
 }
 
 void YMotorDriverSupplier::itr(){
-    /*
-    bool newState = mPhotointerrupter->read();
-    if ( newState != mPrevInterrupterState ){
+    if ( ( mTimer->read_us() > mValidSignalWidth_us ) && mLazer->read() ){
         mIsWorking = false;
-        mPrevInterrupterState = newState;
-    }
-    */
-    float validSignalWidth_us = 80  * 1000;
-    //
-    if ( mTimer->read_us() > validSignalWidth_us ){
-        //
-        //mIsWorking = false;
-        
-        mHasFinished = true;
         mTimer->reset();
         mTimer->stop();
-        mLazerTimer->reset();
-        mLazerTimer->start();
-        //
     }
-    //
-    
-    /*
-    mIsStoppable = true;
-    mNewInterrupterState = mPhotointerrupter->read();
-    mTimer->start();
-    */
 }
 
-void YMotorDriverSupplier::update(){
+void YMotorDriverSupplier::updateI2CSlave(){
     switch ( mI2C->receive() ){
         case I2CSlave::ReadAddressed:{
             char buf = mIsWorking;
@@ -68,12 +37,10 @@
             char buf;
             mI2C->read( &buf, 1 );
             
-            //
             if ( buf && !mIsWorking ){
                 mTimer->reset();
                 mTimer->start();
             }
-            //
             
             mIsWorking = buf;
             break;
@@ -82,60 +49,15 @@
         case I2CSlave::NoData:
             break;
     }
-    
-    updateSupplier();
-    write();
 }
 
-void YMotorDriverSupplier::updateSupplier(){
-    /*
-    bool hasFinished = mIsWorking;
-    hasFinished &= !mLazerDin->read();
-    hasFinished |= ( mTimer->read() > mTimeout_sec );
-    if ( hasFinished ){
-        mIsWorking = false;
-        mTimer->stop();
-        mTimer->reset();
-    }
-    */
-    /*
-    float validSignalWidth_us = 100;
-    if ( mIsMayStoppable ){
-        if ( mTimer->read_us() > validSignalWidth_us ){
-            mIsMayStoppable = false;
-            mIsWorking = false;
-            mTimer->stop();
-            mTimer->reset();
-        }
-    }
-    */
-    
+void YMotorDriverSupplier::updateSpecial(){
     MotorAction action = BRAKE;
     
-    int fallingAmmoTime_us = 500 * 1000;
-    if ( mHasFinished ){
-        if ( !mLazerDin->read() ){
-            mIsWorking = false;
-            mHasFinished = false;
-            mLazerTimer->stop();
-            mLazerTimer->reset();
-        } else if ( mLazerTimer->read_us() > fallingAmmoTime_us ){
-            mHasFinished = false;
-            mLazerTimer->stop();
-            mLazerTimer->reset();
-            mTimer->reset();
-            mTimer->start();
-        }
-    } else if ( mIsWorking ){
+    if ( mIsWorking ){
         action = FORWARD;
         setDuty( mDuty );
     }
     
-    /*
-    if ( mIsWorking ){
-        action = FORWARD;
-        setDuty( mDuty );
-    }
-    */
     setMotorAction( action );
 }
diff -r bb84da068c45 -r 9d8fe1f0ee36 YMotorDriverSupplier.h
--- a/YMotorDriverSupplier.h	Sun Aug 23 15:17:57 2015 +0000
+++ b/YMotorDriverSupplier.h	Wed Oct 14 06:04:26 2015 +0000
@@ -6,29 +6,20 @@
 
 class YMotorDriverSupplier : public YMotorDriverBase{
 public:
-    enum DinID{
-        LAZER,
-        PHOTOINTERRUPTER
-    };
-
     YMotorDriverSupplier( char address );
-    virtual void update();
+    
 private:
-    void updateSupplier();
+    virtual void updateI2CSlave();
+    virtual void updateSpecial();
     void itr();
 
     static const float mDuty;
-    static const PinName mDinPinName[];
-    static const float mTimeout_sec;
+    static const PinName mLazerPinName;
+    static const uint32_t mValidSignalWidth_us;
     
-    DigitalIn* mLazerDin;
-    InterruptIn* mPhotointerrupter;
+    InterruptIn* mLazer;
     Timer* mTimer;
     bool mIsWorking;
-    bool mIsMayStoppable;
-    bool mPrevInterrupterState;
-    bool mHasFinished;
-    Timer* mLazerTimer;
 };
 
 #endif