You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/operate/modules/support-hardware/_index.md
+53-40Lines changed: 53 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,7 +48,7 @@ This page provides instructions for creating a module in Python or Go.
48
48
For C++ module examples, see the [C++ examples directory on GitHub](https://github.com/viamrobotics/viam-cpp-sdk/tree/main/src/viam/examples/).
49
49
If you want to create a module for use with a microcontroller, see [Modules for ESP32](/operate/modules/advanced/micro-module/).
50
50
51
-
**Example module:** With each step of thise guide, you have instruction for creating a {{< glossary_tooltip term_id="module" text="module" >}} which does two things:
51
+
**Example module:** With each step of this guide, you have instructions for creating a {{< glossary_tooltip term_id="module" text="module" >}} which does two things:
52
52
53
53
1. Gets an image from a configured path on your machine
54
54
2. Returns a random number
@@ -65,7 +65,7 @@ Authenticate your CLI session with Viam using one of the following options:
{{% expand "A running machine connected to Viam." %}}
68
+
{{% expand "A running machine connected to Viam" %}}
69
69
70
70
You can write a module without a machine, but to test your module you'll need a [machine](/operate/install/setup/).
71
71
@@ -75,7 +75,7 @@ You can write a module without a machine, but to test your module you'll need a
75
75
76
76
{{< expand "For Python developers: Use Python 3.11+" >}}
77
77
78
-
If you plan to write your module using Python, you need Python version 3.11 or newer installed on your computer to use the code generation tool in this guide.
78
+
If you plan to write your module using Python, you need Python 3.11 or newer installed on your computer to use the code generation tool in this guide.
79
79
80
80
You can check by running `python3 --version` or `python --version` in your terminal.
81
81
@@ -85,7 +85,7 @@ You can check by running `python3 --version` or `python --version` in your termi
85
85
86
86
While not required, we recommend starting by writing a test script to check that you can connect to and control your hardware from your computer, perhaps using the manufacturer's API or other low-level code.
87
87
88
-
**Example module:** For the example module the test script will open an image in the same folder and print a random number.
88
+
**Example module:** For the example module, the test script will open an image in the same directory and print a random number.
89
89
90
90
{{< tabs >}}
91
91
{{% tab name="Python" %}}
@@ -141,15 +141,15 @@ func main() {
141
141
142
142
## Choose an API
143
143
144
-
You can think of a module as a packaged wrapper around some script.
144
+
You can think of a module as a packaged wrapper around a script.
145
145
The module takes the functionality of the script and maps it to a standardized API for use within the Viam ecosystem.
146
146
147
147
Review the available [component APIs](/dev/reference/apis/#component-apis) and choose the one whose methods map most closely to the functionality you need.
148
148
149
149
If you need a method that is not in your chosen API, you can use the flexible `DoCommand` (which is built into all component APIs) to create custom commands.
150
150
See [Run control logic](/docs/operate/modules/support-hardware/) for more information.
151
151
152
-
**Example Module:** To choose the Viam [APIs](/dev/reference/apis/#component-apis)which make sense for your module, think about the functionality you want to implement.
152
+
**Example module:** To choose the Viam [APIs](/dev/reference/apis/#component-apis)that make sense for your module, think about the functionality you want to implement.
153
153
You need a way to return an image and you need a way to return a number.
154
154
155
155
If you look at the [camera API](/dev/reference/apis/components/camera/), you can see the `GetImage` method, which returns an image.
@@ -189,7 +189,7 @@ viam module generate
189
189
| Module name | Choose a name that describes the set of {{< glossary_tooltip term_id="resource" text="resources" >}} it supports. |
190
190
| Language | Choose the programming language for the module. The CLI supports `Python` and `Golang`. |
191
191
| Visibility | Choose `Private` to share only with your organization, or `Public` to share publicly with all organizations. If you are testing, choose `Private`. |
192
-
| Namespace/Organization ID | Navigate to your organization settings through the menu in upper right corner of the page. Find the **Public namespace** (or create one if you haven't already) and copy that string. If you use the organization ID, you must still create a public namespace first if you wish to share the module publicly. |
192
+
| Namespace/Organization ID | Navigate to your organization settings through the menu in the upper-right corner of the page. Find the **Public namespace** (or create one if you haven't already) and copy that string. If you use the organization ID, you must still create a public namespace first if you wish to share the module publicly. |
193
193
| Resource to add to the module (API) | The [component API](/dev/reference/apis/#component-apis) your module will implement. See [Choose an API](#choose-an-api) for more information. |
194
194
| Model name | Name your component model based on what it supports, for example, if it supports a model of ultrasonic sensor called "XYZ Sensor 1234" you could call your model `xyz_1234` or similar. Must be all-lowercase and use only alphanumeric characters (`a-z` and `0-9`), hyphens (`-`), and underscores (`_`). |
195
195
| Enable cloud build | If you select `Yes` (recommended) and push the generated files (including the <file>.github</file> folder) and create a release of the format `X.X.X`, the module will build for [all architectures specified in the meta.json build file](/operate/modules/advanced/metajson/). You can select `No` if you want to always build the module yourself before uploading it. For more information see [Update and manage modules](/operate/modules/advanced/manage-modules/). |
@@ -199,7 +199,7 @@ viam module generate
199
199
200
200
<br>
201
201
202
-
**Example module**: To build an example module that contains a camera model use the following command:
202
+
**Example module**: To build an example module that contains a camera model, use the following command:
203
203
204
204
{{< tabs >}}
205
205
{{% tab name="Python" %}}
@@ -228,8 +228,8 @@ You can add the model for the sensor in a later step in [Creating multiple model
228
228
{{% /tablestep %}}
229
229
{{% tablestep %}}
230
230
231
-
The generator creates a folder containing stub files for your modular component.
232
-
In the next section, you'll customize some of the generated files to support your sensor.
231
+
The generator creates a directory containing stub files for your modular component.
232
+
In the next section, you'll customize some of the generated files to support your camera.
233
233
234
234
**Example module**: For the example module, the file structure is:
235
235
@@ -297,9 +297,9 @@ Some of the code you generated is resource-specific.
297
297
298
298
If you have multiple modular resources that are related, you can put them all into the same module.
299
299
300
-
For convenience, we recommend running the module generator again from within the first module's directory, generating an unregistered module, and copying the resources-specific code.
300
+
For convenience, we recommend running the module generator again from within the first module's directory, generating an unregistered module, and copying the resource-specific code from it.
301
301
302
-
**Example module**: Change directory into the first module's folder:
302
+
**Example module**: Change directory into the first module's directory:
@@ -911,7 +913,7 @@ Since `errUnimplemented` and `Config` are defined in <file>hello-camera.go</file
911
913
In <file>hello-sensor.go</file>:
912
914
913
915
- Delete the `"errors"` import.
914
-
- Search for and delete the line`errUnimplemented = errors.New("unimplemented")`.
916
+
- Search for and delete the line`errUnimplemented = errors.New("unimplemented")`.
915
917
- Search for `type Config struct {` and change it to `type sensorConfig struct {`.
916
918
- Search for all instances of `*Config` in <file>hello-sensor.go</file> and change them to `*sensorConfig`.
917
919
@@ -936,8 +938,8 @@ You can configure it in the web UI using the local files on your machine.
936
938
937
939
### Add module to machine
938
940
939
-
To get your module onto your machine, hot reloading will build and package it and then use the shell service to copy it to the machine for testing.
940
-
If you are using Python `venv`, make sure your module files are on the same device where `viam-server` is running and manually add the module instead.
941
+
To get your module onto your machine, hot reloading builds and packages it and then uses the shell service to copy it to the machine for testing.
942
+
If you are using a Python virtual environment (venv), make sure your module files are on the same device where `viam-server` is running, and add the module manually instead.
941
943
942
944
{{< tabs >}}
943
945
{{% tab name="Hot reloading (recommended)" %}}
@@ -986,13 +988,19 @@ Run the following command to rebuild your module:
986
988
viam module build local
987
989
```
988
990
989
-
Then restart it in your machine's **CONFIGURE** tab.
990
-
In upper right corner of the module's card, click the **...** menu, then click **Restart**.
991
+
Then restart it on your machine's **CONFIGURE** tab.
992
+
In the upper-right corner of the module's card, click the **...** menu, then click **Restart**.
You may need to refresh your machine page for your module to show up.
1001
+
1002
+
{{< /alert >}}
1003
+
996
1004
{{% /tab %}}
997
1005
{{% tab name="Manual (required for Python venv)" %}}
998
1006
@@ -1010,6 +1018,8 @@ For local modules, `viam-server` uses this path to start the module.
1010
1018
**Example module**:
1011
1019
For the `hello-world` module, the path should resemble `/home/yourname/hello-world/run.sh` on Linux, or `/Users/yourname/hello-world/run.sh` on macOS.
1012
1020
1021
+
Save your config.
1022
+
1013
1023
{{% /tab %}}
1014
1024
{{% tab name="Go" %}}
1015
1025
@@ -1025,10 +1035,13 @@ Enter the path to the <file>/bin/<module-name></file> executable.
1025
1035
For local modules, `viam-server` uses this path to start the module.
1026
1036
1027
1037
**Example module**:
1028
-
For the `hello-world` module, the path should resemble `/home/yourname/hello-world/bin/hello-world`. For local modules, `viam-server` uses this path to start the module.
1038
+
For the `hello-world` module, the path should resemble `/home/yourname/hello-world/bin/hello-world`.
1039
+
For local modules, `viam-server` uses this path to start the module.
1029
1040
1030
1041
Click **Create**.
1031
1042
1043
+
Save your config.
1044
+
1032
1045
{{% /tab %}}
1033
1046
{{< /tabs >}}
1034
1047
@@ -1071,9 +1084,9 @@ If your model has required or optional attributes, configure them in the configu
1071
1084
1072
1085
{{% /tablestep %}}
1073
1086
{{% tablestep %}}
1074
-
Save the config, and wait a few seconds for the config to apply.
1087
+
Save the config and wait a few seconds for it to apply.
1075
1088
1076
-
then click the **TEST** section of the camera's configuration card.
1089
+
Then click the **TEST** section of the camera's configuration card.
1077
1090
If there are errors you will see them on the configuration panel and on the **LOGS** tab.
1078
1091
1079
1092
{{% /tablestep %}}
@@ -1082,7 +1095,7 @@ If there are errors you will see them on the configuration panel and on the **LO
1082
1095
1083
1096
Click the **TEST** bar at the bottom of your modular component configuration, and check whether it works as expected.
1084
1097
1085
-
**Test module**: For the camera model, the test panel should show the image:
1098
+
**Example module**: For the camera model, the test panel should show the image:
1086
1099
1087
1100
{{<imgprocsrc="/how-tos/hello-camera.png"resize="x1100"declaredimensions=truealt="The configuration interface with the Test section of the camera card open, showing a hello world image."style="width:800px"class="shadow aligncenter" >}}
1088
1101
@@ -1126,7 +1139,7 @@ viam module reload --part-id 123abc45-1234-432c-aabc-z1y111x23a00
1126
1139
{{% tab name="Python" %}}
1127
1140
1128
1141
As you iterate, save your code changes, then restart the module in your machine's **CONFIGURE** tab:
1129
-
In upper right corner of the module's card, click **...** menu, then click **Restart**.
1142
+
In the upper-right corner of the module's card, click **...** menu, then click **Restart**.
0 commit comments