from greg

Fork of PID by Greg Abdo

Committer:
oprospero
Date:
Sat Feb 15 19:55:04 2014 +0000
Revision:
9:244f8204d1fa
Parent:
8:a020a225bc65
Child:
10:3296a2150efe
Update windup guard logic

Who changed what in which revision?

UserRevisionLine numberNew 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 9:244f8204d1fa 34 PID(const float, const float, const float, const float, const float);
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 8:a020a225bc65 46 float correct(const float);
oprospero 8:a020a225bc65 47
oprospero 8:a020a225bc65 48 void updateP(const float);
oprospero 8:a020a225bc65 49 void updateD(const float);
MitchJCarlson 0:7e5fe0bea780 50
MitchJCarlson 0:7e5fe0bea780 51 private:
oprospero 7:1b1c2ded95f5 52 float proportionalGain;
MitchJCarlson 0:7e5fe0bea780 53 const float integralGain;
oprospero 8:a020a225bc65 54 float derivativeGain;
MitchJCarlson 0:7e5fe0bea780 55 const float windupGainGuard;
oprospero 9:244f8204d1fa 56 const float dt;
oprospero 7:1b1c2ded95f5 57 float proportionalControl, integralControl, derivativeControl;
MitchJCarlson 0:7e5fe0bea780 58
oprospero 7:1b1c2ded95f5 59 float currentError;
MitchJCarlson 0:7e5fe0bea780 60 float previousError;
MitchJCarlson 0:7e5fe0bea780 61 float integralError;
MitchJCarlson 0:7e5fe0bea780 62
MitchJCarlson 0:7e5fe0bea780 63 };
MitchJCarlson 0:7e5fe0bea780 64
MitchJCarlson 0:7e5fe0bea780 65 #endif