pid.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*********************************************************************
  2. *
  3. * pid library for Fraise pic18f device
  4. *
  5. * -pid regulator with maximum output setting
  6. * and anti-windup tracking gain
  7. *********************************************************************
  8. * Author Date Comment
  9. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  10. * Antoine Rousseau dec 2012 Original.
  11. ********************************************************************/
  12. /*
  13. # This program is free software; you can redistribute it and/or
  14. # modify it under the terms of the GNU General Public License
  15. # as published by the Free Software Foundation; either version 2
  16. # of the License, or (at your option) any later version.
  17. #
  18. # This program is distributed in the hope that it will be useful,
  19. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. # GNU General Public License for more details.
  22. # You should have received a copy of the GNU General Public License
  23. # along with this program; if not, write to the Free Software
  24. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25. # MA 02110-1301, USA.
  26. */
  27. #ifndef _pid_H_
  28. #define _pid_H_
  29. #include <fruit.h>
  30. /*
  31. error input : signed 16 bit (int)
  32. gains : unsigned 8 bits
  33. Int = Integration sum clipped to [-1<<26, 1<<26[, then divided by 16 (>>4)
  34. Integration sum of error*GainI : signed max 31 bits
  35. Proportionnal term error*GainP : signed max 24 bits
  36. GainD is multiplied by 128 (1<<7)
  37. Differential term derror*GainD : signed max 30 bits
  38. */
  39. typedef struct {
  40. unsigned char GainP, GainI, GainD;
  41. long int Int; // integral sum
  42. long int Last; // last error, used to compute differential term
  43. long int Out; // output of pid regulator
  44. int MaxOut; // maximum ouput allowed for pid regulator ; multiplied by 256.
  45. } t_pid ;
  46. void pidInit(t_pid *Pid);
  47. void pidCompute(t_pid *Pid,int err);
  48. void pidInput(t_pid *Pid);
  49. void pidDeclareEE(t_pid *Pid);
  50. #define pid_EESIZE 5 // 5 bytes of eeprom
  51. #endif // _pid_H_