Problems with motor #2

Dependents:   quadCommand2

Fork of PID by Derek McLean

Committer:
MitchJCarlson
Date:
Thu Jun 06 18:58:08 2013 +0000
Revision:
0:7e5fe0bea780
Added pid.h and pid.cpp to library

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 */
MitchJCarlson 0:7e5fe0bea780 15 class PID
MitchJCarlson 0:7e5fe0bea780 16 {
MitchJCarlson 0:7e5fe0bea780 17
MitchJCarlson 0:7e5fe0bea780 18 public:
MitchJCarlson 0:7e5fe0bea780 19 /**
MitchJCarlson 0:7e5fe0bea780 20 * Initialize the controller.
MitchJCarlson 0:7e5fe0bea780 21 *
MitchJCarlson 0:7e5fe0bea780 22 * @param proportionalGain Tuning value for adjusting the copter
MitchJCarlson 0:7e5fe0bea780 23 * towards a target position.
MitchJCarlson 0:7e5fe0bea780 24 * @param integralGain Tuning value for compensating for
MitchJCarlson 0:7e5fe0bea780 25 * environment imperfections that provide
MitchJCarlson 0:7e5fe0bea780 26 resistance such as friction.
MitchJCarlson 0:7e5fe0bea780 27 * @param derivativeGain Tuning value for compensating for
MitchJCarlson 0:7e5fe0bea780 28 * environment imperfections that cause
MitchJCarlson 0:7e5fe0bea780 29 * the system to overshoot the target,
MitchJCarlson 0:7e5fe0bea780 30 * such as momentum.
MitchJCarlson 0:7e5fe0bea780 31 * @param windupGainGuard Cap for the maximum error value.
MitchJCarlson 0:7e5fe0bea780 32 */
MitchJCarlson 0:7e5fe0bea780 33 PID(const float, const float, const float, const float);
MitchJCarlson 0:7e5fe0bea780 34
MitchJCarlson 0:7e5fe0bea780 35 /**
MitchJCarlson 0:7e5fe0bea780 36 * Determine how to correct the system to the desired position.
MitchJCarlson 0:7e5fe0bea780 37 *
MitchJCarlson 0:7e5fe0bea780 38 * @param currentPosition The current vector of the system.
MitchJCarlson 0:7e5fe0bea780 39 * @param targetPosition The desired vector of the system.
MitchJCarlson 0:7e5fe0bea780 40 * @param dt The change in time since the last adjustment.
MitchJCarlson 0:7e5fe0bea780 41 * (time determined by caller,
MitchJCarlson 0:7e5fe0bea780 42 * eg. PID can be switched off for manual control)
MitchJCarlson 0:7e5fe0bea780 43 * @return Adjustment to apply to the motors.
MitchJCarlson 0:7e5fe0bea780 44 */
MitchJCarlson 0:7e5fe0bea780 45 float correct(const float, const float, const float);
MitchJCarlson 0:7e5fe0bea780 46
MitchJCarlson 0:7e5fe0bea780 47 private:
MitchJCarlson 0:7e5fe0bea780 48 const float proportionalGain;
MitchJCarlson 0:7e5fe0bea780 49 const float integralGain;
MitchJCarlson 0:7e5fe0bea780 50 const float derivativeGain;
MitchJCarlson 0:7e5fe0bea780 51 const float windupGainGuard;
MitchJCarlson 0:7e5fe0bea780 52
MitchJCarlson 0:7e5fe0bea780 53 float previousError;
MitchJCarlson 0:7e5fe0bea780 54 float integralError;
MitchJCarlson 0:7e5fe0bea780 55
MitchJCarlson 0:7e5fe0bea780 56 };
MitchJCarlson 0:7e5fe0bea780 57
MitchJCarlson 0:7e5fe0bea780 58 #endif