test
Dependencies: Encoder_Nucleo_16_bits
Diff: PID.cpp
- Revision:
- 2:d6f14bb935da
- Parent:
- 1:24c444f3716b
- Child:
- 3:93fb84c4e9bc
--- a/PID.cpp Mon May 21 16:16:13 2018 +0000 +++ b/PID.cpp Tue May 22 17:15:51 2018 +0000 @@ -16,7 +16,7 @@ _Ki = 0; _Kd = 0; - _tick.attach(this, &PID::controlLoop, _loopTime); + _tick.attach(callback(this, &PID::controlLoop), _loopTime); } float PID::setProportionnalValue (float KpValue) @@ -42,22 +42,26 @@ _consigne = setPoint; } +long PID::getPosition (void) +{ + return _Position; +} + void PID::controlLoop() { static int firstTime = 1; static float integralError = 0; static float oldError; double deltaD, error, commande; - long position; static long int oldPosition; - position = _encoder.GetCounter(); + _Position = _encoder.GetCounter(); if (firstTime) { - oldPosition = position; + oldPosition = _Position; firstTime = 0; } else { - deltaD = 1000.0 * ((double)position - (double)oldPosition) / _scale; - oldPosition = position; + deltaD = 1000.0 * ((double)_Position - (double)oldPosition) / _scale; + oldPosition = _Position; error = _consigne - deltaD; integralError += error;