title | linkTitle | weight | type | description | icon | images | date | aliases | ||
---|---|---|---|---|---|---|---|---|---|---|
Control your generic component with the generic API |
Generic |
70 |
docs |
Give commands for running custom model-specific commands using DoCommand on your generic components. |
true |
|
2022-01-01 |
|
The generic API allows you to give commands to your generic components for running model-specific commands using DoCommand
.
{{% alert title="Example usage" color="tip" %}}
See Deploy control logic for an example of how to use the generic component API, including how to call DoCommand()
from the Viam SDKs or from the Viam app.
{{% /alert %}}
The generic component supports the following method:
{{< readfile "/static/include/components/apis/generated/generic_component-table.md" >}}
To get started using Viam's SDKs to connect to and control your generic component and the rest of your machine, go to your machine's page on the Viam app, Navigate to the CONNECT tab's Code sample page, select your preferred programming language, and copy the sample code.
{{% snippet "show-secret.md" %}}
When executed, this sample code will create a connection to your machine as a client.
Then control your machine programmatically by getting your generic
component from the machine with FromRobot
and adding API method calls, as shown in the following examples.
The following examples assume you have a board called "my_board" configured as a component of your machine.
If your board has a different name, change the name
in the code.
Import the generic component package for the SDK you are using:
{{< tabs >}} {{% tab name="Python" %}}
from viam.components.generic import Generic
{{% /tab %}} {{% tab name="Go" %}}
import (
"go.viam.com/rdk/components/generic"
)
{{% /tab %}} {{% tab name="C++" %}}
#include <viam/sdk/components/generic/generic.hpp>
{{% /tab %}} {{< /tabs >}}
{{< readfile "/static/include/components/apis/generated/generic_component.md" >}}