Diff: YMotorDriverPusher.cpp
- Revision:
- 1:9af02800ffac
- Parent:
- 0:4b3f0e4681c9
diff -r 4b3f0e4681c9 -r 9af02800ffac YMotorDriverPusher.cpp --- a/YMotorDriverPusher.cpp Sun Aug 23 15:18:17 2015 +0000 +++ b/YMotorDriverPusher.cpp Wed Oct 14 06:04:53 2015 +0000 @@ -2,7 +2,8 @@ #include "YMotorDriverPusher.h" #include "mbed.h" -const float YMotorDriverPusher::mDuty = 0.5f; +//const float YMotorDriverPusher::mDuty = 0.75f; +const float YMotorDriverPusher::mDuty = 1.0f; const PinName YMotorDriverPusher::mDinPinName[] = { dp2, dp4 @@ -13,10 +14,11 @@ for ( int i = 0; i < 2; ++i ){ mSwitchDin[ i ] = new DigitalIn( mDinPinName[ i ] ); } - mState = NO_OPERATION; + mActionType = NO_OPERATION; + mState = BETWEEN; } -void YMotorDriverPusher::update(){ +void YMotorDriverPusher::updateI2CSlave(){ switch ( mI2C->receive() ){ case I2CSlave::ReadAddressed:{ char buf = mState; @@ -29,31 +31,36 @@ case I2CSlave::WriteAddressed:{ char buf; mI2C->read( &buf, 1 ); - mState = static_cast< State >( buf ); + mActionType = static_cast< ActionType >( buf ); break; } case I2CSlave::NoData: break; } - - updatePusher(); - write(); } -void YMotorDriverPusher::updatePusher(){ - for ( int i = 0; i < 2; ++i ){ - // もしリミットスイッチに入力があったら止める - if ( mSwitchDin[ i ]->read() ){ - mState = NO_OPERATION; - break; +void YMotorDriverPusher::updateSpecial(){ + if ( mSwitchDin[ DRAW_LIMIT_SWITCH ]->read() ){ + if ( mActionType == DRAWING ){ + // スイッチが押されているのにその方向に動こうとしていたら止める + mActionType = NO_OPERATION; } + mState = HAS_FINISHED_DRAWING; + } else if ( mSwitchDin[ PUSH_LIMIT_SWITCH ]->read() ){ + if ( mActionType == PUSHING ){ + // スイッチが押されているのにその方向に動こうとしていたら止める + mActionType = NO_OPERATION; + } + mState = HAS_FINISHED_PUSHING; + } else { + mState = BETWEEN; } MotorAction action = BRAKE; - if ( mState == DRAWING ){ + if ( mActionType == DRAWING ){ action = REVERSE; - } else if ( mState == PUSHING ){ + } else if ( mActionType == PUSHING ){ action = FORWARD; }