added gy80 dcm
Dependencies: mbed DCM_AHRS_GY80 PID MMA8451Q
Fork of quadCommand by
quadCommand/quadCommand.h@53:cce34958f952, 2013-06-11 (annotated)
- Committer:
- gabdo
- Date:
- Tue Jun 11 02:36:12 2013 +0000
- Revision:
- 53:cce34958f952
- Parent:
- 52:24590a45b807
- Child:
- 55:bca9c9e92da6
Some optimization.
Who changed what in which revision?
User | Revision | Line number | New 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 | 52:24590a45b807 | 31 | #define SENSSOR_DELAY 100.0f |
gabdo | 44:a30ba531f614 | 32 | |
gabdo | 9:9e0d0ba5b6b1 | 33 | // PID constants. |
gabdo | 49:f202fb0d4128 | 34 | #define DEFAULT_WINDUP_GUARD 20.0f |
gabdo | 52:24590a45b807 | 35 | #define MOTOR_UPDATE 100.0f |
dereklmc | 6:21ae5e53bb5f | 36 | |
gabdo | 0:8681037b9a18 | 37 | class quadCommand |
gabdo | 0:8681037b9a18 | 38 | { |
gabdo | 0:8681037b9a18 | 39 | public: |
gabdo | 0:8681037b9a18 | 40 | quadCommand(); // Constructor. |
gabdo | 49:f202fb0d4128 | 41 | void run(); // The main loop. |
gabdo | 49:f202fb0d4128 | 42 | void rxInput(); // Receive data from the Xbee. |
gabdo | 49:f202fb0d4128 | 43 | void updateMotors(); // Send PID values to the motors. |
gabdo | 49:f202fb0d4128 | 44 | void updateCurrent(); // Update the current telemetry. |
gabdo | 49:f202fb0d4128 | 45 | void sendTelemetry(); // Transmit the current telemetry. |
dereklmc | 20:4cdabb792d16 | 46 | |
gabdo | 0:8681037b9a18 | 47 | private: |
gabdo | 0:8681037b9a18 | 48 | motor *myMotors[4]; // Array of motor objects. |
gabdo | 50:197a18e49eb4 | 49 | com *myCom; // The com object for Xbee communication. |
gabdo | 0:8681037b9a18 | 50 | sensors *world; // Sensors used to observe the world. |
gabdo | 0:8681037b9a18 | 51 | |
gabdo | 50:197a18e49eb4 | 52 | PID pidThrottle; // PID for throttle. |
gabdo | 50:197a18e49eb4 | 53 | PID pidPitch; // PID for pitch. |
gabdo | 50:197a18e49eb4 | 54 | PID pidRoll; // PID for roll. |
gabdo | 50:197a18e49eb4 | 55 | PID pidYaw; // PID for yaw. |
gabdo | 45:088885f4a13d | 56 | |
gabdo | 50:197a18e49eb4 | 57 | Ticker motorProcess; // Timer for updating the motors. |
gabdo | 53:cce34958f952 | 58 | //Ticker sensorProcess; // Timer for getting sensor data. |
gabdo | 53:cce34958f952 | 59 | //Ticker sendProcess; // Timer for sending data through the Xbee. |
gabdo | 0:8681037b9a18 | 60 | |
gabdo | 50:197a18e49eb4 | 61 | float currentThrottle; // Current throttle. |
gabdo | 50:197a18e49eb4 | 62 | float currentPitch; // Current pitch. |
gabdo | 50:197a18e49eb4 | 63 | float currentRoll; // Current roll. |
gabdo | 50:197a18e49eb4 | 64 | float currentYaw; // Current yaw. |
dereklmc | 6:21ae5e53bb5f | 65 | |
gabdo | 50:197a18e49eb4 | 66 | float targetThrottle; // Desired throttle. |
gabdo | 50:197a18e49eb4 | 67 | float targetPitch; // Desired pitch. |
gabdo | 50:197a18e49eb4 | 68 | float targetRoll; // Desired roll. |
gabdo | 50:197a18e49eb4 | 69 | float targetYaw; // Desired yaw. |
gabdo | 0:8681037b9a18 | 70 | }; |
gabdo | 0:8681037b9a18 | 71 | |
gabdo | 0:8681037b9a18 | 72 | #endif |