added gy80 dcm

Dependencies:   mbed DCM_AHRS_GY80 PID MMA8451Q

Fork of quadCommand by Greg Abdo

Committer:
gabdo
Date:
Sun Jun 09 23:56:44 2013 +0000
Revision:
9:9e0d0ba5b6b1
Parent:
8:72791d8c36b7
Child:
12:15d129d681e9
Child:
16:84c7db5b4464
Minor mods

Who changed what in which revision?

UserRevisionLine numberNew 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
dereklmc 8:72791d8c36b7 7 const float quadCommand::MOTOR_UPDATE(20.0);
dereklmc 8:72791d8c36b7 8
gabdo 0:8681037b9a18 9 quadCommand::quadCommand()
gabdo 0:8681037b9a18 10 {
gabdo 0:8681037b9a18 11 myCom = new com( TXPIN, RXPIN ); // Setup com object.
gabdo 0:8681037b9a18 12 world = new sensors(); // Setup the sensors.
gabdo 0:8681037b9a18 13
gabdo 0:8681037b9a18 14 myMotors[0] = new motor( MOTOR1 ); // Connect motor 0 to PTD4 pin.
gabdo 0:8681037b9a18 15 myMotors[1] = new motor( MOTOR2 ); // Connect motor 1 to PTA12 pin.
gabdo 0:8681037b9a18 16 myMotors[2] = new motor( MOTOR3 ); // Connect motor 2 to PTA4 pin.
gabdo 0:8681037b9a18 17 myMotors[3] = new motor( MOTOR4 ); // Connect motor 3 to PTA5 pin.
gabdo 0:8681037b9a18 18
gabdo 0:8681037b9a18 19 rxThrottle = 0;
gabdo 0:8681037b9a18 20 rxPitch = 0;
gabdo 0:8681037b9a18 21 rxRoll = 0;
gabdo 0:8681037b9a18 22 rxYaw = 0;
gabdo 0:8681037b9a18 23 }
gabdo 0:8681037b9a18 24
gabdo 9:9e0d0ba5b6b1 25 /******************************* run() ***********************************/
gabdo 9:9e0d0ba5b6b1 26 /* */
gabdo 9:9e0d0ba5b6b1 27 /*************************************************************************/
gabdo 9:9e0d0ba5b6b1 28
gabdo 0:8681037b9a18 29 void quadCommand::run()
gabdo 0:8681037b9a18 30 {
gabdo 0:8681037b9a18 31 while(1)
gabdo 0:8681037b9a18 32 {
gabdo 0:8681037b9a18 33 if( myCom->isData() )
gabdo 0:8681037b9a18 34 rxInput();
gabdo 0:8681037b9a18 35 }
gabdo 0:8681037b9a18 36 }
gabdo 0:8681037b9a18 37
gabdo 9:9e0d0ba5b6b1 38 /***************************** rxInput() *********************************/
gabdo 9:9e0d0ba5b6b1 39 /* */
gabdo 9:9e0d0ba5b6b1 40 /*************************************************************************/
gabdo 9:9e0d0ba5b6b1 41
gabdo 0:8681037b9a18 42 void quadCommand::rxInput()
gabdo 0:8681037b9a18 43 {
gabdo 0:8681037b9a18 44 short * command = myCom->read();
gabdo 0:8681037b9a18 45
gabdo 0:8681037b9a18 46 if( command[0] == 1 ) // Throttle command.
gabdo 9:9e0d0ba5b6b1 47 targetThrottle = command[1];
gabdo 0:8681037b9a18 48
gabdo 0:8681037b9a18 49 if( command[0] == 2 ) // Pitch command.
gabdo 9:9e0d0ba5b6b1 50 targetPitch = command[1];
gabdo 0:8681037b9a18 51
gabdo 0:8681037b9a18 52 if( command[0] == 3 ) // Roll command.
gabdo 9:9e0d0ba5b6b1 53 targetRoll = command[1];
gabdo 0:8681037b9a18 54
gabdo 0:8681037b9a18 55 if( command[0] == 4 ) // Yaw command.
gabdo 9:9e0d0ba5b6b1 56 targetYaw = command[1];
dereklmc 8:72791d8c36b7 57 }
dereklmc 8:72791d8c36b7 58
gabdo 9:9e0d0ba5b6b1 59 /*************************** updateMotors() ******************************/
gabdo 9:9e0d0ba5b6b1 60 /* */
gabdo 9:9e0d0ba5b6b1 61 /*************************************************************************/
gabdo 9:9e0d0ba5b6b1 62
dereklmc 8:72791d8c36b7 63 void quadCommand::updateMotors() {
dereklmc 8:72791d8c36b7 64 myMotors[ 0 ]->setSpeed( rxThrottle + rxPitch - rxRoll - rxYaw); // Motor 1
dereklmc 8:72791d8c36b7 65 myMotors[ 1 ]->setSpeed( rxThrottle + rxPitch + rxRoll + rxYaw); // Motor 2
dereklmc 8:72791d8c36b7 66 myMotors[ 2 ]->setSpeed( rxThrottle - rxPitch + rxRoll - rxYaw); // Motor 3
dereklmc 8:72791d8c36b7 67 myMotors[ 3 ]->setSpeed( rxThrottle - rxPitch - rxRoll + rxYaw); // Motor 4
gabdo 0:8681037b9a18 68
gabdo 0:8681037b9a18 69 delete[] command;
gabdo 0:8681037b9a18 70 }