-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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.
<td>An array containing the pin addresses for the 3 supported types</td> <td>yes *</td> </tr> <tr> <td>stepsPerRev</td> <td>Number</td> <td>#</td> <td>Steps per revolution. This will differ by motor, refer to motor specs for value</td> <td>yes</td> </tr> <tr> <td>type</td> <td>constant</td> <td>DRIVER, TWO_WIRE, FOUR_WIRE</td> <td>five.Stepper.TYPE.DRIVER, five.Stepper.TYPE.TWO_WIRE, five.Stepper.TYPE.FOUR_WIRE</td> <td>yes</td> </tr> <tr> <td>rpm</td> <td>Number</td> <td>Per device</td> <td>Revolutions per minute, used to calculate speed. Defaluts to 180</td> <td>no</td> </tr> <tr> <td>direction</td> <td>Number</td> <td>-1, 0, 1</td> <td> Counter-Clockwise: 0, Clockwise: 1, Default: -1 - five.Stepper.DIRECTION.CW - five.Stepper.DIRECTION.CCW </td> <td>no</td> </tr>
Property Type Value(s) Description Required pins Object * DRIVER:
`{ step, dir }`
TWO_WIRE:
`{ m1, m2 }`
FOUR_WIRE:
`{ m1, m2, m3, m4 }`
</td> <td>An object containing the named pin addresses for the 3 supported types</td> <td>yes *</td> </tr> <tr> <td>pins</td> <td>Array *</td> <td>
DRIVER:
[ step, dir ]
TWO_WIRE:[ m1, m2 ]
FOUR_WIRE:[ m1, m2, m3, m4 ]
- The pins property is required, but can be EITHER an object or an array.
{
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:
}
// Create a stepper motor
//
// - Step on pin 11
// - Direction on pin 12
// - Steps per revolution: 200
// - Uses a Driver board
//
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
}
});
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 ]
});
var board = new five.Board();
board.on("ready", function() {
var k = 0;
var stepper = new five.Stepper({
type: five.Stepper.TYPE.DRIVER,
stepsPerRev: 200,
pins: [11, 12]
});
stepper.rpm(180).ccw().step(2000, function() {
console.log("done");
});
});
-
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!"); });
-
speed() Get the speed.
-
speed(value) Set the speed in
0.01 * rad/s
.// 180 rpm stepper.speed(0.18850).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 |