diff --git a/assets/components/generic/generic-control.png b/assets/components/generic/generic-control.png index f4ee690bcd..7fc33c1203 100644 Binary files a/assets/components/generic/generic-control.png and b/assets/components/generic/generic-control.png differ diff --git a/docs/dev/reference/apis/components/generic.md b/docs/dev/reference/apis/components/generic.md index 705ebc3e36..2fc4fc9d3e 100644 --- a/docs/dev/reference/apis/components/generic.md +++ b/docs/dev/reference/apis/components/generic.md @@ -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" >}} diff --git a/docs/manage/software/control-logic.md b/docs/manage/software/control-logic.md index 3dfe21f33e..4c9f2620ac 100644 --- a/docs/manage/software/control-logic.md +++ b/docs/manage/software/control-logic.md @@ -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 src/main.py: +For example, in Python, start your logic in the `reconfigure()` method of src/models/control_logic.py: ```python {class="line-numbers linkable-line-numbers" data-line="20-28"} # Add these imports @@ -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 @@ -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: + +{{}}
+ +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. diff --git a/docs/operate/reference/components/generic/_index.md b/docs/operate/reference/components/generic/_index.md index ff0f4d9e21..9c9f5c8737 100644 --- a/docs/operate/reference/components/generic/_index.md +++ b/docs/operate/reference/components/generic/_index.md @@ -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. diff --git a/static/include/components/test-control/generic-control.md b/static/include/components/test-control/generic-control.md index 8fcdb797dc..bcac65243a 100644 --- a/static/include/components/test-control/generic-control.md +++ b/static/include/components/test-control/generic-control.md @@ -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). -{{}} \ No newline at end of file +{{}} + +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.