pid_controller.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /************************************************************************
  2. Description:Functions and type-defs for PID control.
  3. Taken mostly from Mike Ferguson's ArbotiX code which lives at:
  4. http://vanadium-ros-pkg.googlecode.com/svn/trunk/arbotix/
  5. Author: www.corvin.cn
  6. History: 20180209: init this file;
  7. **************************************************************************/
  8. #ifndef _PID_CONTROLLER_H_
  9. #define _PID_CONTROLLER_H_
  10. /* PID setpoint info For a Motor */
  11. typedef struct {
  12. double TargetTicksPerFrame; // target speed in ticks per frame
  13. long Encoder; // encoder count
  14. long PrevEnc; // last encoder count
  15. /*
  16. Using previous input (PrevInput) instead of PrevError to avoid derivative kick,
  17. see http://brettbeauregard.com/blog/2011/04/improving-the-beginner%E2%80%99s-pid-derivative-kick/
  18. */
  19. int PrevInput; // last input
  20. /*
  21. Using integrated term (ITerm) instead of integrated error (Ierror),
  22. to allow tuning changes,
  23. see http://brettbeauregard.com/blog/2011/04/improving-the-beginner%E2%80%99s-pid-tuning-changes/
  24. */
  25. int ITerm; //integrated term
  26. long output; //last motor setting
  27. }SetPointInfo;
  28. void resetPID(void);
  29. void updatePID(void);
  30. long readPidIn(int wheel);
  31. long readPidOut(int wheel);
  32. void setMoveStatus(unsigned char state);
  33. unsigned char getMoveStatus(void);
  34. void setWheelPIDTarget(int value_A, int value_B, int value_C);
  35. void updatePIDParam(int index, int kp, int kd, int ki, int ko);
  36. #endif