Dependents:   OBROT_ALL

Revision:
0:4877273ec8cc
Child:
1:a46109178200
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OBROT.cpp	Wed Oct 14 03:55:39 2015 +0000
@@ -0,0 +1,94 @@
+#include "mbed.h"
+#include "OBROT.h"
+#include "I2CMotor.h"
+#include "Steering.h"
+#include "XBee.h"
+#include "I2CServo.h"
+#include "Command.h"
+#include "ShootingSystem.h"
+#include "Shooter.h"
+#include "AmmoPusher.h"
+#include "AmmoSupplier.h"
+#include "Robot.h"
+
+OBROT* OBROT::mInstance = NULL;
+
+const char OBROT::mI2CDeviceAddress[] = {
+    // ステアリング駆動輪
+    0xA0 | ( 0x01 << 1 ),
+    0xA0 | ( 0x02 << 1 ),
+    0xA0 | ( 0x03 << 1 ),
+    // ステアリングサーボ
+    0xA0 | ( 0x04 << 1 ),
+    0xA0 | ( 0x05 << 1 ),
+    0xA0 | ( 0x06 << 1 ),
+    // XBee
+    0xA0 | ( 0x07 << 1 ),
+    // AngleManagerServo
+    0xA0 | ( 0x08 << 1 ),
+    // Shooter
+    0xA0 | ( 0x09 << 1 ),
+    // AmmoPusher
+    0xA0 | ( 0x0A << 1 ),
+    // AmmoSupplier
+    0xA0 | ( 0x0B << 1 ),
+    // PositionManager
+    0xA0 | ( 0x0D << 1 )
+};
+
+OBROT::OBROT(){
+    mI2CDevice = new I2CDevice*[ mNumOfI2CDevice ];
+    
+    I2CDevice::createI2C();
+    
+    I2CMotor** i2cMotor = new I2CMotor*[ Steering::mNumOfTire ];
+    I2CServo** i2cServo = new I2CServo*[ Steering::mNumOfTire ];
+    
+    for ( int i = 0; i < Steering::mNumOfTire; ++i ){
+        mI2CDevice[ i ] = i2cMotor[ i ] = new I2CMotor( mI2CDeviceAddress[ i ] );
+        
+        i2cServo[ i ] = new I2CServo( mI2CDeviceAddress[ i + Steering::mNumOfTire ] );
+        mI2CDevice[ i + Steering::mNumOfTire ] = i2cServo[ i ];
+    }
+    
+    // XBee
+    mI2CDevice[ I2CDeviceID::XBEE ] = mXBee =  new XBee( mI2CDeviceAddress[ I2CDeviceID::XBEE ] );
+    
+    // 砲塔の角度調整用サーボ
+    I2CServo* angleManagerServo = new I2CServo( mI2CDeviceAddress[ I2CDeviceID::ANGLE_MANAGER ] );
+    mI2CDevice[ I2CDeviceID::ANGLE_MANAGER ] = angleManagerServo;
+    
+    // 輪押し出し機構
+    AmmoPusher* ammoPusher = new AmmoPusher( mI2CDeviceAddress[ I2CDeviceID::AMMO_PUSHER ] );
+    mI2CDevice[ I2CDeviceID::AMMO_PUSHER ] = ammoPusher;
+    
+    // 輪補給機構
+    AmmoSupplier* ammoSupplier = new AmmoSupplier( mI2CDeviceAddress[ I2CDeviceID::AMMO_SUPPLIER ] );
+    
+    mI2CDevice[ I2CDeviceID::AMMO_SUPPLIER ] = ammoSupplier;
+    
+    // 発射機構
+    Shooter* shooter = new Shooter( mI2CDeviceAddress[ I2CDeviceID::SHOOTER ] );
+    mI2CDevice[ I2CDeviceID::SHOOTER ] = shooter;
+    
+    // 上下機構
+    I2CServo* positionManager = new I2CServo( mI2CDeviceAddress[ I2CDeviceID::POSITION_MANAGER ] );
+    mI2CDevice[ I2CDeviceID::POSITION_MANAGER ] = positionManager;
+    
+    mSteering       = new Steering( i2cMotor, i2cServo );
+    mShootingSystem = new ShootingSystem( angleManagerServo, ammoPusher,
+                                          ammoSupplier, shooter, positionManager );
+}
+
+OBROT::~OBROT(){
+    delete[] mI2CDevice;
+    delete mSteering;
+    delete mShootingSystem;
+}
+
+void OBROT::updateAction(){
+    Command command = mXBee->createCommand();
+    
+    mShootingSystem->update( command );
+    mSteering->update( command );
+}