added gy80 dcm
Dependencies: mbed DCM_AHRS_GY80 PID MMA8451Q
Fork of quadCommand by
quadCommand/quadCommand.h@64:2b6399fe00f6, 2013-07-28 (annotated)
- Committer:
- oprospero
- Date:
- Sun Jul 28 21:46:54 2013 +0000
- Revision:
- 64:2b6399fe00f6
- Parent:
- 63:f4cb482ac5d4
working state;
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" |
oprospero | 63:f4cb482ac5d4 | 11 | #include "DCM.h" |
oprospero | 10:af3be8c6aad7 | 12 | #include "PID.h" |
gabdo | 0:8681037b9a18 | 13 | |
oprospero | 63:f4cb482ac5d4 | 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. |
oprospero | 62:70fc58d4be9b | 34 | #define PID_P 1.0 // Proportional gain. |
gabdo | 56:a550127695b2 | 35 | #define PID_I 0.0 // Integral gain. |
oprospero | 63:f4cb482ac5d4 | 36 | #define PID_D 0.5 // 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. |
oprospero | 63:f4cb482ac5d4 | 51 | DCM *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 | |
oprospero | 63:f4cb482ac5d4 | 57 | Ticker motorProcess; // Timer for updating the motors. |
oprospero | 62:70fc58d4be9b | 58 | Timer timer; |
oprospero | 63:f4cb482ac5d4 | 59 | |
gabdo | 56:a550127695b2 | 60 | float currentThrottle; // Current throttle. |
gabdo | 56:a550127695b2 | 61 | float currentPitch; // Current pitch. |
gabdo | 56:a550127695b2 | 62 | float currentRoll; // Current roll. |
gabdo | 56:a550127695b2 | 63 | float currentYaw; // Current yaw. |
gabdo | 0:8681037b9a18 | 64 | |
gabdo | 56:a550127695b2 | 65 | float pitchTrim; // Trim the pitch. |
gabdo | 56:a550127695b2 | 66 | float rollTrim; // Trim the roll. |
gabdo | 59:9dfd9169a5e7 | 67 | float yawTrim; // Trim the yaw. |
dereklmc | 6:21ae5e53bb5f | 68 | |
gabdo | 56:a550127695b2 | 69 | float targetThrottle; // Desired throttle. |
gabdo | 56:a550127695b2 | 70 | float targetPitch; // Desired pitch. |
gabdo | 56:a550127695b2 | 71 | float targetRoll; // Desired roll. |
gabdo | 56:a550127695b2 | 72 | float targetYaw; // Desired yaw. |
oprospero | 63:f4cb482ac5d4 | 73 | float G_Dt; |
oprospero | 63:f4cb482ac5d4 | 74 | int timestamp_old; |
oprospero | 63:f4cb482ac5d4 | 75 | int timestamp; |
gabdo | 0:8681037b9a18 | 76 | }; |
gabdo | 0:8681037b9a18 | 77 | |
gabdo | 0:8681037b9a18 | 78 | #endif |