added gy80 dcm

Dependencies:   mbed DCM_AHRS_GY80 PID MMA8451Q

Fork of quadCommand by Greg Abdo

Committer:
dereklmc
Date:
Mon Jun 10 02:10:19 2013 +0000
Revision:
46:f1eb22f41ebc
Parent:
43:e2fc699e8e8c
Child:
47:adc1a438aa33
Added more debug state.

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"
dereklmc 32:3d180aa938ba 6 #include "debug.h"
gabdo 0:8681037b9a18 7
dereklmc 15:92ecb025fbc5 8 const float quadCommand::MOTOR_UPDATE(20.0f);
dereklmc 8:72791d8c36b7 9
dereklmc 17:d73944c3c945 10 quadCommand::quadCommand() :
dereklmc 17:d73944c3c945 11 pidThrottle(1.5,0.1,1.20,DEFAULT_WINDUP_GUARD),
dereklmc 17:d73944c3c945 12 pidPitch(1.5,0.1,1.20,DEFAULT_WINDUP_GUARD),
dereklmc 17:d73944c3c945 13 pidRoll(1.5,0.1,1.20,DEFAULT_WINDUP_GUARD),
dereklmc 17:d73944c3c945 14 pidYaw(1.5,0.1,1.20,DEFAULT_WINDUP_GUARD)
gabdo 0:8681037b9a18 15 {
gabdo 43:e2fc699e8e8c 16 //sensorProcess.attach( this,&quadCommand::sendTelemetry, 2 );
gabdo 43:e2fc699e8e8c 17 sensorProcess.attach( this, &quadCommand::updateCurrent, .002 );
gabdo 43:e2fc699e8e8c 18
gabdo 0:8681037b9a18 19 myCom = new com( TXPIN, RXPIN ); // Setup com object.
gabdo 0:8681037b9a18 20 world = new sensors(); // Setup the sensors.
gabdo 0:8681037b9a18 21
gabdo 0:8681037b9a18 22 myMotors[0] = new motor( MOTOR1 ); // Connect motor 0 to PTD4 pin.
gabdo 0:8681037b9a18 23 myMotors[1] = new motor( MOTOR2 ); // Connect motor 1 to PTA12 pin.
gabdo 0:8681037b9a18 24 myMotors[2] = new motor( MOTOR3 ); // Connect motor 2 to PTA4 pin.
gabdo 0:8681037b9a18 25 myMotors[3] = new motor( MOTOR4 ); // Connect motor 3 to PTA5 pin.
gabdo 0:8681037b9a18 26 }
gabdo 0:8681037b9a18 27
gabdo 9:9e0d0ba5b6b1 28 /******************************* run() ***********************************/
oprospero 26:826448361267 29 /* Called from main */
gabdo 9:9e0d0ba5b6b1 30 /*************************************************************************/
gabdo 9:9e0d0ba5b6b1 31
gabdo 0:8681037b9a18 32 void quadCommand::run()
gabdo 0:8681037b9a18 33 {
gabdo 0:8681037b9a18 34 while(1)
gabdo 43:e2fc699e8e8c 35 {
oprospero 26:826448361267 36 if( myCom->isData() )
gabdo 0:8681037b9a18 37 rxInput();
gabdo 0:8681037b9a18 38 }
gabdo 0:8681037b9a18 39 }
gabdo 0:8681037b9a18 40
gabdo 9:9e0d0ba5b6b1 41 /***************************** rxInput() *********************************/
oprospero 26:826448361267 42 /*Call from run() */
gabdo 9:9e0d0ba5b6b1 43 /*************************************************************************/
gabdo 9:9e0d0ba5b6b1 44
gabdo 0:8681037b9a18 45 void quadCommand::rxInput()
gabdo 0:8681037b9a18 46 {
gabdo 0:8681037b9a18 47 short * command = myCom->read();
gabdo 0:8681037b9a18 48
gabdo 0:8681037b9a18 49 if( command[0] == 1 ) // Throttle command.
gabdo 9:9e0d0ba5b6b1 50 targetThrottle = command[1];
gabdo 0:8681037b9a18 51
gabdo 0:8681037b9a18 52 if( command[0] == 2 ) // Pitch command.
gabdo 9:9e0d0ba5b6b1 53 targetPitch = command[1];
gabdo 0:8681037b9a18 54
gabdo 0:8681037b9a18 55 if( command[0] == 3 ) // Roll command.
gabdo 9:9e0d0ba5b6b1 56 targetRoll = command[1];
gabdo 0:8681037b9a18 57
gabdo 0:8681037b9a18 58 if( command[0] == 4 ) // Yaw command.
gabdo 9:9e0d0ba5b6b1 59 targetYaw = command[1];
gabdo 12:15d129d681e9 60
gabdo 12:15d129d681e9 61 delete[] command;
dereklmc 8:72791d8c36b7 62 }
dereklmc 8:72791d8c36b7 63
gabdo 9:9e0d0ba5b6b1 64 /*************************** updateMotors() ******************************/
oprospero 26:826448361267 65 /*Called in main by motorprocess */
gabdo 9:9e0d0ba5b6b1 66 /*************************************************************************/
gabdo 9:9e0d0ba5b6b1 67
dereklmc 8:72791d8c36b7 68 void quadCommand::updateMotors() {
dereklmc 15:92ecb025fbc5 69 float throttle, pitch, roll, yaw;
dereklmc 15:92ecb025fbc5 70
dereklmc 15:92ecb025fbc5 71 throttle = pidThrottle.correct(currentThrottle, targetThrottle, MOTOR_UPDATE);
dereklmc 15:92ecb025fbc5 72 pitch = pidPitch.correct(currentPitch, targetPitch, MOTOR_UPDATE);
dereklmc 15:92ecb025fbc5 73 roll = pidRoll.correct(currentRoll, targetRoll, MOTOR_UPDATE);
dereklmc 15:92ecb025fbc5 74 yaw = 0.0; //pidYaw.correct(currentYaw, targetYaw, MOTOR_UPDATE);
dereklmc 32:3d180aa938ba 75
dereklmc 46:f1eb22f41ebc 76 DEBUG(pc.printf("----------------------------------------");)
dereklmc 46:f1eb22f41ebc 77 DEBUG(pc.printf("cur : { t : %f, p : %f, r : %f, y : %f }\r\n", currentThrottle, currentPitch, currentRoll, 0.0);)
dereklmc 46:f1eb22f41ebc 78 DEBUG(pc.printf("tar : { t : %f, p : %f, r : %f, y : %f }\r\n", targetThrottle, targetPitch, targetRoll, 0.0);)
dereklmc 41:40e432c5cbe6 79 DEBUG(pc.printf("att : { t : %f, p : %f, r : %f, y : %f }\r\n", throttle, pitch, roll, yaw);)
dereklmc 46:f1eb22f41ebc 80 DEBUG(pc.printf("----------------------------------------");)
dereklmc 15:92ecb025fbc5 81
dereklmc 46:f1eb22f41ebc 82 float speed0 = throttle + pitch - roll - yaw;
dereklmc 46:f1eb22f41ebc 83 float speed1 = throttle + pitch + roll + yaw;
dereklmc 46:f1eb22f41ebc 84 float speed2 = throttle - pitch + roll - yaw;
dereklmc 46:f1eb22f41ebc 85 float speed3 = throttle - pitch - roll + yaw;
dereklmc 33:4f62a7a46e71 86
dereklmc 41:40e432c5cbe6 87 DEBUG(pc.printf("motor : [ %f , %f , %f , %f ]\r\n", speed0, speed1, speed2, speed3);)
dereklmc 33:4f62a7a46e71 88
dereklmc 33:4f62a7a46e71 89 myMotors[ 0 ]->setSpeed(speed0); // Motor 1
dereklmc 33:4f62a7a46e71 90 myMotors[ 1 ]->setSpeed(speed1); // Motor 2
dereklmc 33:4f62a7a46e71 91 myMotors[ 2 ]->setSpeed(speed2); // Motor 3
dereklmc 33:4f62a7a46e71 92 myMotors[ 3 ]->setSpeed(speed3); // Motor 4
gabdo 40:8c01bf294768 93 }
gabdo 40:8c01bf294768 94
gabdo 40:8c01bf294768 95 /**************************** sendData() *********************************/
gabdo 40:8c01bf294768 96 /* */
gabdo 40:8c01bf294768 97 /*************************************************************************/
gabdo 40:8c01bf294768 98
gabdo 40:8c01bf294768 99 void quadCommand::sendTelemetry()
gabdo 40:8c01bf294768 100 {
gabdo 40:8c01bf294768 101
gabdo 43:e2fc699e8e8c 102 }
gabdo 43:e2fc699e8e8c 103
gabdo 43:e2fc699e8e8c 104 /************************** updateCurrent() ******************************/
gabdo 43:e2fc699e8e8c 105 /* */
gabdo 43:e2fc699e8e8c 106 /*************************************************************************/
gabdo 43:e2fc699e8e8c 107
gabdo 43:e2fc699e8e8c 108 void quadCommand::updateCurrent()
gabdo 43:e2fc699e8e8c 109 {
gabdo 43:e2fc699e8e8c 110 currentPitch = world->getAbsoluteX();
gabdo 43:e2fc699e8e8c 111 currentRoll = world->getAbsoluteY();
gabdo 0:8681037b9a18 112 }