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.
Configuration
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 and its motor driver.
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:
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. | |
DoCommand | Execute model-specific commands that are not otherwise defined by the component API. | |
GetResourceName | Get the ResourceName for this motor with the given name. | |
Close | Safely shut down the resource and prevent further use. |
Troubleshooting
If your motor is not working as expected, follow these steps:
- Check your machine logs on the LOGS tab to check for errors.
- Review your motor model’s documentation to ensure you have configured all required attributes.
- Check that all wires are securely attached to the correct pins.
- Click on the TEST panel on the CONFIGURE or CONTROL tab and test if you can use the motor there.
If none of these steps work, reach out to us on the Community Discord 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!