Skip to content

Commit fdaf622

Browse files
authored
DOCS-1515, DOCS-3771: Add generic and DoCommand guidance (#4134)
1 parent 3359eae commit fdaf622

File tree

5 files changed

+57
-7
lines changed

5 files changed

+57
-7
lines changed
-30.1 KB
Loading

docs/dev/reference/apis/components/generic.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ aliases:
1414

1515
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).
1616

17+
{{% alert title="Example usage" color="tip" %}}
18+
19+
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.
20+
21+
{{% /alert %}}
22+
1723
The generic component supports the following method:
1824

1925
{{< readfile "/static/include/components/apis/generated/generic_component-table.md" >}}

docs/manage/software/control-logic.md

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ When your new model gets added to your machine, its `reconfigure()` method gets
6363
If you want your control logic to run in a loop in the background, you can start this loop here.
6464
Be sure to also implement logic to handle subsequent calls to the reconfigure method gracefully.
6565

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

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

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

161-
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.
162-
163161
Follow the steps in [Upload your module](/operate/get-started/other-hardware/#upload-your-module) using cloud build.
162+
When you create a release, your module will be built, packaged and pushed to the Viam Registry.
164163

165-
Then [create a new release](https://docs.github.com/en/repositories/releasing-projects-on-github) with a tag of the form `1.0.0`.
166-
Your module will now be built, packaged and pushed to the Viam Registry.
164+
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.
167165

168166
## Deploy your control logic
169167

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

179177
Your control logic will now be added to your machine.
178+
179+
## Start and stop your control logic with Viam SDKs
180+
181+
You can start and stop your control logic with the Viam SDKs by calling `DoCommand()`.
182+
183+
For example, in Python, you can start and stop your control logic with the following code:
184+
185+
```python
186+
# Start your control logic
187+
await control_logic.do_command({"start": ""})
188+
189+
# Stop your control logic
190+
await control_logic.do_command({"stop": ""})
191+
```
192+
193+
## Start and stop your control logic with the Viam app
194+
195+
You can start and stop your control logic from your machine's **CONTROL** tab in the Viam app:
196+
197+
{{<imgproc src="/components/generic/generic-control.png" alt="The generic component in the test panel." resize="900x" style="width:500px" class="imgzoom shadow">}}<br>
198+
199+
1. To start your control logic, copy and paste the following command input:
200+
201+
```json {class="line-numbers linkable-line-numbers"}
202+
{
203+
"start": ""
204+
}
205+
```
206+
207+
To stop your control logic, use the following command input:
208+
209+
```json {class="line-numbers linkable-line-numbers"}
210+
{
211+
"stop": ""
212+
}
213+
```
214+
215+
2. Click **Execute** to call `DoCommand()` on your machine.

docs/operate/reference/components/generic/_index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ If you want to use most of an existing API but need just a few other functions,
3939

4040
{{% /alert %}}
4141

42+
{{% alert title="Example usage" color="tip" %}}
43+
44+
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.
45+
46+
{{% /alert %}}
47+
4248
## Configuration
4349

4450
To use a generic component, check whether one of the following models supports it.
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
## Test the generic component
22

3-
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.
3+
After you configure your generic component, open the generic's panel on the [**CONTROL**](/manage/troubleshoot/teleoperate/default-interface/#viam-app) tab.
44
Use the card to send arbitrary commands to the resource with [`DoCommand()`](/dev/reference/apis/components/generic/#docommand).
55

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

0 commit comments

Comments
 (0)