Advertisement
Guest User

pid.cpp

a guest
Jan 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include "PID.h"
  2. #include "everytime.h"
  3. #include <FrameStream.h>
  4. #include <Frameiterator.h>
  5. #include <avr/io.h>
  6. #include <avr/interrupt.h>
  7. #include "Odometry.h"
  8. #include "MotorControl.h"
  9. #define OUTPUT__BAUD_RATE 57600
  10. #include "Distance.h"
  11.  
  12. void PID_Cyclic (int current, struct PID_Einstellung& PID)
  13. {
  14. PID.Tn = (millis()-PID.T);
  15. PID.I = (1/PID.Tn);
  16. int AS = 0.15; //akzeptierer Fehler
  17.  
  18.  
  19. PID.e = PID.goal - current; // aktuelle Regelabweichung bestimmen
  20. if ((PID.e >= AS)||(PID.e) >= (AS * (-1))) // Schwelle
  21. {
  22. if ((PID.u < 1023)&&(PID.u > 0)) // (Anti-Windup)
  23. PID.esum = PID.esum + PID.e;
  24.  
  25.  
  26. PID.u = PID.Kp* (PID.e + PID.I*PID.esum)+ PID.Tv*(PID.e-PID.ealt);
  27. PID.ealt = PID.e;
  28. }
  29. if (PID.u>= 128)
  30. PID.u = 128;
  31.  
  32. if(PID.u<=-127)
  33. PID.u = -127;
  34.  
  35. PID.T = millis();
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement