added gy80 dcm

Dependencies:   mbed DCM_AHRS_GY80 PID MMA8451Q

Fork of quadCommand by Greg Abdo

Committer:
gabdo
Date:
Mon Jun 10 05:57:47 2013 +0000
Revision:
51:60258b84ebab
Parent:
50:197a18e49eb4
Child:
52:24590a45b807
Working with PID

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gabdo 0:8681037b9a18 1 /************************* quadCommand.h *********************************/
gabdo 0:8681037b9a18 2 /* */
gabdo 0:8681037b9a18 3 /*************************************************************************/
gabdo 0:8681037b9a18 4
gabdo 0:8681037b9a18 5 #ifndef QUAD_COMMAND_H
gabdo 0:8681037b9a18 6 #define QUAD_COMMAND_H
gabdo 0:8681037b9a18 7
gabdo 0:8681037b9a18 8 #include "mbed.h"
gabdo 0:8681037b9a18 9 #include "motor.h"
gabdo 0:8681037b9a18 10 #include "com.h"
gabdo 0:8681037b9a18 11 #include "sensors.h"
oprospero 10:af3be8c6aad7 12 #include "PID.h"
gabdo 0:8681037b9a18 13
gabdo 9:9e0d0ba5b6b1 14 // Motor constants.
gabdo 50:197a18e49eb4 15 #define MOTOR1 PTD4 // Pin used for motor 1.
gabdo 50:197a18e49eb4 16 #define MOTOR2 PTA12 // Pin used for motor 2.
gabdo 50:197a18e49eb4 17 #define MOTOR3 PTA4 // Pin used for motor 3.
gabdo 50:197a18e49eb4 18 #define MOTOR4 PTA5 // Pin used for motor 4.
gabdo 0:8681037b9a18 19
gabdo 9:9e0d0ba5b6b1 20 // Xbee constants.
oprospero 10:af3be8c6aad7 21 // Alternative Pins
oprospero 10:af3be8c6aad7 22 // RX = PTA1, TX PTA2
gabdo 50:197a18e49eb4 23 #define TXPIN PTD3 // Pin used for xbee TX.
gabdo 50:197a18e49eb4 24 #define RXPIN PTD2 // Pin used for xbee RX.
gabdo 0:8681037b9a18 25
oprospero 10:af3be8c6aad7 26
gabdo 9:9e0d0ba5b6b1 27 // Sensor constants.
gabdo 9:9e0d0ba5b6b1 28 #define MMA8451_I2C_ADDRESS (0x1d<<1) // Address of I2C accelerometer.
gabdo 50:197a18e49eb4 29 #define ACCSDA PTE25 // Pin for accelerometer SDA line.
gabdo 50:197a18e49eb4 30 #define ACCSCL PTE24 // Pin for accelerometer SCL line.
gabdo 50:197a18e49eb4 31 #define SENSSOR_DELAY 500.0f
gabdo 51:60258b84ebab 32 #define SEND_DELAY 500.0f
gabdo 44:a30ba531f614 33
gabdo 9:9e0d0ba5b6b1 34 // PID constants.
gabdo 49:f202fb0d4128 35 #define DEFAULT_WINDUP_GUARD 20.0f
gabdo 50:197a18e49eb4 36 #define MOTOR_UPDATE 500.0f
dereklmc 6:21ae5e53bb5f 37
gabdo 0:8681037b9a18 38 class quadCommand
gabdo 0:8681037b9a18 39 {
gabdo 0:8681037b9a18 40 public:
gabdo 0:8681037b9a18 41 quadCommand(); // Constructor.
gabdo 49:f202fb0d4128 42 void run(); // The main loop.
gabdo 49:f202fb0d4128 43 void rxInput(); // Receive data from the Xbee.
gabdo 49:f202fb0d4128 44 void updateMotors(); // Send PID values to the motors.
gabdo 49:f202fb0d4128 45 void updateCurrent(); // Update the current telemetry.
gabdo 49:f202fb0d4128 46 void sendTelemetry(); // Transmit the current telemetry.
dereklmc 20:4cdabb792d16 47
gabdo 0:8681037b9a18 48 private:
gabdo 0:8681037b9a18 49 motor *myMotors[4]; // Array of motor objects.
gabdo 50:197a18e49eb4 50 com *myCom; // The com object for Xbee communication.
gabdo 0:8681037b9a18 51 sensors *world; // Sensors used to observe the world.
gabdo 0:8681037b9a18 52
gabdo 50:197a18e49eb4 53 PID pidThrottle; // PID for throttle.
gabdo 50:197a18e49eb4 54 PID pidPitch; // PID for pitch.
gabdo 50:197a18e49eb4 55 PID pidRoll; // PID for roll.
gabdo 50:197a18e49eb4 56 PID pidYaw; // PID for yaw.
gabdo 45:088885f4a13d 57
gabdo 51:60258b84ebab 58 bool txValues;
gabdo 51:60258b84ebab 59
gabdo 50:197a18e49eb4 60 Ticker sensorProcess; // Timer for getting sensor data.
gabdo 50:197a18e49eb4 61 Ticker motorProcess; // Timer for updating the motors.
gabdo 51:60258b84ebab 62 Ticker sendProcess; // Timer for sending data through the Xbee.
gabdo 0:8681037b9a18 63
gabdo 50:197a18e49eb4 64 float currentThrottle; // Current throttle.
gabdo 50:197a18e49eb4 65 float currentPitch; // Current pitch.
gabdo 50:197a18e49eb4 66 float currentRoll; // Current roll.
gabdo 50:197a18e49eb4 67 float currentYaw; // Current yaw.
dereklmc 6:21ae5e53bb5f 68
gabdo 50:197a18e49eb4 69 float targetThrottle; // Desired throttle.
gabdo 50:197a18e49eb4 70 float targetPitch; // Desired pitch.
gabdo 50:197a18e49eb4 71 float targetRoll; // Desired roll.
gabdo 50:197a18e49eb4 72 float targetYaw; // Desired yaw.
gabdo 0:8681037b9a18 73 };
gabdo 0:8681037b9a18 74
gabdo 0:8681037b9a18 75 #endif