Dependents:   ShootingSystem

Committer:
inst
Date:
Fri Aug 21 04:52:43 2015 +0000
Revision:
1:42d2772575c5
Parent:
0:fac139a6b77c
Child:
2:5ec2a3097d4c
y evol

Who changed what in which revision?

UserRevisionLine numberNew contents of line
inst 0:fac139a6b77c 1 #include "AmmoPusher.h"
inst 1:42d2772575c5 2 #include "mbed.h"
inst 1:42d2772575c5 3 #include "I2CMotor.h"
inst 1:42d2772575c5 4
inst 1:42d2772575c5 5 const float AmmoPusher::mDuty = 0.8f;
inst 1:42d2772575c5 6 const PinName AmmoPusher::mDrawingLimitSwitchPinName = D7;
inst 1:42d2772575c5 7 const PinName AmmoPusher::mPushingLimitSwitchPinName = D6;
inst 1:42d2772575c5 8
inst 1:42d2772575c5 9 AmmoPusher::AmmoPusher( I2CMotor* drawerMotor ){
inst 1:42d2772575c5 10 mDrawerMotor = drawerMotor;
inst 1:42d2772575c5 11 mDrawerMotor->setDuty( mDuty );
inst 1:42d2772575c5 12 mDrawingLimitSwitch = new DigitalIn( mDrawingLimitSwitchPinName );
inst 1:42d2772575c5 13 mPushingLimitSwitch = new DigitalIn( mPushingLimitSwitchPinName );
inst 1:42d2772575c5 14 }
inst 1:42d2772575c5 15
inst 1:42d2772575c5 16 void AmmoPusher::update(){
inst 1:42d2772575c5 17 // スイッチが押されたらブレーキ
inst 1:42d2772575c5 18 if ( mDrawingLimitSwitch->read() || mPushingLimitSwitch->read() ){
inst 1:42d2772575c5 19 mDrawerMotor->setActionType( I2CMotor::BRAKE );
inst 1:42d2772575c5 20 }
inst 1:42d2772575c5 21 }
inst 1:42d2772575c5 22
inst 1:42d2772575c5 23 void AmmoPusher::draw(){
inst 1:42d2772575c5 24 // スイッチが押されたらブレーキ
inst 1:42d2772575c5 25 if ( mDrawingLimitSwitch->read() || mPushingLimitSwitch->read() ){
inst 1:42d2772575c5 26 mDrawerMotor->setActionType( I2CMotor::BRAKE );
inst 1:42d2772575c5 27 } else {
inst 1:42d2772575c5 28 mDrawerMotor->setActionType( I2CMotor::REVERSE );
inst 1:42d2772575c5 29 }
inst 1:42d2772575c5 30 }
inst 1:42d2772575c5 31
inst 1:42d2772575c5 32 void AmmoPusher::push(){
inst 1:42d2772575c5 33 // スイッチが押されたらブレーキ
inst 1:42d2772575c5 34 if ( mDrawingLimitSwitch->read() || mPushingLimitSwitch->read() ){
inst 1:42d2772575c5 35 mDrawerMotor->setActionType( I2CMotor::BRAKE );
inst 1:42d2772575c5 36 } else {
inst 1:42d2772575c5 37 mDrawerMotor->setActionType( I2CMotor::FORWARD );
inst 1:42d2772575c5 38 }
inst 1:42d2772575c5 39 }
inst 1:42d2772575c5 40
inst 1:42d2772575c5 41 bool AmmoPusher::hasPusherFinishedPushing(){
inst 1:42d2772575c5 42 if ( mPushingLimitSwitch->read() ){
inst 1:42d2772575c5 43 mDrawerMotor->setActionType( I2CMotor::BRAKE );
inst 1:42d2772575c5 44 return true;
inst 1:42d2772575c5 45 }
inst 1:42d2772575c5 46 return false;
inst 1:42d2772575c5 47 }
inst 1:42d2772575c5 48
inst 1:42d2772575c5 49 bool AmmoPusher::hasPusherFinishedDrawing(){
inst 1:42d2772575c5 50 if ( mDrawingLimitSwitch->read() ){
inst 1:42d2772575c5 51 mDrawerMotor->setActionType( I2CMotor::BRAKE );
inst 1:42d2772575c5 52 return true;
inst 1:42d2772575c5 53 }
inst 1:42d2772575c5 54 return false;
inst 1:42d2772575c5 55 }