Arduino Project Libraries  0.00
Stock and random Arduino Libraries
MultiStepper Class Reference

Operate multiple AccelSteppers in a co-ordinated fashion. More...

#include <MultiStepper.h>

Collaboration diagram for MultiStepper:
Collaboration graph

Public Member Functions

 MultiStepper ()
 Constructor. More...
 
boolean addStepper (AccelStepper &stepper)
 Add a stepper to the set of managed steppers There is an upper limit of MULTISTEPPER_MAX_STEPPERS = 10 to the number of steppers that can be managed. More...
 
void moveTo (long absolute[])
 Set the target positions of all managed steppers according to a coordinate array. New speeds will be computed for each stepper so they will all arrive at their respective targets at very close to the same time. More...
 
boolean run ()
 Calls runSpeed() on all the managed steppers that have not acheived their target position. More...
 
void runSpeedToPosition ()
 Runs all managed steppers until they acheived their target position. Blocks until all that position is acheived. If you dont want blocking consider using run() instead. More...
 

Private Attributes

AccelStepper_steppers [MULTISTEPPER_MAX_STEPPERS]
 Array of pointers to the steppers we are controlling. Fills from 0 onwards. More...
 
uint8_t _num_steppers
 Number of steppers we are controlling and the number of steppers in _steppers[]. More...
 

Detailed Description

Operate multiple AccelSteppers in a co-ordinated fashion.

This class can manage multiple AccelSteppers (up to MULTISTEPPER_MAX_STEPPERS = 10), and cause them all to move to selected positions at such a (constant) speed that they all arrive at their target position at the same time. This can be used to support devices with multiple steppers on say multiple axes to cause linear diagonal motion. Suitable for use with X-Y plotters, flatbeds, 3D printers etc to get linear straight line movement between arbitrary 2d (or 3d or ...) positions.

Caution: only constant speed stepper motion is supported: acceleration and deceleration is not supported All the steppers managed by MultiStepper will step at a constant speed to their target (albeit perhaps different speeds for each stepper).

Definition at line 33 of file MultiStepper.h.

Constructor & Destructor Documentation

◆ MultiStepper()

MultiStepper::MultiStepper ( )

Constructor.

Definition at line 9 of file MultiStepper.cpp.

References MultiStepper().

Referenced by MultiStepper().

10  : _num_steppers(0)
11 {
12 }
uint8_t _num_steppers
Number of steppers we are controlling and the number of steppers in _steppers[].
Definition: MultiStepper.h:71
Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ addStepper()

boolean MultiStepper::addStepper ( AccelStepper stepper)

Add a stepper to the set of managed steppers There is an upper limit of MULTISTEPPER_MAX_STEPPERS = 10 to the number of steppers that can be managed.

Parameters
[in]stepperReference to a stepper to add to the managed list
Returns
true if successful. false if the number of managed steppers would exceed MULTISTEPPER_MAX_STEPPERS

Definition at line 14 of file MultiStepper.cpp.

15 {
17  return false; // No room for more
18  _steppers[_num_steppers++] = &stepper;
19  return true;
20 }
AccelStepper * _steppers[MULTISTEPPER_MAX_STEPPERS]
Array of pointers to the steppers we are controlling. Fills from 0 onwards.
Definition: MultiStepper.h:67
#define MULTISTEPPER_MAX_STEPPERS
Definition: MultiStepper.h:14
uint8_t _num_steppers
Number of steppers we are controlling and the number of steppers in _steppers[].
Definition: MultiStepper.h:71

◆ moveTo()

void MultiStepper::moveTo ( long  absolute[])

Set the target positions of all managed steppers according to a coordinate array. New speeds will be computed for each stepper so they will all arrive at their respective targets at very close to the same time.

Parameters
[in]absoluteAn array of desired absolute stepper positions. absolute[0] will be used to set the absolute position of the first stepper added by addStepper() etc. The array must be at least as long as the number of steppers that have been added by addStepper, else results are undefined.

Definition at line 22 of file MultiStepper.cpp.

23 {
24  // First find the stepper that will take the longest time to move
25  float longestTime = 0.0;
26 
27  uint8_t i;
28  for (i = 0; i < _num_steppers; i++)
29  {
30  long thisDistance = absolute[i] - _steppers[i]->currentPosition();
31  float thisTime = abs(thisDistance) / _steppers[i]->maxSpeed();
32 
33  if (thisTime > longestTime)
34  longestTime = thisTime;
35  }
36 
37  if (longestTime > 0.0)
38  {
39  // Now work out a new max speed for each stepper so they will all
40  // arrived at the same time of longestTime
41  for (i = 0; i < _num_steppers; i++)
42  {
43  long thisDistance = absolute[i] - _steppers[i]->currentPosition();
44  float thisSpeed = thisDistance / longestTime;
45  _steppers[i]->moveTo(absolute[i]); // New target position (resets speed)
46  _steppers[i]->setSpeed(thisSpeed); // New speed
47  }
48  }
49 }
AccelStepper * _steppers[MULTISTEPPER_MAX_STEPPERS]
Array of pointers to the steppers we are controlling. Fills from 0 onwards.
Definition: MultiStepper.h:67
long currentPosition()
The currently motor position.
uint8_t _num_steppers
Number of steppers we are controlling and the number of steppers in _steppers[].
Definition: MultiStepper.h:71
float maxSpeed()
returns the maximum speed configured for this stepper that was previously set by setMaxSpeed(); ...
void setSpeed(float speed)
Sets the desired constant speed for use with runSpeed().
void moveTo(long absolute)
Set the target position. The run() function will try to move the motor (at most one step per call) fr...

◆ run()

boolean MultiStepper::run ( )

Calls runSpeed() on all the managed steppers that have not acheived their target position.

Returns
true if any stepper is still in the process of running to its target position.

Definition at line 52 of file MultiStepper.cpp.

53 {
54  uint8_t i;
55  boolean ret = false;
56  for (i = 0; i < _num_steppers; i++)
57  {
58  if ( _steppers[i]->distanceToGo() != 0)
59  {
60  _steppers[i]->runSpeed();
61  ret = true;
62  }
63  }
64  return ret;
65 }
AccelStepper * _steppers[MULTISTEPPER_MAX_STEPPERS]
Array of pointers to the steppers we are controlling. Fills from 0 onwards.
Definition: MultiStepper.h:67
uint8_t _num_steppers
Number of steppers we are controlling and the number of steppers in _steppers[].
Definition: MultiStepper.h:71
boolean runSpeed()
Poll the motor and step it if a step is due, implementing a constant speed as set by the most recent ...

◆ runSpeedToPosition()

void MultiStepper::runSpeedToPosition ( )

Runs all managed steppers until they acheived their target position. Blocks until all that position is acheived. If you dont want blocking consider using run() instead.

Definition at line 68 of file MultiStepper.cpp.

69 {
70  while (run())
71  ;
72 }
boolean run()
Calls runSpeed() on all the managed steppers that have not acheived their target position.

Field Documentation

◆ _num_steppers

uint8_t MultiStepper::_num_steppers
private

Number of steppers we are controlling and the number of steppers in _steppers[].

Definition at line 71 of file MultiStepper.h.

◆ _steppers

AccelStepper* MultiStepper::_steppers[MULTISTEPPER_MAX_STEPPERS]
private

Array of pointers to the steppers we are controlling. Fills from 0 onwards.

Definition at line 67 of file MultiStepper.h.


The documentation for this class was generated from the following files: