Dependents:   OBROT_ALL

Committer:
inst
Date:
Thu Oct 15 08:22:20 2015 +0000
Revision:
2:cefcd4cb1777
Parent:
1:a46109178200
Child:
3:dd113546dfd1
last update

Who changed what in which revision?

UserRevisionLine numberNew 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 1:a46109178200 44 initXBee();
inst 0:4877273ec8cc 45
inst 1:a46109178200 46 I2CMotor** i2cMotor = initSteeringTire();
inst 1:a46109178200 47 I2CServo** i2cServo = initSteeringServo();
inst 0:4877273ec8cc 48
inst 2:cefcd4cb1777 49 I2CServo* angleManagerServo = initAngleManager();
inst 1:a46109178200 50 AmmoPusher* ammoPusher = initAmmoPusher();;
inst 1:a46109178200 51 AmmoSupplier* ammoSupplier = initAmmoSupplier();
inst 1:a46109178200 52 Shooter* shooter = initShooter();
inst 1:a46109178200 53 I2CServo* positionManager = initPositionManager();
inst 0:4877273ec8cc 54
inst 0:4877273ec8cc 55 mSteering = new Steering( i2cMotor, i2cServo );
inst 0:4877273ec8cc 56 mShootingSystem = new ShootingSystem( angleManagerServo, ammoPusher,
inst 0:4877273ec8cc 57 ammoSupplier, shooter, positionManager );
inst 0:4877273ec8cc 58 }
inst 0:4877273ec8cc 59
inst 0:4877273ec8cc 60 OBROT::~OBROT(){
inst 0:4877273ec8cc 61 delete[] mI2CDevice;
inst 0:4877273ec8cc 62 delete mSteering;
inst 0:4877273ec8cc 63 delete mShootingSystem;
inst 0:4877273ec8cc 64 }
inst 0:4877273ec8cc 65
inst 0:4877273ec8cc 66 void OBROT::updateAction(){
inst 0:4877273ec8cc 67 Command command = mXBee->createCommand();
inst 0:4877273ec8cc 68
inst 0:4877273ec8cc 69 mShootingSystem->update( command );
inst 0:4877273ec8cc 70 mSteering->update( command );
inst 0:4877273ec8cc 71 }
inst 1:a46109178200 72
inst 1:a46109178200 73 I2CServo** OBROT::initSteeringServo(){
inst 1:a46109178200 74 I2CServo** i2cServo = new I2CServo*[ Steering::mNumOfTire ];
inst 1:a46109178200 75
inst 1:a46109178200 76 for ( int i = 0; i < Steering::mNumOfTire; ++i ){
inst 1:a46109178200 77 i2cServo[ i ] = new I2CServo( mI2CDeviceAddress[ i + Steering::mNumOfTire ] );
inst 1:a46109178200 78 mI2CDevice[ i + Steering::mNumOfTire ] = i2cServo[ i ];
inst 1:a46109178200 79 }
inst 1:a46109178200 80
inst 1:a46109178200 81 return i2cServo;
inst 1:a46109178200 82 }
inst 1:a46109178200 83
inst 1:a46109178200 84 I2CMotor** OBROT::initSteeringTire(){
inst 1:a46109178200 85 I2CMotor** i2cMotor = new I2CMotor*[ Steering::mNumOfTire ];
inst 1:a46109178200 86
inst 1:a46109178200 87 for ( int i = 0; i < Steering::mNumOfTire; ++i ){
inst 1:a46109178200 88 mI2CDevice[ i ] = i2cMotor[ i ] = new I2CMotor( mI2CDeviceAddress[ i ] );
inst 1:a46109178200 89 }
inst 1:a46109178200 90
inst 1:a46109178200 91 return i2cMotor;
inst 1:a46109178200 92 }
inst 1:a46109178200 93
inst 1:a46109178200 94 XBee* OBROT::initXBee(){
inst 1:a46109178200 95 mI2CDevice[ I2CDeviceID::XBEE ] = mXBee = new XBee( mI2CDeviceAddress[ I2CDeviceID::XBEE ] );
inst 1:a46109178200 96 return mXBee;
inst 1:a46109178200 97 }
inst 1:a46109178200 98
inst 1:a46109178200 99 I2CServo* OBROT::initAngleManager(){
inst 1:a46109178200 100 I2CServo* angleManagerServo = new I2CServo( mI2CDeviceAddress[ I2CDeviceID::ANGLE_MANAGER ] );
inst 1:a46109178200 101 mI2CDevice[ I2CDeviceID::ANGLE_MANAGER ] = angleManagerServo;
inst 1:a46109178200 102 return angleManagerServo;
inst 1:a46109178200 103 }
inst 1:a46109178200 104
inst 1:a46109178200 105 AmmoPusher* OBROT::initAmmoPusher(){
inst 1:a46109178200 106 AmmoPusher* ammoPusher = new AmmoPusher( mI2CDeviceAddress[ I2CDeviceID::AMMO_PUSHER ] );
inst 1:a46109178200 107 mI2CDevice[ I2CDeviceID::AMMO_PUSHER ] = ammoPusher;
inst 1:a46109178200 108 return ammoPusher;
inst 1:a46109178200 109 }
inst 1:a46109178200 110
inst 1:a46109178200 111 AmmoSupplier* OBROT::initAmmoSupplier(){
inst 1:a46109178200 112 AmmoSupplier* ammoSupplier = new AmmoSupplier( mI2CDeviceAddress[ I2CDeviceID::AMMO_SUPPLIER ] );
inst 1:a46109178200 113 mI2CDevice[ I2CDeviceID::AMMO_SUPPLIER ] = ammoSupplier;
inst 1:a46109178200 114 return ammoSupplier;
inst 1:a46109178200 115 }
inst 1:a46109178200 116
inst 1:a46109178200 117 Shooter* OBROT::initShooter(){
inst 1:a46109178200 118 Shooter* shooter = new Shooter( mI2CDeviceAddress[ I2CDeviceID::SHOOTER ] );
inst 1:a46109178200 119 mI2CDevice[ I2CDeviceID::SHOOTER ] = shooter;
inst 1:a46109178200 120 return shooter;
inst 1:a46109178200 121 }
inst 1:a46109178200 122
inst 1:a46109178200 123 I2CServo* OBROT::initPositionManager(){
inst 1:a46109178200 124 I2CServo* positionManager = new I2CServo( mI2CDeviceAddress[ I2CDeviceID::POSITION_MANAGER ] );
inst 1:a46109178200 125 mI2CDevice[ I2CDeviceID::POSITION_MANAGER ] = positionManager;
inst 1:a46109178200 126 return positionManager;
inst 1:a46109178200 127 }