-
Notifications
You must be signed in to change notification settings - Fork 0
Stepper
The Stepper
class constructs objects that represent a single stepper motor attached to the physical board. This class is new and should be considered unstable.
In order to use the Stepper
class, your board must be flashed with AdvancedFirmata
, which is available here: https://github.com/soundanalogous/AdvancedFirmata
Stepper motors generally require significantly involved hardware setup (that is, more then just plugging a single lead into a pin).
- options An object of property parameters.
Property Name | Type | Value(s) | Description | Required |
---|---|---|---|---|
pins | Object * |
```js
Type: DRIVER
{ step, dir }
```
|
var stepper = new five.Stepper({ type: five.Stepper.TYPE.DRIVER, stepsPerRev: 200, pins: [ 11, 12 ] });
// Is the same as...
var stepper = five.Stepper({ type: five.Stepper.TYPE.DRIVER stepsPerRev: 200, pins: { step: 11 dir: 12 } });
* The **pins** property is required, but can be EITHER an object or an array.
### Shape
{ id: A user definable id value. Defaults to a generated uid pins: Object containing the pin addresses for the Stepper rpm: Revolutions per minute, used to calculate speed. Defaluts to 180 direction: speed: accel: decel: }
### Usage
```js
var stepper = five.Stepper({
type: five.Stepper.TYPE.DRIVER
stepsPerRev: number,
pins: {
step: number
dir: number
}
});
var stepper = five.Stepper({
type: five.Stepper.TYPE.DRIVER
stepsPerRev: number,
pins: [ step, dir ]
});
var stepper = five.Stepper({
type: five.Stepper.TYPE.TWO_WIRE
stepsPerRev: number,
pins: {
motor1: number,
motor2: number
}
});
var stepper = five.Stepper({
type: five.Stepper.TYPE.TWO_WIRE
stepsPerRev: number,
pins: [ motor1, motor2 ]
});
var stepper = five.Stepper({
type: five.Stepper.TYPE.FOUR_WIRE
stepsPerRev: number,
pins: {
motor1: number,
motor2: number,
motor3: number,
motor4: number
}
});
var stepper = five.Stepper({
type: five.Stepper.TYPE.FOUR_WIRE
stepsPerRev: number,
pins: [ motor1, motor2, motor3, motor4 ]
});
- step(stepsOrOpts, callback) Move a stepper motor.
// stepsOrOpts
{
steps: number of steps to move
direction: 1, 0 (CCW, CW)
rpm: Revolutions per minute. Defaults to 180
accel: Number of steps to accelerate
decel: Number of steps to decelerate
}
//
// - 10 full revolutions
// - Clockwise
// - Accelerate over the first 1600 steps
// - Decelerate over the last 1600 steps
//
stepper.step({ steps: 2000, direction: 1, accel: 1600, decel: 1600 }, function() {
console.log( "Done stepping!" );
});
- rpm() Get the rpm.
- rpm(value) Set the rpm.
stepper.rpm(180).step(2000, function() {
console.log( "Done stepping!" );
});
- direction() Get the direction.
- direction(value) Set the direction.
stepper.direction(1).step(2000, function() {
console.log( "Done stepping!" );
});
stepper.direction(0).step(2000, function() {
console.log( "Done stepping!" );
});
Or...
stepper.direction(five.Stepper.DIRECTION.CW).step(2000, function() {
console.log( "Done stepping!" );
});
stepper.direction(five.Stepper.DIRECTION.CCW).step(2000, function() {
console.log( "Done stepping!" );
});
- accel() Get the acceleration.
- accel(value) Set the acceleration.
stepper.accel(1600).step(2000, function() {
console.log( "Done stepping!" );
});
- decel() Get the deceleration.
- decel(value) Set the deceleration.
stepper.decel(1600).step(2000, function() {
console.log( "Done stepping!" );
});
- cw() Set the Stepper to move Clockwise.
stepper.cw().step(2000);
- ccw() Set the Stepper to move Counter-Clockwise.
stepper.ccw().step(2000);
Type | Value | Constant |
---|---|---|
DRIVER | 1 | Stepper.TYPE.DRIVER |
DRIVER | 2 | Stepper.TYPE.TWO_WIRE |
DRIVER | 4 | Stepper.TYPE.FOUR_WIRE |
State | Value | Constant |
---|---|---|
STOP | 0 | Stepper.RUNSTATE.STOP |
DRIVER | 1 | Stepper.RUNSTATE.ACCEL |
DRIVER | 2 | Stepper.RUNSTATE.DECEL |
DRIVER | 3 | Stepper.RUNSTATE.RUN |
Direction | Value | Constant |
---|---|---|
CCW | 0 | Stepper.DIRECTION.CCW |
CW | 1 | Stepper.DIRECTION.CW |