Motor Component

The motor component provides an API for operating a motor or getting its current status.

If you have a device that converts electricity into rotary motion, such as a brushed DC motor, a brushless DC motor, or a stepper motor, configure it as a motor component.

If you have a hobby servo, configure it as a servo component instead.

Available models

To use a motor, you need to add it to your machine’s configuration. Go to your machine’s CONFIGURE page, and add a model that supports your motor.

Because your machine controls your motor using a motor driver, you technically need to select a motor model that supports your motor driver rather than the motor itself.

The following list shows the available motor models. For additional configuration information, click on the model name:

Model
Description
ModelDescription
gpioStandard brushed or brushless DC motor

API

The motor API supports the following methods:

The motor component supports the following methods:

Method NameDescriptionviam-micro-server Support
SetPowerSet the portion of max power to send to the motor (between -1 and 1).

SetRPMSpin the motor indefinitely at the specified speed, in revolutions per minute. If rpm is positive, the motor will spin forwards, and if rpm is negative, the motor will spin backwards.

GoForSpin the motor the specified number of revolutions at specified revolutions per minute.

GoToTurn the motor to a specified position (in terms of revolutions from home/zero) at a specified speed in revolutions per minute (RPM).

ResetZeroPositionSet the current position (modified by offset) to be the new zero (home) position.

GetPositionReport the position of the motor based on its encoder.

GetPropertiesReport a dictionary mapping optional properties to whether it is supported by this motor.

IsPoweredReturn whether or not the motor is currently running, and the portion of max power (between 0 and 1; if the motor is off the power will be 0).

IsMovingReturn whether the motor is actively moving (or attempting to move) under its own power.

StopCut the power to the motor immediately, without any gradual step down.

ReconfigureReconfigure this resource.

GetResourceNameGet the ResourceName for this motor with the given name.

CloseSafely shut down the resource and prevent further use.

Troubleshooting

You can find additional assistance in the Troubleshooting section.

You can also ask questions on the Viam Community Slack and we will be happy to help.

Next steps

For general configuration and development info, see: