Add Custom Components as Remotes of Your Robot
Caution
Modular resources are the preferred method of creating custom resource implementations for SDKs with module support unless you are hosting viam-server
on a non-Linux system or have another issue with compilation.
Instructions on creating and using modular resources are available here.
If a type or model of component you are working with is not built-in to the Viam RDK, you can use a Viam SDK to code a custom resource implementation, host it on a server, and add it as a remote of your robot.
Once you have coded your custom component and configured the remote servers, you can control and monitor your component with the Viam SDKs, like any other component.
For example, you may have a robotic arm that is not one of the models supported by Viam’s arm component, and you want to integrate it with Viam. To use is with Viam, you can create a custom component and register the new arm model with a Viam SDK. Then you can control it as part of your robot with the same API methods available for arm models built-in to the RDK.
This example is available in the Python SDK documentation.
Instructions
To add a custom resource as a remote:
- Code a new model of a built-in resource type. You can do this by creating a new interface that implements required methods. The new model must implement any functions of the built-in resource type marked as required in its RDK API definition.
- Register the custom component on a new gRPC server instance and start the server.
- Add the server as a remote of your robot.
- Configure a command to launch this remote server as a process of your robot to make sure the remote server is always running alongside the rest of your robot.
Each remote server can host one or many custom components.
- Code a new model of a built-in resource type.
You can do this by subclassing a built in resource type like
sensor
orarm
. The new model must implement any functions of the built-in resource type marked as required in its RDK API definition. - Register the custom component on a new gRPC server instance and start the server.
You can do this with the
viam.rpc
library by creating a newrpc.server.Server
instance. - Add the server as a remote of your robot.
- Configure a command to launch this remote server as a process of your robot to make sure the remote server is always running alongside the rest of your robot.
Each remote server can host one or many custom components.
Note
You must define all functions belonging to a built-in resource type if defining a new model. Otherwise, the class won’t instantiate.
- If you are using the Python SDK, raise an
NotImplementedError()
in the body of functions you do not want to implement or putpass
. - If you are using the Go SDK, return
errUnimplemented
. - Additionally, return any values designated in the function’s return signature, typed correctly.
The following tutorials also explain how to add custom components as remotes:
Have questions, or want to meet other people working on robots? Join our Community Discord.
Was this page helpful?
Glad to hear it! If there is anything we could be doing better, please create an issue.
We're sorry about that. If you'd like to talk to us for help, please join the Community Discord. To ensure we know what's wrong with this page, you can also open an issue.