OBROT.cpp@0:4877273ec8cc, 2015-10-14 (annotated)
- Committer:
- inst
- Date:
- Wed Oct 14 03:55:39 2015 +0000
- Revision:
- 0:4877273ec8cc
- Child:
- 1:a46109178200
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
inst | 0:4877273ec8cc | 1 | #include "mbed.h" |
inst | 0:4877273ec8cc | 2 | #include "OBROT.h" |
inst | 0:4877273ec8cc | 3 | #include "I2CMotor.h" |
inst | 0:4877273ec8cc | 4 | #include "Steering.h" |
inst | 0:4877273ec8cc | 5 | #include "XBee.h" |
inst | 0:4877273ec8cc | 6 | #include "I2CServo.h" |
inst | 0:4877273ec8cc | 7 | #include "Command.h" |
inst | 0:4877273ec8cc | 8 | #include "ShootingSystem.h" |
inst | 0:4877273ec8cc | 9 | #include "Shooter.h" |
inst | 0:4877273ec8cc | 10 | #include "AmmoPusher.h" |
inst | 0:4877273ec8cc | 11 | #include "AmmoSupplier.h" |
inst | 0:4877273ec8cc | 12 | #include "Robot.h" |
inst | 0:4877273ec8cc | 13 | |
inst | 0:4877273ec8cc | 14 | OBROT* OBROT::mInstance = NULL; |
inst | 0:4877273ec8cc | 15 | |
inst | 0:4877273ec8cc | 16 | const char OBROT::mI2CDeviceAddress[] = { |
inst | 0:4877273ec8cc | 17 | // ステアリング駆動輪 |
inst | 0:4877273ec8cc | 18 | 0xA0 | ( 0x01 << 1 ), |
inst | 0:4877273ec8cc | 19 | 0xA0 | ( 0x02 << 1 ), |
inst | 0:4877273ec8cc | 20 | 0xA0 | ( 0x03 << 1 ), |
inst | 0:4877273ec8cc | 21 | // ステアリングサーボ |
inst | 0:4877273ec8cc | 22 | 0xA0 | ( 0x04 << 1 ), |
inst | 0:4877273ec8cc | 23 | 0xA0 | ( 0x05 << 1 ), |
inst | 0:4877273ec8cc | 24 | 0xA0 | ( 0x06 << 1 ), |
inst | 0:4877273ec8cc | 25 | // XBee |
inst | 0:4877273ec8cc | 26 | 0xA0 | ( 0x07 << 1 ), |
inst | 0:4877273ec8cc | 27 | // AngleManagerServo |
inst | 0:4877273ec8cc | 28 | 0xA0 | ( 0x08 << 1 ), |
inst | 0:4877273ec8cc | 29 | // Shooter |
inst | 0:4877273ec8cc | 30 | 0xA0 | ( 0x09 << 1 ), |
inst | 0:4877273ec8cc | 31 | // AmmoPusher |
inst | 0:4877273ec8cc | 32 | 0xA0 | ( 0x0A << 1 ), |
inst | 0:4877273ec8cc | 33 | // AmmoSupplier |
inst | 0:4877273ec8cc | 34 | 0xA0 | ( 0x0B << 1 ), |
inst | 0:4877273ec8cc | 35 | // PositionManager |
inst | 0:4877273ec8cc | 36 | 0xA0 | ( 0x0D << 1 ) |
inst | 0:4877273ec8cc | 37 | }; |
inst | 0:4877273ec8cc | 38 | |
inst | 0:4877273ec8cc | 39 | OBROT::OBROT(){ |
inst | 0:4877273ec8cc | 40 | mI2CDevice = new I2CDevice*[ mNumOfI2CDevice ]; |
inst | 0:4877273ec8cc | 41 | |
inst | 0:4877273ec8cc | 42 | I2CDevice::createI2C(); |
inst | 0:4877273ec8cc | 43 | |
inst | 0:4877273ec8cc | 44 | I2CMotor** i2cMotor = new I2CMotor*[ Steering::mNumOfTire ]; |
inst | 0:4877273ec8cc | 45 | I2CServo** i2cServo = new I2CServo*[ Steering::mNumOfTire ]; |
inst | 0:4877273ec8cc | 46 | |
inst | 0:4877273ec8cc | 47 | for ( int i = 0; i < Steering::mNumOfTire; ++i ){ |
inst | 0:4877273ec8cc | 48 | mI2CDevice[ i ] = i2cMotor[ i ] = new I2CMotor( mI2CDeviceAddress[ i ] ); |
inst | 0:4877273ec8cc | 49 | |
inst | 0:4877273ec8cc | 50 | i2cServo[ i ] = new I2CServo( mI2CDeviceAddress[ i + Steering::mNumOfTire ] ); |
inst | 0:4877273ec8cc | 51 | mI2CDevice[ i + Steering::mNumOfTire ] = i2cServo[ i ]; |
inst | 0:4877273ec8cc | 52 | } |
inst | 0:4877273ec8cc | 53 | |
inst | 0:4877273ec8cc | 54 | // XBee |
inst | 0:4877273ec8cc | 55 | mI2CDevice[ I2CDeviceID::XBEE ] = mXBee = new XBee( mI2CDeviceAddress[ I2CDeviceID::XBEE ] ); |
inst | 0:4877273ec8cc | 56 | |
inst | 0:4877273ec8cc | 57 | // 砲塔の角度調整用サーボ |
inst | 0:4877273ec8cc | 58 | I2CServo* angleManagerServo = new I2CServo( mI2CDeviceAddress[ I2CDeviceID::ANGLE_MANAGER ] ); |
inst | 0:4877273ec8cc | 59 | mI2CDevice[ I2CDeviceID::ANGLE_MANAGER ] = angleManagerServo; |
inst | 0:4877273ec8cc | 60 | |
inst | 0:4877273ec8cc | 61 | // 輪押し出し機構 |
inst | 0:4877273ec8cc | 62 | AmmoPusher* ammoPusher = new AmmoPusher( mI2CDeviceAddress[ I2CDeviceID::AMMO_PUSHER ] ); |
inst | 0:4877273ec8cc | 63 | mI2CDevice[ I2CDeviceID::AMMO_PUSHER ] = ammoPusher; |
inst | 0:4877273ec8cc | 64 | |
inst | 0:4877273ec8cc | 65 | // 輪補給機構 |
inst | 0:4877273ec8cc | 66 | AmmoSupplier* ammoSupplier = new AmmoSupplier( mI2CDeviceAddress[ I2CDeviceID::AMMO_SUPPLIER ] ); |
inst | 0:4877273ec8cc | 67 | |
inst | 0:4877273ec8cc | 68 | mI2CDevice[ I2CDeviceID::AMMO_SUPPLIER ] = ammoSupplier; |
inst | 0:4877273ec8cc | 69 | |
inst | 0:4877273ec8cc | 70 | // 発射機構 |
inst | 0:4877273ec8cc | 71 | Shooter* shooter = new Shooter( mI2CDeviceAddress[ I2CDeviceID::SHOOTER ] ); |
inst | 0:4877273ec8cc | 72 | mI2CDevice[ I2CDeviceID::SHOOTER ] = shooter; |
inst | 0:4877273ec8cc | 73 | |
inst | 0:4877273ec8cc | 74 | // 上下機構 |
inst | 0:4877273ec8cc | 75 | I2CServo* positionManager = new I2CServo( mI2CDeviceAddress[ I2CDeviceID::POSITION_MANAGER ] ); |
inst | 0:4877273ec8cc | 76 | mI2CDevice[ I2CDeviceID::POSITION_MANAGER ] = positionManager; |
inst | 0:4877273ec8cc | 77 | |
inst | 0:4877273ec8cc | 78 | mSteering = new Steering( i2cMotor, i2cServo ); |
inst | 0:4877273ec8cc | 79 | mShootingSystem = new ShootingSystem( angleManagerServo, ammoPusher, |
inst | 0:4877273ec8cc | 80 | ammoSupplier, shooter, positionManager ); |
inst | 0:4877273ec8cc | 81 | } |
inst | 0:4877273ec8cc | 82 | |
inst | 0:4877273ec8cc | 83 | OBROT::~OBROT(){ |
inst | 0:4877273ec8cc | 84 | delete[] mI2CDevice; |
inst | 0:4877273ec8cc | 85 | delete mSteering; |
inst | 0:4877273ec8cc | 86 | delete mShootingSystem; |
inst | 0:4877273ec8cc | 87 | } |
inst | 0:4877273ec8cc | 88 | |
inst | 0:4877273ec8cc | 89 | void OBROT::updateAction(){ |
inst | 0:4877273ec8cc | 90 | Command command = mXBee->createCommand(); |
inst | 0:4877273ec8cc | 91 | |
inst | 0:4877273ec8cc | 92 | mShootingSystem->update( command ); |
inst | 0:4877273ec8cc | 93 | mSteering->update( command ); |
inst | 0:4877273ec8cc | 94 | } |