added gy80 dcm
Dependencies: mbed DCM_AHRS_GY80 PID MMA8451Q
Fork of quadCommand by
quadCommand/quadCommand.h@49:f202fb0d4128, 2013-06-10 (annotated)
- Committer:
- gabdo
- Date:
- Mon Jun 10 04:43:30 2013 +0000
- Revision:
- 49:f202fb0d4128
- Parent:
- 48:75d06c707414
- Child:
- 50:197a18e49eb4
Few cleanup mods
;
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 | 0:8681037b9a18 | 15 | const PinName MOTOR1 = PTD4; // Pin used for motor 1. |
gabdo | 0:8681037b9a18 | 16 | const PinName MOTOR2 = PTA12; // Pin used for motor 2. |
gabdo | 0:8681037b9a18 | 17 | const PinName MOTOR3 = PTA4; // Pin used for motor 3. |
gabdo | 0:8681037b9a18 | 18 | const PinName 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 | 0:8681037b9a18 | 23 | const PinName TXPIN = PTD3; // Pin used for xbee TX. |
gabdo | 0:8681037b9a18 | 24 | const PinName 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 | 9:9e0d0ba5b6b1 | 29 | const PinName ACCSDA = PTE25; // Pin for accelerometer SDA line. |
gabdo | 9:9e0d0ba5b6b1 | 30 | const PinName ACCSCL = PTE24; // Pin for accelerometer SCL line. |
gabdo | 9:9e0d0ba5b6b1 | 31 | |
gabdo | 49:f202fb0d4128 | 32 | #define SENSSORDELAY 10.0f |
gabdo | 49:f202fb0d4128 | 33 | #define SENDDELAY 10.0f |
gabdo | 44:a30ba531f614 | 34 | |
gabdo | 9:9e0d0ba5b6b1 | 35 | // PID constants. |
gabdo | 49:f202fb0d4128 | 36 | #define DEFAULT_WINDUP_GUARD 20.0f |
gabdo | 49:f202fb0d4128 | 37 | #define MOTOR_UPDATE 10.0f |
dereklmc | 6:21ae5e53bb5f | 38 | |
gabdo | 0:8681037b9a18 | 39 | class quadCommand |
gabdo | 0:8681037b9a18 | 40 | { |
gabdo | 0:8681037b9a18 | 41 | public: |
gabdo | 0:8681037b9a18 | 42 | quadCommand(); // Constructor. |
gabdo | 49:f202fb0d4128 | 43 | void run(); // The main loop. |
gabdo | 49:f202fb0d4128 | 44 | void rxInput(); // Receive data from the Xbee. |
gabdo | 49:f202fb0d4128 | 45 | void updateMotors(); // Send PID values to the motors. |
gabdo | 49:f202fb0d4128 | 46 | void updateCurrent(); // Update the current telemetry. |
gabdo | 49:f202fb0d4128 | 47 | void sendTelemetry(); // Transmit the current telemetry. |
dereklmc | 20:4cdabb792d16 | 48 | |
gabdo | 0:8681037b9a18 | 49 | private: |
gabdo | 0:8681037b9a18 | 50 | motor *myMotors[4]; // Array of motor objects. |
gabdo | 0:8681037b9a18 | 51 | com *myCom; // The com object. |
gabdo | 0:8681037b9a18 | 52 | sensors *world; // Sensors used to observe the world. |
gabdo | 0:8681037b9a18 | 53 | |
gabdo | 45:088885f4a13d | 54 | Ticker sensorProcess; |
gabdo | 49:f202fb0d4128 | 55 | Ticker sendProcess; |
gabdo | 49:f202fb0d4128 | 56 | Ticker motorProcess; // Control timer |
gabdo | 45:088885f4a13d | 57 | |
gabdo | 1:9b90e7de6e09 | 58 | float currentThrottle; |
gabdo | 1:9b90e7de6e09 | 59 | float currentPitch; |
gabdo | 1:9b90e7de6e09 | 60 | float currentRoll; |
gabdo | 1:9b90e7de6e09 | 61 | float currentYaw; |
gabdo | 0:8681037b9a18 | 62 | |
gabdo | 1:9b90e7de6e09 | 63 | float targetThrottle; |
gabdo | 1:9b90e7de6e09 | 64 | float targetPitch; |
gabdo | 1:9b90e7de6e09 | 65 | float targetRoll; |
gabdo | 1:9b90e7de6e09 | 66 | float targetYaw; |
dereklmc | 6:21ae5e53bb5f | 67 | |
dereklmc | 17:d73944c3c945 | 68 | PID pidThrottle; |
dereklmc | 17:d73944c3c945 | 69 | PID pidPitch; |
dereklmc | 17:d73944c3c945 | 70 | PID pidRoll; |
dereklmc | 17:d73944c3c945 | 71 | PID pidYaw; |
gabdo | 0:8681037b9a18 | 72 | }; |
gabdo | 0:8681037b9a18 | 73 | |
gabdo | 0:8681037b9a18 | 74 | #endif |