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