added gy80 dcm

Dependencies:   mbed DCM_AHRS_GY80 PID MMA8451Q

Fork of quadCommand by Greg Abdo

Committer:
gabdo
Date:
Thu Jun 13 01:11:03 2013 +0000
Revision:
55:bca9c9e92da6
Parent:
53:cce34958f952
Child:
56:a550127695b2
Good job!

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