added gy80 dcm
Dependencies: mbed DCM_AHRS_GY80 PID MMA8451Q
Fork of quadCommand by
quadCommand/quadCommand.cpp@4:ce6ad16337c5, 2013-06-09 (annotated)
- Committer:
- gabdo
- Date:
- Sun Jun 09 22:59:11 2013 +0000
- Revision:
- 4:ce6ad16337c5
- Parent:
- 1:9b90e7de6e09
- Child:
- 8:72791d8c36b7
None
;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gabdo | 0:8681037b9a18 | 1 | /************************ quadCommand.cpp ********************************/ |
gabdo | 0:8681037b9a18 | 2 | /* */ |
gabdo | 0:8681037b9a18 | 3 | /*************************************************************************/ |
gabdo | 0:8681037b9a18 | 4 | |
gabdo | 0:8681037b9a18 | 5 | #include "quadCommand.h" |
gabdo | 0:8681037b9a18 | 6 | |
gabdo | 0:8681037b9a18 | 7 | quadCommand::quadCommand() |
gabdo | 0:8681037b9a18 | 8 | { |
gabdo | 0:8681037b9a18 | 9 | myCom = new com( TXPIN, RXPIN ); // Setup com object. |
gabdo | 0:8681037b9a18 | 10 | world = new sensors(); // Setup the sensors. |
gabdo | 0:8681037b9a18 | 11 | |
gabdo | 0:8681037b9a18 | 12 | myMotors[0] = new motor( MOTOR1 ); // Connect motor 0 to PTD4 pin. |
gabdo | 0:8681037b9a18 | 13 | myMotors[1] = new motor( MOTOR2 ); // Connect motor 1 to PTA12 pin. |
gabdo | 0:8681037b9a18 | 14 | myMotors[2] = new motor( MOTOR3 ); // Connect motor 2 to PTA4 pin. |
gabdo | 0:8681037b9a18 | 15 | myMotors[3] = new motor( MOTOR4 ); // Connect motor 3 to PTA5 pin. |
gabdo | 0:8681037b9a18 | 16 | |
gabdo | 0:8681037b9a18 | 17 | rxThrottle = 0; |
gabdo | 0:8681037b9a18 | 18 | rxPitch = 0; |
gabdo | 0:8681037b9a18 | 19 | rxRoll = 0; |
gabdo | 0:8681037b9a18 | 20 | rxYaw = 0; |
gabdo | 0:8681037b9a18 | 21 | } |
gabdo | 0:8681037b9a18 | 22 | |
gabdo | 0:8681037b9a18 | 23 | void quadCommand::run() |
gabdo | 0:8681037b9a18 | 24 | { |
gabdo | 0:8681037b9a18 | 25 | while(1) |
gabdo | 0:8681037b9a18 | 26 | { |
gabdo | 0:8681037b9a18 | 27 | if( myCom->isData() ) |
gabdo | 0:8681037b9a18 | 28 | rxInput(); |
gabdo | 0:8681037b9a18 | 29 | } |
gabdo | 0:8681037b9a18 | 30 | } |
gabdo | 0:8681037b9a18 | 31 | |
gabdo | 0:8681037b9a18 | 32 | void quadCommand::rxInput() |
gabdo | 0:8681037b9a18 | 33 | { |
gabdo | 0:8681037b9a18 | 34 | short * command = myCom->read(); |
gabdo | 0:8681037b9a18 | 35 | |
gabdo | 0:8681037b9a18 | 36 | if( command[0] == 1 ) // Throttle command. |
gabdo | 0:8681037b9a18 | 37 | rxThrottle = command[1]; |
gabdo | 0:8681037b9a18 | 38 | |
gabdo | 0:8681037b9a18 | 39 | if( command[0] == 2 ) // Pitch command. |
gabdo | 0:8681037b9a18 | 40 | rxPitch = command[1]; |
gabdo | 0:8681037b9a18 | 41 | |
gabdo | 0:8681037b9a18 | 42 | if( command[0] == 3 ) // Roll command. |
gabdo | 0:8681037b9a18 | 43 | rxRoll = command[1]; |
gabdo | 0:8681037b9a18 | 44 | |
gabdo | 0:8681037b9a18 | 45 | if( command[0] == 4 ) // Yaw command. |
gabdo | 0:8681037b9a18 | 46 | rxYaw = command[1]; |
gabdo | 0:8681037b9a18 | 47 | |
gabdo | 0:8681037b9a18 | 48 | myMotors[ 0 ]->setSpeed( rxThrottle + rxPitch - rxRoll ); // Motor 1 |
gabdo | 0:8681037b9a18 | 49 | myMotors[ 1 ]->setSpeed( rxThrottle + rxPitch + rxRoll ); // Motor 2 |
gabdo | 0:8681037b9a18 | 50 | myMotors[ 2 ]->setSpeed( rxThrottle - rxPitch + rxRoll ); // Motor 3 |
gabdo | 0:8681037b9a18 | 51 | myMotors[ 3 ]->setSpeed( rxThrottle - rxPitch - rxRoll ); // Motor 4 |
gabdo | 0:8681037b9a18 | 52 | |
gabdo | 0:8681037b9a18 | 53 | delete[] command; |
gabdo | 0:8681037b9a18 | 54 | } |