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:
Add support for other models
If none of the existing models fit your use case, you can create a modular resource to add support for it.
Model | Description |
---|---|
gpio | Standard brushed or brushless DC motor |
Add support for other models
If none of the existing models fit your use case, you can create a modular resource to add support for it.
viam-micro-server
works differently from the RDK, so creating modular resources for it is different.
Refer to the Micro-RDK Module Template on GitHub for information on how to create custom resources for your viam-micro-server
machine.
You will need to recompile and flash your ESP32 yourself instead of using Viam’s prebuilt binary and installer.
API
The motor API supports the following methods:
The motor component supports the following methods:
Method Name | Description | viam-micro-server Support |
---|---|---|
SetPower | Set the portion of max power to send to the motor (between -1 and 1 ). | |
SetRPM | Spin 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. | |
GoFor | Spin the motor the specified number of revolutions at specified revolutions per minute. | |
GoTo | Turn the motor to a specified position (in terms of revolutions from home/zero) at a specified speed in revolutions per minute (RPM). | |
ResetZeroPosition | Set the current position (modified by offset ) to be the new zero (home) position. | |
GetPosition | Report the position of the motor based on its encoder. | |
GetProperties | Report a dictionary mapping optional properties to whether it is supported by this motor. | |
IsPowered | Return 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 ). | |
IsMoving | Return whether the motor is actively moving (or attempting to move) under its own power. | |
Stop | Cut the power to the motor immediately, without any gradual step down. | |
Reconfigure | Reconfigure this resource. | |
GetResourceName | Get the ResourceName for this motor with the given name. | |
Close | Safely 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:
Was this page helpful?
Glad to hear it! If you have any other feedback please let us know:
We're sorry about that. To help us improve, please tell us what we can do better:
Thank you!