StepControl - Class Reference
#include "TeensyStep.h"

Objects of the StepControl class are used to move up to 10 motors to target positions in sync. The synchronization is done by Bresenham’s algorithm and it is kept during acceleration and deceleration phases and all motors will reach their target positions at the same time.

Construction

StepControl(unsigned stepPulseWidth, unsigned speedUpdatePeriod)

Constructs a StepControl object with selectable values for the step pulse width (µs) and the speed update period (µs). During acceleration and deceleration, the controller updates the motor speed periodically. The period of this updates is set by the speedUpdatePeriod parameter (500µs to 20000µs). Smaller values increase the processor load but lead to a smoother acceleration. A value of 5000µs is sufficient for most of real life applications.

StepControl()

Constructs a StepControl object with default parameters for stepPulseWidth (5µs) and speedUpdatePeriod (5ms)

Moving Motors to Targets

void moveAsync(Stepper& s1 [, ...Stepper& sN])

Accepts up to N=10 references to stepper objects and starts moving them to their targets in sync. I.e. all motors will reach their targets at the same time. The function returns immediately after starting the movement (non blocking).

   StepControl controller;
   Stepper s1(1,2), s2(3,4);
   controller.moveAsync(s1,s2);        
void moveAsync(Stepper* stepperArray[N])

Accepts an array of up to N=10 pointers to stepper objects and starts moving them to their targets in sync. I.e. all motors will reach their targets at the same time. The function returns immediately after starting the movement (non blocking).

   StepControl controller;
   Stepper* stArray[] = { new Stepper(1,2), new Stepper(3,4), newStepper(5,6)};
   
   controller.moveAsync(stArray);        
void move(Stepper& s1 [, ...Stepper& sN])

Accepts up to N=10 references to stepper objects and starts moving them to their targets in sync. I.e. all motors will reach their targets at the same time. The function waits until the movement is finished (blocking).

   StepControl controller;
   Stepper s1(1,2), s2(3,4);
   controller.move(s1,s2);  // returns after the motors reached their targets   
void move(Stepper* stepperArray[N])

Accepts an array of up to N=10 pointers to stepper objects and starts moving them to their targets in sync. I.e. all motors will reach their targets at the same time. The function waits until the movement is finished (blocking).

   StepControl controller;
   Stepper* stArray[] = { new Stepper(1,2), new Stepper(3,4), newStepper(5,6)};
   
   controller.move(stArray); // returns after the motors reached their targets
int32_t getCurrentSpeed()

Returns the current speed of the controlled motor. If more than one motor is controlled by the controller it returns the current speed of the leading (fastest) motor. The speed of the other motors is always a fixed ratio to the speed of the leading motor.

Stopping Motors

void stopAsync()

Decelerates the controlled motors to a stop. This function returns immediately after starting the stop sequence (non blocking).

void stop()

Decelerates the controlled motors to a stop and waits until the motors are stopped (blocking function).

void emergencyStop()

Immediately stops the controlled motors. Use this only in emergency since, depending on motor speed this will probably lead to step losses. A homing sequence is highly recommended after a call to emergencyStop().

 controller.moveAsync(s1,s2);
 
 delay(1000);
 controller.stopAsync();     // starts deceleration
 
 delay(50); 
 controller.emergencyStop(); // immediately stops the motor without decelleration