Winder.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. #pragma once
  2. #include "TeensyStep.h"
  3. class Winder
  4. {
  5. public:
  6. Winder(Stepper &spindle, Stepper &feeder);
  7. void begin();
  8. Winder &setSpindleParams(unsigned stpPerRev, unsigned acceleration); // steps per spindle revolution & acceleration in stp/s^2
  9. Winder &setFeederParams(unsigned stpPerMM, unsigned acceleration); // steps to move the feeder 1mm, acceleration for pitch trimming
  10. void setSpindleSpeed(float rpm); // changes the spindle speed to the given rpm
  11. void setPitch(float pitch_in_mm); // changes the winder pitch to the given value
  12. void updateSpeeds();
  13. inline int getCurSpindleSpeed() { return spindleCtrl.isRunning() ? spindleCtrl.getCurrentSpeed() : 0; }
  14. inline int getCurFeederSpeed() { return feederCtrl.isRunning() ? feederCtrl.getCurrentSpeed() : 0; }
  15. inline float getCurPitch(){return (float)getCurFeederSpeed()/getCurSpindleSpeed()/pitchFactor; }
  16. protected:
  17. Stepper &spindle;
  18. Stepper &feeder;
  19. unsigned spindleStpPerRev, spindleAcc, feederStpPerMM, feederAcc;
  20. float pitchFactor;
  21. float targetSpindleSpeed, targetPitch;
  22. float oldSpindleSpeed, oldPitch;
  23. RotateControl feederCtrl, spindleCtrl;
  24. };