Software > Software

PID algorithm

<< < (4/4)

[email protected]:
Error = target_pos - current_pos;             //calculate error
 P = Error * Kp;                       //error times proportional constant gives P
 I = I + (Ki*Error);                             //calculates the integral value
 D = kd * (Error - previos_error);       //stores change in error to derivate
 Correction = P + I + D;
 pwm = 175;
  RPM_of_Lm = pwm - (Correction);        // calculate pwm for motors
  RPM_of_Rm = pwm + (Correction);

now is this controller right???

You have two error terms one Error and one error. That is a problem.

You set the value for the previous error right after you calculate the Error - too late  - you need to do that BEFORE you change the value of Error.

But you are getting closer.

[email protected]:
is the term correction  right????
will it work properly...?

If you fix the errors noted above it should work (you will have to tune the gains of course - I would set Ki and kd = 0 and just work with Kp to start. Set the intital value to 10 - if that doesn't work try 1 (if it's turning too much) or 100 (not turning enough) once you get close you can change it by double or half instead of by 10 or 1/10)

[email protected]:
thanxx .. alot for your help....!
i am fixing the issues with the driver circuit ....
i would probably finish the driver problem in some days and than start tuning part.....


[0] Message Index

[*] Previous page

Go to full version