Dependencies: AmmoPusher AmmoSupplier Shooter
ShootingSystem.cpp
- Committer:
- inst
- Date:
- 2015-08-21
- Revision:
- 0:987c53b6a212
- Child:
- 1:3b0b583eba77
File content as of revision 0:987c53b6a212:
#include "ShootingSystem.h" #include "mbed.h" #include "AmmoPusher.h" #include "AmmoSupplier.h" #include "Command.h" #include "I2CServo.h" #include "Shooter.h" ShootingSystem::ShootingSystem( I2CServo* angleManagerServo, I2CServo* positionManagerServo, I2CMotor* ammoPusherMotor, I2CMotor** ammoSupplierMotor, Shooter* shooter ){ mShooterAngleManager = angleManagerServo; mShooterPositionManager = positionManagerServo; mShooter = shooter; mAmmoPusher = new AmmoPusher( ammoPusherMotor ); mAmmoSupplier = new AmmoSupplier( ammoSupplierMotor ); mIsShooting = false; mIsResetting = false; } void ShootingSystem::update( Command command ){ if ( mIsResetting ){ reset(); } else { if ( command.isShootable() && ( !mIsShooting ) ){ // 射撃態勢に移行し,発射装置を目指すポールにあった角度・位置にする mIsShooting = true; mShooterAngleManager->setTargetPosition( command.getAngleOfShooting() ); mShooterPositionManager->setTargetPosition( command.getPositionOfShooting() ); mShooter->launch(); } // 発射装置が目標の角度・位置に移動したら発射 bool canShooterFire = mIsShooting; canShooterFire &= mShooterAngleManager->isStop(); canShooterFire &= mShooterPositionManager->isStop(); if ( canShooterFire ){ mAmmoPusher->push(); // 発射が終わったら輪を装填するためにリセット状態に遷移する mIsResetting = mAmmoPusher->hasPusherFinishedPushing(); } } mAmmoSupplier->update(); mAmmoPusher->update(); } void ShootingSystem::reset(){ mShooter->stop(); // 次の弾の装填のため押出機構は引いておく mAmmoPusher->draw(); if ( mAmmoPusher->hasPusherFinishedDrawing() ){ mAmmoSupplier->supply(); if ( mAmmoSupplier->isSupplying() ){ mIsShooting = false; } } }