Dependencies:   AmmoPusher AmmoSupplier Shooter

Dependents:   OBROT_ALL

Committer:
inst
Date:
Fri Aug 21 04:52:50 2015 +0000
Revision:
0:987c53b6a212
Child:
1:3b0b583eba77
y evol

Who changed what in which revision?

UserRevisionLine numberNew contents of line
inst 0:987c53b6a212 1 #include "ShootingSystem.h"
inst 0:987c53b6a212 2 #include "mbed.h"
inst 0:987c53b6a212 3 #include "AmmoPusher.h"
inst 0:987c53b6a212 4 #include "AmmoSupplier.h"
inst 0:987c53b6a212 5 #include "Command.h"
inst 0:987c53b6a212 6 #include "I2CServo.h"
inst 0:987c53b6a212 7 #include "Shooter.h"
inst 0:987c53b6a212 8
inst 0:987c53b6a212 9 ShootingSystem::ShootingSystem(
inst 0:987c53b6a212 10 I2CServo* angleManagerServo, I2CServo* positionManagerServo,
inst 0:987c53b6a212 11 I2CMotor* ammoPusherMotor, I2CMotor** ammoSupplierMotor,
inst 0:987c53b6a212 12 Shooter* shooter ){
inst 0:987c53b6a212 13
inst 0:987c53b6a212 14 mShooterAngleManager = angleManagerServo;
inst 0:987c53b6a212 15 mShooterPositionManager = positionManagerServo;
inst 0:987c53b6a212 16 mShooter = shooter;
inst 0:987c53b6a212 17 mAmmoPusher = new AmmoPusher( ammoPusherMotor );
inst 0:987c53b6a212 18 mAmmoSupplier = new AmmoSupplier( ammoSupplierMotor );
inst 0:987c53b6a212 19 mIsShooting = false;
inst 0:987c53b6a212 20 mIsResetting = false;
inst 0:987c53b6a212 21 }
inst 0:987c53b6a212 22
inst 0:987c53b6a212 23 void ShootingSystem::update( Command command ){
inst 0:987c53b6a212 24 if ( mIsResetting ){
inst 0:987c53b6a212 25 reset();
inst 0:987c53b6a212 26 } else {
inst 0:987c53b6a212 27 if ( command.isShootable() && ( !mIsShooting ) ){
inst 0:987c53b6a212 28 // 射撃態勢に移行し,発射装置を目指すポールにあった角度・位置にする
inst 0:987c53b6a212 29 mIsShooting = true;
inst 0:987c53b6a212 30 mShooterAngleManager->setTargetPosition( command.getAngleOfShooting() );
inst 0:987c53b6a212 31 mShooterPositionManager->setTargetPosition( command.getPositionOfShooting() );
inst 0:987c53b6a212 32 mShooter->launch();
inst 0:987c53b6a212 33 }
inst 0:987c53b6a212 34
inst 0:987c53b6a212 35 // 発射装置が目標の角度・位置に移動したら発射
inst 0:987c53b6a212 36 bool canShooterFire = mIsShooting;
inst 0:987c53b6a212 37 canShooterFire &= mShooterAngleManager->isStop();
inst 0:987c53b6a212 38 canShooterFire &= mShooterPositionManager->isStop();
inst 0:987c53b6a212 39 if ( canShooterFire ){
inst 0:987c53b6a212 40 mAmmoPusher->push();
inst 0:987c53b6a212 41 // 発射が終わったら輪を装填するためにリセット状態に遷移する
inst 0:987c53b6a212 42 mIsResetting = mAmmoPusher->hasPusherFinishedPushing();
inst 0:987c53b6a212 43 }
inst 0:987c53b6a212 44 }
inst 0:987c53b6a212 45
inst 0:987c53b6a212 46 mAmmoSupplier->update();
inst 0:987c53b6a212 47 mAmmoPusher->update();
inst 0:987c53b6a212 48 }
inst 0:987c53b6a212 49
inst 0:987c53b6a212 50 void ShootingSystem::reset(){
inst 0:987c53b6a212 51 mShooter->stop();
inst 0:987c53b6a212 52 // 次の弾の装填のため押出機構は引いておく
inst 0:987c53b6a212 53 mAmmoPusher->draw();
inst 0:987c53b6a212 54
inst 0:987c53b6a212 55 if ( mAmmoPusher->hasPusherFinishedDrawing() ){
inst 0:987c53b6a212 56 mAmmoSupplier->supply();
inst 0:987c53b6a212 57
inst 0:987c53b6a212 58 if ( mAmmoSupplier->isSupplying() ){
inst 0:987c53b6a212 59 mIsShooting = false;
inst 0:987c53b6a212 60 }
inst 0:987c53b6a212 61 }
inst 0:987c53b6a212 62 }