Advertisement
Guest User

pid

a guest
Jan 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. #include "PID.h"
  2.  
  3. void PID_Cyclic (int goal, int current, struct PID_Einstellung& PID)
  4. {
  5. int AS = 15; //akzeptierer Fehler
  6.  
  7.  
  8. PID.e = goal - current; // aktuelle Regelabweichung bestimmen
  9. if ((PID.e >= AS)||(PID.e) >= (AS * (-1))) // Schwelle
  10. {
  11. if ((PID.u < 1023)&&(PID.u > 0)) // (Anti-Windup)
  12. PID.esum = PID.esum + PID.e;
  13.  
  14.  
  15. PID.u = PID.Kp* (PID.e + PID.I*PID.esum)+ PID.Tv*(PID.e-PID.ealt);
  16. PID.ealt = PID.e;
  17. }
  18. if (PID.u > 1023) // Stellgröße auf (10 bit PWM)
  19. {
  20. PID.u = 1023;
  21. }
  22.  
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement