Generic Component
Generic components provide an API for running model-specific commands using DoCommand
.
If you have a physical device or a program that does not fit into any of the provided components APIs, use a generic component.
For example, if you want to use an LED display, you need functionality that isn’t currently exposed in an existing API. Instead, you can use the generic component API to add support for your unique type of hardware, like LED displays, to your machine.
You should use the generic component for modular resources that represent a unique type of hardware. If you are adding new high-level software functionality, rather than supporting new hardware components, use the generic service instead.
Important
The generic component API only supports the DoCommand
method.
If you use the generic subtype, your module needs to define any and all component functionality and pass it through DoCommand
.
Whenever possible, it is best to use an existing component API instead of generic so that you do not have to replicate code.
If you want to use most of an existing API but need just a few other functions, try using the DoCommand
endpoint and extra parameters to add custom functionality to an existing subtype, instead of using the generic component.
Configuration
To use a generic component, check whether one of the following models supports it.
For 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.
If your viam-micro-server
machine includes a resource that isn’t a base, board,encoder, movement sensor, motor, or servo, you can create a modular resource to add support for it as a custom model of the generic subtype.
Important
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 generic API supports the following methods:
Method Name | Description | viam-micro-server Support |
---|---|---|
DoCommand | Execute model-specific commands. | |
GetResourceName | Get the ResourceName for this generic component with the given name. | |
Close | Safely shut down the resource and prevent further use. |
Troubleshooting
If your generic component is not working as expected, follow these steps:
- Check your machine logs on the LOGS tab to check for errors.
- Review your generic component model’s documentation to ensure you have configured all required attributes.
- Click on the TEST panel on the CONFIGURE or CONTROL tab and test if you can use the generic component 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!