AmmoSupplier.cpp@0:49a747f09bd2, 2015-08-21 (annotated)
- Committer:
- inst
- Date:
- Fri Aug 21 04:52:23 2015 +0000
- Revision:
- 0:49a747f09bd2
- Child:
- 1:2a43c09cc3be
y evol
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
inst | 0:49a747f09bd2 | 1 | #include "mbed.h" |
inst | 0:49a747f09bd2 | 2 | #include "AmmoSupplier.h" |
inst | 0:49a747f09bd2 | 3 | #include "I2CMotor.h" |
inst | 0:49a747f09bd2 | 4 | |
inst | 0:49a747f09bd2 | 5 | const float AmmoSupplier::mTimeout_sec = 3.0f; |
inst | 0:49a747f09bd2 | 6 | const float AmmoSupplier::mDuty = 0.5f; |
inst | 0:49a747f09bd2 | 7 | const PinName AmmoSupplier::mLazerSensorDinPinName = D5; |
inst | 0:49a747f09bd2 | 8 | |
inst | 0:49a747f09bd2 | 9 | AmmoSupplier::AmmoSupplier( I2CMotor** motor ){ |
inst | 0:49a747f09bd2 | 10 | mSupplier = motor; |
inst | 0:49a747f09bd2 | 11 | mAmmoLazerSensor = new DigitalIn( mLazerSensorDinPinName ); |
inst | 0:49a747f09bd2 | 12 | mTimer = new Timer; |
inst | 0:49a747f09bd2 | 13 | mIsSupplying = false; |
inst | 0:49a747f09bd2 | 14 | } |
inst | 0:49a747f09bd2 | 15 | |
inst | 0:49a747f09bd2 | 16 | void AmmoSupplier::update(){ |
inst | 0:49a747f09bd2 | 17 | I2CMotor::ActionType action = I2CMotor::BRAKE; |
inst | 0:49a747f09bd2 | 18 | |
inst | 0:49a747f09bd2 | 19 | if ( mIsSupplying ){ |
inst | 0:49a747f09bd2 | 20 | if ( mTimer->read() > mTimeout_sec ){ |
inst | 0:49a747f09bd2 | 21 | mIsSupplying = false; |
inst | 0:49a747f09bd2 | 22 | mTimer->stop(); |
inst | 0:49a747f09bd2 | 23 | mTimer->reset(); |
inst | 0:49a747f09bd2 | 24 | } else if ( mAmmoLazerSensor->read() ){ |
inst | 0:49a747f09bd2 | 25 | mIsSupplying = false; |
inst | 0:49a747f09bd2 | 26 | } else { |
inst | 0:49a747f09bd2 | 27 | action = I2CMotor::FORWARD; |
inst | 0:49a747f09bd2 | 28 | } |
inst | 0:49a747f09bd2 | 29 | } |
inst | 0:49a747f09bd2 | 30 | |
inst | 0:49a747f09bd2 | 31 | for ( int i = 0; i < 2; ++i ){ |
inst | 0:49a747f09bd2 | 32 | mSupplier[ i ]->setActionType( action ); |
inst | 0:49a747f09bd2 | 33 | mSupplier[ i ]->setDuty( mDuty ); |
inst | 0:49a747f09bd2 | 34 | } |
inst | 0:49a747f09bd2 | 35 | } |