added gy80 dcm
Dependencies: mbed DCM_AHRS_GY80 PID MMA8451Q
Fork of quadCommand by
quadCommand/quadCommand.h@59:9dfd9169a5e7, 2013-07-03 (annotated)
- Committer:
- gabdo
- Date:
- Wed Jul 03 04:45:03 2013 +0000
- Revision:
- 59:9dfd9169a5e7
- Parent:
- 58:983801808a94
- Child:
- 62:70fc58d4be9b
Working code, needs to be tuned.
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 | 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 | 56:a550127695b2 | 20 | #define MOTOR4 PTA5 // Pin used for motor 4. |
gabdo | 0:8681037b9a18 | 21 | |
gabdo | 9:9e0d0ba5b6b1 | 22 | // Xbee constants. |
gabdo | 56:a550127695b2 | 23 | #define TXPIN PTA2 // Pin used for xbee TX. |
gabdo | 56:a550127695b2 | 24 | #define RXPIN PTA1 // 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 | 44:a30ba531f614 | 31 | |
gabdo | 9:9e0d0ba5b6b1 | 32 | // PID constants. |
gabdo | 56:a550127695b2 | 33 | #define DEFAULT_WINDUP_GUARD 5.0 // Integral windup. |
gabdo | 59:9dfd9169a5e7 | 34 | #define PID_P 2.0 // Proportional gain. |
gabdo | 56:a550127695b2 | 35 | #define PID_I 0.0 // Integral gain. |
gabdo | 56:a550127695b2 | 36 | #define PID_D 0.0 // Derivative gain. |
gabdo | 59:9dfd9169a5e7 | 37 | #define MOTOR_UPDATE 150.0 // Motor update speed. |
dereklmc | 6:21ae5e53bb5f | 38 | |
gabdo | 0:8681037b9a18 | 39 | class quadCommand |
gabdo | 0:8681037b9a18 | 40 | { |
gabdo | 0:8681037b9a18 | 41 | public: |
gabdo | 56:a550127695b2 | 42 | quadCommand(); // Constructor. |
gabdo | 56:a550127695b2 | 43 | void run(); // The main loop. |
gabdo | 56:a550127695b2 | 44 | void rxInput(); // Receive data from the Xbee. |
gabdo | 56:a550127695b2 | 45 | void updateMotors(); // Send PID values to the motors. |
gabdo | 56:a550127695b2 | 46 | void updateCurrent(); // Update the current telemetry. |
dereklmc | 20:4cdabb792d16 | 47 | |
gabdo | 0:8681037b9a18 | 48 | private: |
gabdo | 56:a550127695b2 | 49 | motor *myMotors[4]; // Array of motor objects. |
gabdo | 56:a550127695b2 | 50 | com *myCom; // The com object for Xbee communication. |
gabdo | 56:a550127695b2 | 51 | sensors *world; // Sensors used to observe the world. |
gabdo | 55:bca9c9e92da6 | 52 | |
gabdo | 58:983801808a94 | 53 | PID *pidPitch; // PID for pitch. |
gabdo | 58:983801808a94 | 54 | PID *pidRoll; // PID for roll. |
gabdo | 58:983801808a94 | 55 | PID *pidYaw; // PID for yaw. |
gabdo | 0:8681037b9a18 | 56 | |
gabdo | 56:a550127695b2 | 57 | Ticker motorProcess; // Timer for updating the motors. |
gabdo | 58:983801808a94 | 58 | |
gabdo | 56:a550127695b2 | 59 | float currentThrottle; // Current throttle. |
gabdo | 56:a550127695b2 | 60 | float currentPitch; // Current pitch. |
gabdo | 56:a550127695b2 | 61 | float currentRoll; // Current roll. |
gabdo | 56:a550127695b2 | 62 | float currentYaw; // Current yaw. |
gabdo | 0:8681037b9a18 | 63 | |
gabdo | 56:a550127695b2 | 64 | float pitchTrim; // Trim the pitch. |
gabdo | 56:a550127695b2 | 65 | float rollTrim; // Trim the roll. |
gabdo | 59:9dfd9169a5e7 | 66 | float yawTrim; // Trim the yaw. |
dereklmc | 6:21ae5e53bb5f | 67 | |
gabdo | 56:a550127695b2 | 68 | float targetThrottle; // Desired throttle. |
gabdo | 56:a550127695b2 | 69 | float targetPitch; // Desired pitch. |
gabdo | 56:a550127695b2 | 70 | float targetRoll; // Desired roll. |
gabdo | 56:a550127695b2 | 71 | float targetYaw; // Desired yaw. |
gabdo | 0:8681037b9a18 | 72 | }; |
gabdo | 0:8681037b9a18 | 73 | |
gabdo | 0:8681037b9a18 | 74 | #endif |