Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOCS-1515, DOCS-3771: Add generic and DoCommand guidance #4134

Merged
merged 1 commit into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified assets/components/generic/generic-control.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions docs/dev/reference/apis/components/generic.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ aliases:

The generic API allows you to give commands to your [generic components](/operate/reference/components/generic/) for running model-specific commands using [`DoCommand`](/dev/reference/apis/components/generic/#docommand).

{{% alert title="Example usage" color="tip" %}}

See [Deploy control logic](/manage/software/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" >}}
Expand Down
46 changes: 41 additions & 5 deletions docs/manage/software/control-logic.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ When your new model gets added to your machine, its `reconfigure()` method gets
If you want your control logic to run in a loop in the background, you can start this loop here.
Be sure to also implement logic to handle subsequent calls to the reconfigure method gracefully.

For example, in Python, start your logic in the `reconfigure()` method of <FILE>src/main.py</FILE>:
For example, in Python, start your logic in the `reconfigure()` method of <FILE>src/models/control_logic.py</FILE>:

```python {class="line-numbers linkable-line-numbers" data-line="20-28"}
# Add these imports
Expand Down Expand Up @@ -158,12 +158,10 @@ For complete examples that implement control logic, see:

Once you have implemented your control logic, commit and push your changes to a GitHub repository.

If you are not using GitHub, see [Upload your module](/operate/get-started/other-hardware/#upload-your-module) and [Update an existing module](/operate/get-started/other-hardware/manage-modules/#update-automatically) for more information on alternatives.

Follow the steps in [Upload your module](/operate/get-started/other-hardware/#upload-your-module) using cloud build.
When you create a release, your module will be built, packaged and pushed to the Viam Registry.

Then [create a new release](https://docs.github.com/en/repositories/releasing-projects-on-github) with a tag of the form `1.0.0`.
Your module will now be built, packaged and pushed to the Viam Registry.
If you are not using GitHub or cloud build, see [Upload your module](/operate/get-started/other-hardware/#upload-your-module) and [Update an existing module](/operate/get-started/other-hardware/manage-modules/#update-automatically) for more information on alternatives.

## Deploy your control logic

Expand All @@ -177,3 +175,41 @@ Your module will now be built, packaged and pushed to the Viam Registry.
1. Click **Save**.

Your control logic will now be added to your machine.

## Start and stop your control logic with Viam SDKs

You can start and stop your control logic with the Viam SDKs by calling `DoCommand()`.

For example, in Python, you can start and stop your control logic with the following code:

```python
# Start your control logic
await control_logic.do_command({"start": ""})

# Stop your control logic
await control_logic.do_command({"stop": ""})
```

## Start and stop your control logic with the Viam app

You can start and stop your control logic from your machine's **CONTROL** tab in the Viam app:

{{<imgproc src="/components/generic/generic-control.png" alt="The generic component in the test panel." resize="900x" style="width:500px" class="imgzoom shadow">}}<br>

1. To start your control logic, copy and paste the following command input:

```json {class="line-numbers linkable-line-numbers"}
{
"start": ""
}
```

To stop your control logic, use the following command input:

```json {class="line-numbers linkable-line-numbers"}
{
"stop": ""
}
```

2. Click **Execute** to call `DoCommand()` on your machine.
6 changes: 6 additions & 0 deletions docs/operate/reference/components/generic/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ If you want to use most of an existing API but need just a few other functions,

{{% /alert %}}

{{% alert title="Example usage" color="tip" %}}

See [Deploy control logic](/manage/software/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 %}}

## Configuration

To use a generic component, check whether one of the following models supports it.
Expand Down
6 changes: 4 additions & 2 deletions static/include/components/test-control/generic-control.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## Test the generic component

After you configure your generic component, open the generic's **TEST** panel on the **CONFIGURE** or [**CONTROL**](/manage/troubleshoot/teleoperate/default-interface/#viam-app) tabs.
After you configure your generic component, open the generic's panel on the [**CONTROL**](/manage/troubleshoot/teleoperate/default-interface/#viam-app) tab.
Use the card to send arbitrary commands to the resource with [`DoCommand()`](/dev/reference/apis/components/generic/#docommand).

{{<imgproc src="/components/generic/generic-control.png" alt="The generic component in the test panel." resize="800x" style="width:500px" class="imgzoom">}}
{{<imgproc src="/components/generic/generic-control.png" alt="The generic component in control panel." resize="900x" style="width:500px" class="imgzoom shadow">}}

The example above works for interacting with the generic component model shown in [Deploy control logic](/manage/software/control-logic/), but other components require different commands depending on how `DoCommand()` is implemented.
Loading