tarou yamada / ShootingSystem

Dependencies:   AmmoPusher AmmoSupplier Shooter

Dependents:   OBROT_ALL

Files at this revision

API Documentation at this revision

Comitter:
inst
Date:
Fri Aug 21 04:52:50 2015 +0000
Child:
1:3b0b583eba77
Commit message:
y evol

Changed in this revision

AmmoPusher.lib Show annotated file Show diff for this revision Revisions of this file
AmmoSupplier.lib Show annotated file Show diff for this revision Revisions of this file
Shooter.lib Show annotated file Show diff for this revision Revisions of this file
ShootingSystem.cpp Show annotated file Show diff for this revision Revisions of this file
ShootingSystem.h Show annotated file Show diff for this revision Revisions of this file
ShootingSystemDoc.txt Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AmmoPusher.lib	Fri Aug 21 04:52:50 2015 +0000
@@ -0,0 +1,1 @@
+AmmoPusher#42d2772575c5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AmmoSupplier.lib	Fri Aug 21 04:52:50 2015 +0000
@@ -0,0 +1,1 @@
+AmmoSupplier#49a747f09bd2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Shooter.lib	Fri Aug 21 04:52:50 2015 +0000
@@ -0,0 +1,1 @@
+Shooter#d660b49b71e0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ShootingSystem.cpp	Fri Aug 21 04:52:50 2015 +0000
@@ -0,0 +1,62 @@
+#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;
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ShootingSystem.h	Fri Aug 21 04:52:50 2015 +0000
@@ -0,0 +1,30 @@
+#ifndef INCLUDED_SHOOTING_SYSTEM_H
+#define INCLUDED_SHOOTING_SYSTEM_H
+
+class I2CServo;
+class I2CMotor;
+class Command;
+class AmmoPusher;
+class AmmoSupplier;
+class Shooter;
+
+class ShootingSystem{
+public:
+    ShootingSystem( 
+        I2CServo* angleManagerServo, I2CServo* positionManagerServo,
+        I2CMotor* ammoPusherMotor, I2CMotor** ammoSupplier,
+        Shooter* shooter );
+    void update( Command command );
+private:
+    void reset();
+
+    I2CServo* mShooterAngleManager;
+    I2CServo* mShooterPositionManager;
+    AmmoPusher* mAmmoPusher;
+    AmmoSupplier* mAmmoSupplier;
+    Shooter* mShooter;
+    bool mIsShooting;
+    bool mIsResetting;
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ShootingSystemDoc.txt	Fri Aug 21 04:52:50 2015 +0000
@@ -0,0 +1,92 @@
+MD
+(I2CServo)ShooterAngleManager	 	: 発射角度変更機構	: ポテメ 					: I2CServo
+(I2CServo)ShooterPositionManager	: 発射機構上下機構	: ポテメ					: I2CServo
+AmmoPusher			 				: 押出機構			: 2入力スイッチ			: DigitalIn * 2, I2CMotor * 1
+AmmoSupplier	 					: 補給機構			: 2モータ, レーザーON/OFF	: DigitalIn, InterruptIn, I2CMotor * 2
+
+リレーMD
+Shooter 							: 発射機構			: 出力3つ					: *I2C ( LPC1114側のプログラム : RelayYMotorDriver )
+
+About Shooter{
+	LPC1114{
+		DigitalOut( dp11, dp13, dp14 );
+	}
+}
+
+
+全統一制御ShootingSystem
+interface:
+	void update( Command command ){
+		if ( command.getIsShootable() && ( !mIsShooting ) ){
+			mIsShooting = true;
+			mShooterAngleManager->setTargetPosition( command.getAngleOfShooting() );
+			mShooterPositionManager->setTargetPosition( command.getPositionOfShooting() );
+			mAmmoPusher->draw();	// 補給された時に受け取れるように引いておく
+		}
+		
+		// 弾押し出し機構が補給された弾を受け取る位置に来たら補給開始
+		if ( mAmmoPusher->hasPusherFinishedDrawing() ){
+			mAmmoSupplier->supply();
+		}
+		
+		// 射撃作業で
+		//  ・角度調整
+		//  ・位置調整
+		//  ・弾補給
+		//  ・押出機構の準備
+		// が完了したら発射
+		bool canShooterFire = mIsShooting;
+		canShooterFire &= mShooterAngleManager->isStop();
+		canShooterFire &= mShooterPositionManager->isSop();
+		canShooterFire &= mAmmoPusher->hasPusherFinishedDrawing();
+		canShooterFire &= mAmmoSupplier->hasSupplied();
+		if ( canShooterFire ){
+			mShooter->launch();
+			mAmmoPusher->push();
+			
+			if ( mAmmoPresser->hasPresserFinishedPushing() ){
+				mAmmoPresser->draw();
+			}
+		}
+		/*
+			hasWorkFinished系は仕事の受注でフラグリセット、仕事の完了でフラグセット.
+			つまり受注前に使用すると前回の仕事のフラグを返されるため正しく動作しない可能性がある.
+		*/
+	}
+	void update( Command command ){
+		if ( command.getIsShootable() && ( !mIsShooting ) ){
+			mIsShooting 		= true;
+			mShooterAngleManager->setAngle( command.getAngleOfShooting() );
+			mShooterPositionManager->setPosition( command.getPositionOfShooting() );
+			mAmmoPusher->draw();
+		}
+		
+		// 弾押し出し機構が補給された弾を受け取る位置に来たら補給開始
+		if ( mAmmoPusher->hasPusherFinishedDrawing() ){
+			mAmmoSupplier->supply();
+		}
+		
+		// 射撃作業で
+		//  ・角度調整
+		//  ・位置調整
+		//  ・弾補給
+		//  ・押出機構の準備
+		// が完了したら発射
+		bool canShooterFire = mIsShooting;
+		canShooterFire &= mShooterAngleManager->hasWorkFinished();
+		canShooterFire &= mShooterPositionManager->hasWorkFinished();
+		canShooterFire &= mAmmoPusher->hasPusherFinishedDrawing();
+		canShooterFire &= mAmmoSupplier->hasSupplied();
+		if ( canShooterFire ){
+			mShooter->launch();
+			mAmmoPusher->push();
+			
+			if ( mAmmoPresser->hasPresserFinishedPushing() ){
+				mAmmoPresser->draw();
+			}
+		}
+		/*
+			hasWorkFinished系は仕事の受注でフラグリセット、仕事の完了でフラグセット.
+			つまり受注前に使用すると前回の仕事のフラグを返されるため正しく動作しない可能性がある.
+		*/
+	}