ramp.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*********************************************************************
  2. *
  3. * Ramp library for Fraise pic18f device
  4. *
  5. * Ramp generator with destination position, maxspeed/acceleration
  6. *********************************************************************
  7. * Author Date Comment
  8. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  9. * Antoine Rousseau dec 2012 Original.
  10. ********************************************************************/
  11. /*
  12. # This program is free software; you can redistribute it and/or
  13. # modify it under the terms of the GNU General Public License
  14. # as published by the Free Software Foundation; either version 2
  15. # of the License, or (at your option) any later version.
  16. #
  17. # This program is distributed in the hope that it will be useful,
  18. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. # GNU General Public License for more details.
  21. # You should have received a copy of the GNU General Public License
  22. # along with this program; if not, write to the Free Software
  23. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  24. # MA 02110-1301, USA.
  25. */
  26. #ifndef _ramp_H_
  27. #define _ramp_H_
  28. #include <fruit.h>
  29. #ifndef RAMP_UINCPOW
  30. #define RAMP_UINCPOW 10 // 1 increment = 1024 milli-increments (mincs) = 1024x1024 micro-increments (uincs)
  31. #endif
  32. #ifndef RAMP_MAXERROR
  33. #define RAMP_MAXERROR 3 //
  34. #endif
  35. typedef struct {
  36. int destPos; //Destination position, in incs
  37. long int currentPos; //Current position in mincs
  38. int maxSpeed; //Maximum absolute speed allowed to ramp generator, in minc/ms
  39. long int speed; //Consign speed computed by ramp generator, in uinc/ms
  40. int maxAccel ; //Maximum acceleration allowed to ramp generator, in uinc/ms/ms
  41. //ex: RAMP_UINCPOW=10
  42. // maxAccel=1 -> 1 uinc/ms/ms : during 1s, speed will be increased of 1000/1024 minc/ms :
  43. // it will take about 1s for speed to increase of 1 maxSpeed unity.
  44. // maxAccel=1024 -> 1uinc/ms/ms:1000(uinc/ms)/s: 1.024s to reach speed 1024 (=1 inc/s)
  45. // max 65535-> about 1/16s to reach speed 1024
  46. int maxDecel ; //Maximum acceleration allowed to trajectory generator, in uinc/ms/ms
  47. } t_ramp ;
  48. void rampInit(t_ramp *Ramp);
  49. void rampGoto(t_ramp *Ramp,int pos);
  50. void rampSetPos(t_ramp *Ramp,int pos);
  51. #define rampGetPos(Ramp) ((Ramp)->currentPos>>(RAMP_UINCPOW))
  52. void rampCompute(t_ramp *Ramp);
  53. void rampInput(t_ramp *Ramp);
  54. void rampDeclareEE(t_ramp *Ramp);
  55. #define RAMP_EESIZE 6 // 4 bytes of eeprom
  56. #endif // _PID_H_