Diff: OBROT.cpp
- Revision:
- 1:a46109178200
- Parent:
- 0:4877273ec8cc
- Child:
- 2:cefcd4cb1777
diff -r 4877273ec8cc -r a46109178200 OBROT.cpp --- a/OBROT.cpp Wed Oct 14 03:55:39 2015 +0000 +++ b/OBROT.cpp Thu Oct 15 03:56:01 2015 +0000 @@ -41,39 +41,16 @@ I2CDevice::createI2C(); - I2CMotor** i2cMotor = new I2CMotor*[ Steering::mNumOfTire ]; - I2CServo** i2cServo = new I2CServo*[ Steering::mNumOfTire ]; + initXBee(); - 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; + I2CMotor** i2cMotor = initSteeringTire(); + I2CServo** i2cServo = initSteeringServo(); - // 輪押し出し機構 - 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; + I2CServo* angleManagerServo = initAngleManagerServo(); + AmmoPusher* ammoPusher = initAmmoPusher();; + AmmoSupplier* ammoSupplier = initAmmoSupplier(); + Shooter* shooter = initShooter(); + I2CServo* positionManager = initPositionManager(); mSteering = new Steering( i2cMotor, i2cServo ); mShootingSystem = new ShootingSystem( angleManagerServo, ammoPusher, @@ -92,3 +69,59 @@ mShootingSystem->update( command ); mSteering->update( command ); } + +I2CServo** OBROT::initSteeringServo(){ + I2CServo** i2cServo = new I2CServo*[ Steering::mNumOfTire ]; + + for ( int i = 0; i < Steering::mNumOfTire; ++i ){ + i2cServo[ i ] = new I2CServo( mI2CDeviceAddress[ i + Steering::mNumOfTire ] ); + mI2CDevice[ i + Steering::mNumOfTire ] = i2cServo[ i ]; + } + + return i2cServo; +} + +I2CMotor** OBROT::initSteeringTire(){ + I2CMotor** i2cMotor = new I2CMotor*[ Steering::mNumOfTire ]; + + for ( int i = 0; i < Steering::mNumOfTire; ++i ){ + mI2CDevice[ i ] = i2cMotor[ i ] = new I2CMotor( mI2CDeviceAddress[ i ] ); + } + + return i2cMotor; +} + +XBee* OBROT::initXBee(){ + mI2CDevice[ I2CDeviceID::XBEE ] = mXBee = new XBee( mI2CDeviceAddress[ I2CDeviceID::XBEE ] ); + return mXBee; +} + +I2CServo* OBROT::initAngleManager(){ + I2CServo* angleManagerServo = new I2CServo( mI2CDeviceAddress[ I2CDeviceID::ANGLE_MANAGER ] ); + mI2CDevice[ I2CDeviceID::ANGLE_MANAGER ] = angleManagerServo; + return angleManagerServo; +} + +AmmoPusher* OBROT::initAmmoPusher(){ + AmmoPusher* ammoPusher = new AmmoPusher( mI2CDeviceAddress[ I2CDeviceID::AMMO_PUSHER ] ); + mI2CDevice[ I2CDeviceID::AMMO_PUSHER ] = ammoPusher; + return ammoPusher; +} + +AmmoSupplier* OBROT::initAmmoSupplier(){ + AmmoSupplier* ammoSupplier = new AmmoSupplier( mI2CDeviceAddress[ I2CDeviceID::AMMO_SUPPLIER ] ); + mI2CDevice[ I2CDeviceID::AMMO_SUPPLIER ] = ammoSupplier; + return ammoSupplier; +} + +Shooter* OBROT::initShooter(){ + Shooter* shooter = new Shooter( mI2CDeviceAddress[ I2CDeviceID::SHOOTER ] ); + mI2CDevice[ I2CDeviceID::SHOOTER ] = shooter; + return shooter; +} + +I2CServo* OBROT::initPositionManager(){ + I2CServo* positionManager = new I2CServo( mI2CDeviceAddress[ I2CDeviceID::POSITION_MANAGER ] ); + mI2CDevice[ I2CDeviceID::POSITION_MANAGER ] = positionManager; + return positionManager; +}