Readonly
nameThe name of the resource.
Return the position of the motor relative to its zero position. Raise an error if position reporting is not supported.
const motor = new VIAM.MotorClient(machine, 'my_motor');
// Get the current position of the motor
const position = await motor.getPosition();
console.log('Position:', position);
For more information, see Motor API.
Return the motor's properties.
const motor = new VIAM.MotorClient(machine, 'my_motor');
// Report a dictionary mapping optional properties to whether it is supported by
// this motor
const properties = await motor.getProperties();
console.log('Properties:', properties);
For more information, see Motor API.
Turn the motor at a specified speed for either a specified number of revolutions or indefinitely. Raise an error if position reporting is not supported.
Speed in revolutions per minute.
Number of revolutions relative to the motor's starting position. If this value is 0, this will run the motor at the given rpm indefinitely. If this value is nonzero, this will block until the number of revolutions has been completed or another operation comes in.
const motor = new VIAM.MotorClient(machine, 'my_motor');
// Turn the motor 7.2 revolutions at 60 RPM
await motor.goFor(60, 7.2);
For more information, see Motor API.
Move the motor to a specific position relative to its home position at a specified speed. Raise an error if position reporting is not supported.
Speed in revolutions per minute.
Number of revolutions relative to the motor's home position.
const motor = new VIAM.MotorClient(machine, 'my_motor');
// Turn the motor to 8.3 revolutions from home at 75 RPM
await motor.goTo(75, 8.3);
For more information, see Motor API.
Return true if the motor is in motion.
const motor = new VIAM.MotorClient(machine, 'my_motor');
// Check whether the motor is currently moving
const moving = await motor.isMoving();
console.log('Moving:', moving);
For more information, see Motor API.
Return true if the motor is on.
const motor = new VIAM.MotorClient(machine, 'my_motor');
// Check whether the motor is currently running
const [isPowered, powerPct] = await motor.isPowered();
console.log('Powered:', isPowered);
console.log('Power percentage:', powerPct);
For more information, see Motor API.
Set the current position of the motor as the new zero position, offset by a given position. Raise an error if position reporting is not supported.
Position from which to offset the current position.
const motor = new VIAM.MotorClient(machine, 'my_motor');
// Set the current position as the new home position with no offset
await motor.resetZeroPosition(0.0);
For more information, see Motor API.
Set the percentage of the motor's total power that should be employed.
A value between -1 and 1 where negative values indicate a backwards direction and positive values a forward direction.
const motor = new VIAM.MotorClient(machine, 'my_motor');
// Set the power to 40% forwards
await motor.setPower(0.4);
For more information, see Motor API.
Move the motor indefinitely at a specified speed. Raise an error if position reporting is not supported.
Speed in revolutions per minute.
const motor = new VIAM.MotorClient(machine, 'my_motor');
// Spin the motor at 75 RPM
await motor.setRPM(75);
For more information, see Motor API.
Turn the motor off.
const motor = new VIAM.MotorClient(machine, 'my_motor');
// Stop the motor
await motor.stop();
For more information, see Motor API.
A gRPC-web client for the Motor component.