BO.io.Stepper Class
Creates an interface to a Stepper motor. Use this object to set the direction and number of steps for the motor to rotate. See Breakout/examples/actuators/stepper_2wire.html, stepper_4wire.html, stepper_easydriver.html and stepper_simple.html for example applications.
Constructor
BO.io.Stepper
-
board
-
driverType.
-
numStepsPerRev
-
directionPin
-
stepPin
-
motorPin3
-
motorPin4
Parameters:
-
board
IOBoardA reference to the IOBoard instance that the stepper is attached to.
-
driverType.
NumberThe type of driver (
Stepper.DRIVER
,Stepper.DRIVER_HIGH_CURRENT
,Stepper.TWO_WIRE
, orStepper.FOUR_WIRE
). -
numStepsPerRev
NumberThe number of steps to make 1 revolution.
-
directionPin
PinIf dirver interface, the pin used to control the direction. If 2-wire or 4-wire interface, the 1st moter pin.
-
stepPin
PinIf dirver interface, the pin used to control the steps. If 2-wire or 4-wire interface, the 2nd moter pin.
-
motorPin3
Pin[optional] Only required for a 4-wire interface.
-
motorPin4
Pin[optional] Only required for a 4-wire interface.
Example:
var Stepper = BO.io.Stepper,
Event = JSUTILS.Event;
var stepper,
stepsPerRev = 200, // update this for your stepper
numSteps = stepsPerRev * 10, // 10 revolutions (+ CW, - CCW)
speed = 15.0, // rad/sec (RPM = speed * 9.55)
acceleration = 20.0, // rad/sec^2
deceleration = 20.0; // rad/sec^2
stepper = new Stepper(arduino,
Stepper.TWO_WIRE, // or Stepper.DRIVER or Stepper.FOUR_WIRE
stepsPerRev,
arduino.getDigitalPin(2),
arduino.getDigitalPin(3));
stepper.addEventListener(Event.COMPLETE, onStepperComplete);
// acceleration and deceleration parameters are optional
stepper.step(numSteps, speed, acceleration, deceleration);
function onStepperComplete(event) {
// each stepper is assigned a read-only id value when instantiated
console.log("stepper " + event.target.id + " sequence complete");
}
Item Index
Properties
- id
- Stepper.CLOCKWISE static
- Stepper.COUNTER_CLOCKWISE static
- Stepper.DRIVER static
- Stepper.DRIVER_HIGH_CURRENT static
- Stepper.FOUR_WIRE static
- Stepper.TWO_WIRE static
Methods
addEventListener
-
type
-
listener
Parameters:
-
type
StringThe event type
-
listener
FunctionThe function to be called when the event is fired
dispatchEvent
-
type
-
optionalParams
Parameters:
-
type
EventThe Event object.
-
optionalParams
ObjectOptional parameters passed as an object. return {boolean} True if dispatch is successful, false if not.
hasEventListener
-
type
Parameters:
-
type
StringThe event type return {boolean} True is listener exists for this type, false if not.
onSysExMessage
()
private
Listen for stepping complete event
removeEventListener
-
type
-
listener
Parameters:
-
type
StringThe event type
-
listener
FunctionThe function to be called when the event is fired
step
-
numSteps
-
speed
-
accel
-
decel
Move the stepper a given number of steps at the specified speed (rad/sec), acceleration (rad/sec^2) and deceleration (rad/sec^2). The accel and decel parameters are optional but if using, both values must be passed to the function.
Parameters:
-
numSteps
NumberThe number ofsteps to move the motor (max = +/-2097151 (21 bits)). Positive value is clockwise, negative value is counter clockwise.
-
speed
NumberMax speed in rad/sec (1 rad/sec = 9.549 RPM) (max precision of 2 decimal places)
-
accel
Number[optional] Acceleration in rad/sec^2 (max precision of 2 decimal places)
-
decel
Number[optional] Deceleration in rad/sec^2 (max precision of 2 decimal places)
Properties
id
Number
[read-only] The id of the Stepper object instance. Each stepper motor is given a unique id upon initialization.
Stepper.CLOCKWISE
Unknown
static
Stepper.COUNTER_CLOCKWISE
Unknown
static
Stepper.DRIVER
Unknown
static
Uses 1 microsecond delay between steps
Stepper.DRIVER_HIGH_CURRENT
Unknown
static
Uses 2 microsecond delay between steps