Servo Component
The servo component provides an API for controlling the angular position of a servo precisely or getting its current status.
If you have a physical “RC” or “hobby” servo motor with built-in potentiometer position sensors, configure it as a servo component.
If your motor is coupled with an encoder, not a potentiometer, for position feedback, you should configure it as an encoded motor instead.
Configuration
To use a hobby servo, you need to add it to your machine’s configuration.
Go to your machine’s CONFIGURE page, and add a model that supports your servo.
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 | A hobby servo. |
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 servo API supports the following methods:
Method Name | Description | viam-micro-server Support |
---|---|---|
Move | Move the servo to the desired angle in degrees. | |
GetPosition | Get the current set angle of the servo in degrees. | |
IsMoving | Returns whether the servo is actively moving (or attempting to move) under its own power. | |
Stop | Stop the servo from moving. | |
Reconfigure | Reconfigure this resource. | |
DoCommand | Execute model-specific commands that are not otherwise defined by the component API. | |
GetResourceName | Get the ResourceName for this servo with the given name. | |
Close | Safely shut down the resource and prevent further use. |
Troubleshooting
If your servo is not working as expected, follow these steps:
- Check your machine logs on the LOGS tab to check for errors.
- Review your servo model’s documentation to ensure you have configured all required attributes.
- Check that all wires are securely attached to the correct pins on the board.
- Click on the TEST panel on the CONFIGURE or CONTROL tab and test if you can use the servo 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!