from greg
Fork of PID by
PID.h@7:1b1c2ded95f5, 2013-12-21 (annotated)
- Committer:
- oprospero
- Date:
- Sat Dec 21 08:27:42 2013 +0000
- Revision:
- 7:1b1c2ded95f5
- Parent:
- 5:43a44c2880a3
- Child:
- 8:a020a225bc65
Reduce PID parameters. Made P variable remotely changable;
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 | |
MitchJCarlson | 0:7e5fe0bea780 | 6 | /** |
MitchJCarlson | 0:7e5fe0bea780 | 7 | * UWB Quadcopter project |
MitchJCarlson | 0:7e5fe0bea780 | 8 | * |
MitchJCarlson | 0:7e5fe0bea780 | 9 | * Implementation of the Proportional Integral Derivative |
MitchJCarlson | 0:7e5fe0bea780 | 10 | * control system for quadcopter stabilization. |
MitchJCarlson | 0:7e5fe0bea780 | 11 | * http://nicisdigital.wordpress.com/2011/06/27/proportional-integral-derivative-pid-controller/ |
MitchJCarlson | 0:7e5fe0bea780 | 12 | * |
MitchJCarlson | 0:7e5fe0bea780 | 13 | * @author UWB Quadcopter group |
MitchJCarlson | 0:7e5fe0bea780 | 14 | */ |
oprospero | 5:43a44c2880a3 | 15 | |
MitchJCarlson | 0:7e5fe0bea780 | 16 | class PID |
MitchJCarlson | 0:7e5fe0bea780 | 17 | { |
MitchJCarlson | 0:7e5fe0bea780 | 18 | |
MitchJCarlson | 0:7e5fe0bea780 | 19 | public: |
MitchJCarlson | 0:7e5fe0bea780 | 20 | /** |
MitchJCarlson | 0:7e5fe0bea780 | 21 | * Initialize the controller. |
MitchJCarlson | 0:7e5fe0bea780 | 22 | * |
MitchJCarlson | 0:7e5fe0bea780 | 23 | * @param proportionalGain Tuning value for adjusting the copter |
MitchJCarlson | 0:7e5fe0bea780 | 24 | * towards a target position. |
MitchJCarlson | 0:7e5fe0bea780 | 25 | * @param integralGain Tuning value for compensating for |
MitchJCarlson | 0:7e5fe0bea780 | 26 | * environment imperfections that provide |
MitchJCarlson | 0:7e5fe0bea780 | 27 | resistance such as friction. |
MitchJCarlson | 0:7e5fe0bea780 | 28 | * @param derivativeGain Tuning value for compensating for |
MitchJCarlson | 0:7e5fe0bea780 | 29 | * environment imperfections that cause |
MitchJCarlson | 0:7e5fe0bea780 | 30 | * the system to overshoot the target, |
MitchJCarlson | 0:7e5fe0bea780 | 31 | * such as momentum. |
MitchJCarlson | 0:7e5fe0bea780 | 32 | * @param windupGainGuard Cap for the maximum error value. |
MitchJCarlson | 0:7e5fe0bea780 | 33 | */ |
oprospero | 7:1b1c2ded95f5 | 34 | PID(const float, const float, const float, const float, const int); |
MitchJCarlson | 0:7e5fe0bea780 | 35 | |
MitchJCarlson | 0:7e5fe0bea780 | 36 | /** |
MitchJCarlson | 0:7e5fe0bea780 | 37 | * Determine how to correct the system to the desired position. |
MitchJCarlson | 0:7e5fe0bea780 | 38 | * |
MitchJCarlson | 0:7e5fe0bea780 | 39 | * @param currentPosition The current vector of the system. |
MitchJCarlson | 0:7e5fe0bea780 | 40 | * @param targetPosition The desired vector of the system. |
MitchJCarlson | 0:7e5fe0bea780 | 41 | * @param dt The change in time since the last adjustment. |
MitchJCarlson | 0:7e5fe0bea780 | 42 | * (time determined by caller, |
MitchJCarlson | 0:7e5fe0bea780 | 43 | * eg. PID can be switched off for manual control) |
MitchJCarlson | 0:7e5fe0bea780 | 44 | * @return Adjustment to apply to the motors. |
MitchJCarlson | 0:7e5fe0bea780 | 45 | */ |
oprospero | 7:1b1c2ded95f5 | 46 | float correct(const float, const float); |
MitchJCarlson | 0:7e5fe0bea780 | 47 | |
MitchJCarlson | 0:7e5fe0bea780 | 48 | private: |
oprospero | 7:1b1c2ded95f5 | 49 | float proportionalGain; |
MitchJCarlson | 0:7e5fe0bea780 | 50 | const float integralGain; |
MitchJCarlson | 0:7e5fe0bea780 | 51 | const float derivativeGain; |
MitchJCarlson | 0:7e5fe0bea780 | 52 | const float windupGainGuard; |
oprospero | 7:1b1c2ded95f5 | 53 | const int dt; |
oprospero | 7:1b1c2ded95f5 | 54 | float proportionalControl, integralControl, derivativeControl; |
MitchJCarlson | 0:7e5fe0bea780 | 55 | |
oprospero | 7:1b1c2ded95f5 | 56 | float currentError; |
MitchJCarlson | 0:7e5fe0bea780 | 57 | float previousError; |
MitchJCarlson | 0:7e5fe0bea780 | 58 | float integralError; |
MitchJCarlson | 0:7e5fe0bea780 | 59 | |
MitchJCarlson | 0:7e5fe0bea780 | 60 | }; |
MitchJCarlson | 0:7e5fe0bea780 | 61 | |
MitchJCarlson | 0:7e5fe0bea780 | 62 | #endif |