MultiStepper.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // MultiStepper.h
  2. #ifndef MultiStepper_h
  3. #define MultiStepper_h
  4. #include <stdlib.h>
  5. #if ARDUINO >= 100
  6. #include <Arduino.h>
  7. #else
  8. #include <WProgram.h>
  9. #include <wiring.h>
  10. #endif
  11. #define MULTISTEPPER_MAX_STEPPERS 10
  12. class AccelStepper;
  13. /////////////////////////////////////////////////////////////////////
  14. /// \class MultiStepper MultiStepper.h <MultiStepper.h>
  15. /// \brief Operate multiple AccelSteppers in a co-ordinated fashion
  16. ///
  17. /// This class can manage multiple AccelSteppers (up to MULTISTEPPER_MAX_STEPPERS = 10),
  18. /// and cause them all to move
  19. /// to selected positions at such a (constant) speed that they all arrive at their
  20. /// target position at the same time. This can be used to support devices with multiple steppers
  21. /// on say multiple axes to cause linear diagonal motion. Suitable for use with X-Y plotters, flatbeds,
  22. /// 3D printers etc
  23. /// to get linear straight line movement between arbitrary 2d (or 3d or ...) positions.
  24. ///
  25. /// Caution: only constant speed stepper motion is supported: acceleration and deceleration is not supported
  26. /// All the steppers managed by MultiStepper will step at a constant speed to their
  27. /// target (albeit perhaps different speeds for each stepper).
  28. class MultiStepper
  29. {
  30. public:
  31. /// Constructor
  32. MultiStepper();
  33. /// Add a stepper to the set of managed steppers
  34. /// There is an upper limit of MULTISTEPPER_MAX_STEPPERS = 10 to the number of steppers that can be managed
  35. /// \param[in] stepper Reference to a stepper to add to the managed list
  36. /// \return true if successful. false if the number of managed steppers would exceed MULTISTEPPER_MAX_STEPPERS
  37. boolean addStepper(AccelStepper& stepper);
  38. /// Set the target positions of all managed steppers
  39. /// according to a coordinate array.
  40. /// New speeds will be computed for each stepper so they will all arrive at their
  41. /// respective targets at very close to the same time.
  42. /// \param[in] absolute An array of desired absolute stepper positions. absolute[0] will be used to set
  43. /// the absolute position of the first stepper added by addStepper() etc. The array must be at least as long as
  44. /// the number of steppers that have been added by addStepper, else results are undefined.
  45. void moveTo(long absolute[]);
  46. /// Calls runSpeed() on all the managed steppers
  47. /// that have not acheived their target position.
  48. /// \return true if any stepper is still in the process of running to its target position.
  49. boolean run();
  50. /// Runs all managed steppers until they acheived their target position.
  51. /// Blocks until all that position is acheived. If you dont
  52. /// want blocking consider using run() instead.
  53. void runSpeedToPosition();
  54. private:
  55. /// Array of pointers to the steppers we are controlling.
  56. /// Fills from 0 onwards
  57. AccelStepper* _steppers[MULTISTEPPER_MAX_STEPPERS];
  58. /// Number of steppers we are controlling and the number
  59. /// of steppers in _steppers[]
  60. uint8_t _num_steppers;
  61. };
  62. /// @example MultiStepper.pde
  63. /// Use MultiStepper class to manage multiple steppers and make them all move to
  64. /// the same position at the same time for linear 2d (or 3d) motion.
  65. #endif