from greg
Fork of PID by
PID.h@12:9d078cd8ca83, 2014-10-15 (annotated)
- Committer:
- oprospero
- Date:
- Wed Oct 15 04:59:05 2014 +0000
- Revision:
- 12:9d078cd8ca83
- Parent:
- 10:3296a2150efe
minor changes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MitchJCarlson | 0:7e5fe0bea780 | 1 | /** PID.h */ |
MitchJCarlson | 0:7e5fe0bea780 | 2 | |
MitchJCarlson | 0:7e5fe0bea780 | 3 | #ifndef UWBQuad__PID__h |
MitchJCarlson | 0:7e5fe0bea780 | 4 | #define UWBQuad__PID__h |
MitchJCarlson | 0:7e5fe0bea780 | 5 | |
oprospero | 12:9d078cd8ca83 | 6 | #define CONTROL_LIMIT 250 |
oprospero | 12:9d078cd8ca83 | 7 | |
MitchJCarlson | 0:7e5fe0bea780 | 8 | /** |
MitchJCarlson | 0:7e5fe0bea780 | 9 | * UWB Quadcopter project |
MitchJCarlson | 0:7e5fe0bea780 | 10 | * |
MitchJCarlson | 0:7e5fe0bea780 | 11 | * Implementation of the Proportional Integral Derivative |
MitchJCarlson | 0:7e5fe0bea780 | 12 | * control system for quadcopter stabilization. |
MitchJCarlson | 0:7e5fe0bea780 | 13 | * http://nicisdigital.wordpress.com/2011/06/27/proportional-integral-derivative-pid-controller/ |
MitchJCarlson | 0:7e5fe0bea780 | 14 | * |
MitchJCarlson | 0:7e5fe0bea780 | 15 | * @author UWB Quadcopter group |
MitchJCarlson | 0:7e5fe0bea780 | 16 | */ |
oprospero | 5:43a44c2880a3 | 17 | |
MitchJCarlson | 0:7e5fe0bea780 | 18 | class PID |
MitchJCarlson | 0:7e5fe0bea780 | 19 | { |
MitchJCarlson | 0:7e5fe0bea780 | 20 | |
MitchJCarlson | 0:7e5fe0bea780 | 21 | public: |
MitchJCarlson | 0:7e5fe0bea780 | 22 | /** |
MitchJCarlson | 0:7e5fe0bea780 | 23 | * Initialize the controller. |
MitchJCarlson | 0:7e5fe0bea780 | 24 | * |
MitchJCarlson | 0:7e5fe0bea780 | 25 | * @param proportionalGain Tuning value for adjusting the copter |
MitchJCarlson | 0:7e5fe0bea780 | 26 | * towards a target position. |
MitchJCarlson | 0:7e5fe0bea780 | 27 | * @param integralGain Tuning value for compensating for |
MitchJCarlson | 0:7e5fe0bea780 | 28 | * environment imperfections that provide |
MitchJCarlson | 0:7e5fe0bea780 | 29 | resistance such as friction. |
MitchJCarlson | 0:7e5fe0bea780 | 30 | * @param derivativeGain Tuning value for compensating for |
MitchJCarlson | 0:7e5fe0bea780 | 31 | * environment imperfections that cause |
MitchJCarlson | 0:7e5fe0bea780 | 32 | * the system to overshoot the target, |
MitchJCarlson | 0:7e5fe0bea780 | 33 | * such as momentum. |
MitchJCarlson | 0:7e5fe0bea780 | 34 | * @param windupGainGuard Cap for the maximum error value. |
MitchJCarlson | 0:7e5fe0bea780 | 35 | */ |
oprospero | 10:3296a2150efe | 36 | PID(const float, const float, const float, const float); |
MitchJCarlson | 0:7e5fe0bea780 | 37 | |
MitchJCarlson | 0:7e5fe0bea780 | 38 | /** |
MitchJCarlson | 0:7e5fe0bea780 | 39 | * Determine how to correct the system to the desired position. |
MitchJCarlson | 0:7e5fe0bea780 | 40 | * |
MitchJCarlson | 0:7e5fe0bea780 | 41 | * @param currentPosition The current vector of the system. |
MitchJCarlson | 0:7e5fe0bea780 | 42 | * @param targetPosition The desired vector of the system. |
MitchJCarlson | 0:7e5fe0bea780 | 43 | * @param dt The change in time since the last adjustment. |
MitchJCarlson | 0:7e5fe0bea780 | 44 | * (time determined by caller, |
MitchJCarlson | 0:7e5fe0bea780 | 45 | * eg. PID can be switched off for manual control) |
MitchJCarlson | 0:7e5fe0bea780 | 46 | * @return Adjustment to apply to the motors. |
MitchJCarlson | 0:7e5fe0bea780 | 47 | */ |
oprospero | 10:3296a2150efe | 48 | float correct(const float,const int); |
oprospero | 8:a020a225bc65 | 49 | |
oprospero | 8:a020a225bc65 | 50 | void updateP(const float); |
oprospero | 8:a020a225bc65 | 51 | void updateD(const float); |
oprospero | 12:9d078cd8ca83 | 52 | void setControlLimit(const float); |
MitchJCarlson | 0:7e5fe0bea780 | 53 | |
MitchJCarlson | 0:7e5fe0bea780 | 54 | private: |
oprospero | 7:1b1c2ded95f5 | 55 | float proportionalGain; |
MitchJCarlson | 0:7e5fe0bea780 | 56 | const float integralGain; |
oprospero | 8:a020a225bc65 | 57 | float derivativeGain; |
MitchJCarlson | 0:7e5fe0bea780 | 58 | const float windupGainGuard; |
oprospero | 7:1b1c2ded95f5 | 59 | float proportionalControl, integralControl, derivativeControl; |
MitchJCarlson | 0:7e5fe0bea780 | 60 | |
oprospero | 7:1b1c2ded95f5 | 61 | float currentError; |
MitchJCarlson | 0:7e5fe0bea780 | 62 | float previousError; |
MitchJCarlson | 0:7e5fe0bea780 | 63 | float integralError; |
oprospero | 12:9d078cd8ca83 | 64 | |
oprospero | 12:9d078cd8ca83 | 65 | float controlTotal; |
oprospero | 12:9d078cd8ca83 | 66 | |
MitchJCarlson | 0:7e5fe0bea780 | 67 | |
MitchJCarlson | 0:7e5fe0bea780 | 68 | }; |
MitchJCarlson | 0:7e5fe0bea780 | 69 | |
MitchJCarlson | 0:7e5fe0bea780 | 70 | #endif |