naive pid impl
This commit is contained in:
parent
0534981d4b
commit
4ca507605a
1 changed files with 7 additions and 1 deletions
|
@ -122,8 +122,14 @@ protected:
|
||||||
// Calculate the error in speed
|
// Calculate the error in speed
|
||||||
float error = targetSpeed - speed;
|
float error = targetSpeed - speed;
|
||||||
|
|
||||||
|
sumError += error;
|
||||||
|
|
||||||
|
float errorDiff = error - prevError;
|
||||||
|
|
||||||
|
prevError = error;
|
||||||
|
|
||||||
// Calculate the effort from the PID gains
|
// Calculate the effort from the PID gains
|
||||||
int16_t effort = Kp * error;
|
int16_t effort = Kp * error + Ki * sumError + Kd * errorDiff;
|
||||||
|
|
||||||
// Set the effort for the motor
|
// Set the effort for the motor
|
||||||
SetEffort(effort);
|
SetEffort(effort);
|
||||||
|
|
Loading…
Reference in a new issue