Skip to content

Commit 99cdc0d

Browse files
committed
Review
1 parent 598286f commit 99cdc0d

File tree

1 file changed

+53
-40
lines changed
  • docs/operate/modules/support-hardware

1 file changed

+53
-40
lines changed

docs/operate/modules/support-hardware/_index.md

Lines changed: 53 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ This page provides instructions for creating a module in Python or Go.
4848
For C++ module examples, see the [C++ examples directory on GitHub](https://github.com/viamrobotics/viam-cpp-sdk/tree/main/src/viam/examples/).
4949
If you want to create a module for use with a microcontroller, see [Modules for ESP32](/operate/modules/advanced/micro-module/).
5050

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:
5252

5353
1. Gets an image from a configured path on your machine
5454
2. Returns a random number
@@ -65,7 +65,7 @@ Authenticate your CLI session with Viam using one of the following options:
6565
{{< readfile "/static/include/how-to/auth-cli.md" >}}
6666
{{< /expand >}}
6767

68-
{{% expand "A running machine connected to Viam." %}}
68+
{{% expand "A running machine connected to Viam" %}}
6969

7070
You can write a module without a machine, but to test your module you'll need a [machine](/operate/install/setup/).
7171

@@ -75,7 +75,7 @@ You can write a module without a machine, but to test your module you'll need a
7575

7676
{{< expand "For Python developers: Use Python 3.11+" >}}
7777

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.
7979

8080
You can check by running `python3 --version` or `python --version` in your terminal.
8181

@@ -85,7 +85,7 @@ You can check by running `python3 --version` or `python --version` in your termi
8585

8686
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.
8787

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.
8989

9090
{{< tabs >}}
9191
{{% tab name="Python" %}}
@@ -141,15 +141,15 @@ func main() {
141141

142142
## Choose an API
143143

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.
145145
The module takes the functionality of the script and maps it to a standardized API for use within the Viam ecosystem.
146146

147147
Review the available [component APIs](/dev/reference/apis/#component-apis) and choose the one whose methods map most closely to the functionality you need.
148148

149149
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.
150150
See [Run control logic](/docs/operate/modules/support-hardware/) for more information.
151151

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.
153153
You need a way to return an image and you need a way to return a number.
154154

155155
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
189189
| Module name | Choose a name that describes the set of {{< glossary_tooltip term_id="resource" text="resources" >}} it supports. |
190190
| Language | Choose the programming language for the module. The CLI supports `Python` and `Golang`. |
191191
| 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. |
193193
| 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. |
194194
| 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 (`_`). |
195195
| 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
199199

200200
<br>
201201

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:
203203

204204
{{< tabs >}}
205205
{{% tab name="Python" %}}
@@ -228,8 +228,8 @@ You can add the model for the sensor in a later step in [Creating multiple model
228228
{{% /tablestep %}}
229229
{{% tablestep %}}
230230

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.
233233

234234
**Example module**: For the example module, the file structure is:
235235

@@ -297,9 +297,9 @@ Some of the code you generated is resource-specific.
297297

298298
If you have multiple modular resources that are related, you can put them all into the same module.
299299

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.
301301

302-
**Example module**: Change directory into the first module's folder:
302+
**Example module**: Change directory into the first module's directory:
303303

304304
```sh {id="terminal-prompt" class="command-line" data-prompt="$"}
305305
cd hello-world
@@ -489,26 +489,27 @@ Save the file.
489489
{{% /tab %}}
490490
{{< /tabs >}}
491491

492-
You can now delete the temporary <file>hello-world/hello-world</file> folder and all its contents.
492+
You can now delete the temporary <file>hello-world/hello-world</file> directory and all its contents.
493493

494494
### Implement the components
495495

496496
At this point you have a template for your module.
497497

498498
If you want to see example modules, check out the Viam Registry.
499499
Many modules have a linked GitHub repo, where you can see the module's code.
500-
When logged in you can also download the module's source code to inspect it.
500+
When logged in, you can also download the module's source code to inspect it.
501501

502502
{{< tabs >}}
503503
{{% tab name="Python" %}}
504504

505505
Generally you will add your custom logic in these files:
506506

507-
| File | Description |
508-
| ---------------------------------------------- | ------------------------------------------------------------------------------------------------ |
507+
<!-- prettier-ignore -->
508+
| File | Description |
509+
| ---- | ----------- |
509510
| <file>/src/models/&lt;model-name&gt;.py</file> | Set up the configuration options for the model and implement the API methods for the model. |
510511
| `setup.sh` and `run.sh` | Add any logic for installing or running other software for your module. |
511-
| `requirements.txt` | Add any python packages that are required for your module. They will be installed by `setup.sh`. |
512+
| `requirements.txt` | Add any Python packages that are required for your module. They will be installed by `setup.sh`. |
512513

513514
<br>
514515

@@ -517,8 +518,9 @@ Generally you will add your custom logic in these files:
517518

518519
Generally you will add your custom logic in these files:
519520

520-
| File | Description |
521-
| ------------------------------------------ | ---------------------------------------- |
521+
<!-- prettier-ignore -->
522+
| File | Description |
523+
| ---- | ----------- |
522524
| Model file (for example `hello-camera.go`) | Implement the API methods for the model. |
523525

524526
{{% /tab %}}
@@ -528,9 +530,9 @@ Generally you will add your custom logic in these files:
528530

529531
#### Set up model configuration options
530532

531-
Many resource models have configuration options which allow you to specify options such as:
533+
Many resource models have configuration options that allow you to specify options such as:
532534

533-
- A filepath from which to access data
535+
- A file path from which to access data
534536
- A pin to which a device is wired
535537
- An optional signal frequency to override a default value
536538
- The name of _another_ resource you wish to use in the model
@@ -560,7 +562,7 @@ Since the camera model returns an image at a provided path, the configuration mu
560562
{{< tabs >}}
561563
{{% tab name="Python" %}}
562564

563-
In <file>/src/models/&lt;model-name&gt;.py</file> edit the `validate_config` function to:
565+
In <file>/src/models/&lt;model-name&gt;.py</file>, edit the `validate_config` function to:
564566

565567
```python {class="line-numbers linkable-line-numbers" data-start="38" data-line="5-10" }
566568
@classmethod
@@ -582,7 +584,7 @@ In <file>/src/models/&lt;model-name&gt;.py</file> edit the `validate_config` fun
582584

583585
In <file>hello-world/hello-camera.go</file> edit the `Validate` function to:
584586

585-
```python {class="line-numbers linkable-line-numbers" data-start="51" data-line="2-10" }
587+
```go {class="line-numbers linkable-line-numbers" data-start="51" data-line="2-10" }
586588
func (cfg *Config) Validate(path string) ([]string, error) {
587589
var deps []string
588590
if cfg.ImagePath == "" {
@@ -596,7 +598,7 @@ func (cfg *Config) Validate(path string) ([]string, error) {
596598
}
597599
```
598600

599-
Add the following imports at the top of <file>hello-world/hello-camera.go</file>:
601+
Add the following import at the top of <file>hello-world/hello-camera.go</file>:
600602

601603
```go {class="line-numbers linkable-line-numbers" data-start="7"}
602604
"reflect"
@@ -605,15 +607,15 @@ Add the following imports at the top of <file>hello-world/hello-camera.go</file>
605607
{{% /tab %}}
606608
{{< /tabs >}}
607609

608-
For the sensor model, you do not need to edit any of the validate or configuration methods because the sensor has no configurable attributes.
610+
For the sensor model, you do not need to edit any of the validation or configuration methods because the sensor has no configurable attributes.
609611

610612
{{% /tablestep %}}
611613
{{% tablestep %}}
612614
**Reconfiguration**
613615

614616
`viam-server` calls the `reconfigure` method when the user adds the model or changes its configuration.
615617

616-
The validation step serves two purposes:
618+
The reconfiguration step serves two purposes:
617619

618620
- Use the configuration attributes and dependencies to set attributes on the model for usage within the API methods.
619621
- Obtain access to dependencies.
@@ -863,7 +865,7 @@ func (s *helloWorldHelloCamera) Images(ctx context.Context, filterSourceNames []
863865
{{% /tablestep %}}
864866
{{% tablestep %}}
865867

866-
Add the following import to the list of imports at the top of <file>hello-world/hello-camera.go</file>:
868+
Add the following import at the top of <file>hello-world/hello-camera.go</file>:
867869

868870
```go {class="line-numbers linkable-line-numbers" data-start="7"}
869871
"os"
@@ -885,7 +887,7 @@ The module generator created a stub for the `Readings()` function we want to imp
885887

886888
Replace `panic("not implemented")` with code to implement the method:
887889

888-
```python {class="line-numbers linkable-line-numbers" data-start="92" data-line="8-11" }
890+
```go {class="line-numbers linkable-line-numbers" data-start="92" data-line="8-11" }
889891
func (s *helloWorldHelloSensor) Readings(ctx context.Context, extra map[string]interface{}) (map[string]interface{}, error) {
890892
number := rand.Float64()
891893
return map[string]interface{}{
@@ -897,7 +899,7 @@ func (s *helloWorldHelloSensor) Readings(ctx context.Context, extra map[string]i
897899
{{% /tablestep %}}
898900
{{< tablestep >}}
899901

900-
Add the following import to the list of imports at the top of <file>hello-world/hello-camera.go</file>:
902+
Add the following import to the list of imports at the top of <file>hello-world/hello-sensor.go</file>:
901903

902904
```go {class="line-numbers linkable-line-numbers" data-start="7"}
903905
"math/rand"
@@ -911,7 +913,7 @@ Since `errUnimplemented` and `Config` are defined in <file>hello-camera.go</file
911913
In <file>hello-sensor.go</file>:
912914

913915
- 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")`.
915917
- Search for `type Config struct {` and change it to `type sensorConfig struct {`.
916918
- Search for all instances of `*Config` in <file>hello-sensor.go</file> and change them to `*sensorConfig`.
917919

@@ -936,8 +938,8 @@ You can configure it in the web UI using the local files on your machine.
936938

937939
### Add module to machine
938940

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.
941943

942944
{{< tabs >}}
943945
{{% tab name="Hot reloading (recommended)" %}}
@@ -986,13 +988,19 @@ Run the following command to rebuild your module:
986988
viam module build local
987989
```
988990

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**.
991993

992994
{{<imgproc src="/registry/restart-module.png" resize="x600" declaredimensions=true alt="Module menu." style="width:300px" class="shadow" >}}
993995

994996
{{< /expand >}}
995997

998+
{{< alert title="Refresh" color="note" >}}
999+
1000+
You may need to refresh your machine page for your module to show up.
1001+
1002+
{{< /alert >}}
1003+
9961004
{{% /tab %}}
9971005
{{% tab name="Manual (required for Python venv)" %}}
9981006

@@ -1010,6 +1018,8 @@ For local modules, `viam-server` uses this path to start the module.
10101018
**Example module**:
10111019
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.
10121020

1021+
Save your config.
1022+
10131023
{{% /tab %}}
10141024
{{% tab name="Go" %}}
10151025

@@ -1025,10 +1035,13 @@ Enter the path to the <file>/bin/&#60;module-name&#62;</file> executable.
10251035
For local modules, `viam-server` uses this path to start the module.
10261036

10271037
**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.
10291040

10301041
Click **Create**.
10311042

1043+
Save your config.
1044+
10321045
{{% /tab %}}
10331046
{{< /tabs >}}
10341047

@@ -1071,9 +1084,9 @@ If your model has required or optional attributes, configure them in the configu
10711084

10721085
{{% /tablestep %}}
10731086
{{% 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.
10751088

1076-
then click the **TEST** section of the camera's configuration card.
1089+
Then click the **TEST** section of the camera's configuration card.
10771090
If there are errors you will see them on the configuration panel and on the **LOGS** tab.
10781091

10791092
{{% /tablestep %}}
@@ -1082,7 +1095,7 @@ If there are errors you will see them on the configuration panel and on the **LO
10821095

10831096
Click the **TEST** bar at the bottom of your modular component configuration, and check whether it works as expected.
10841097

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:
10861099

10871100
{{<imgproc src="/how-tos/hello-camera.png" resize="x1100" declaredimensions=true alt="The configuration interface with the Test section of the camera card open, showing a hello world image." style="width:800px" class="shadow aligncenter" >}}
10881101

@@ -1126,7 +1139,7 @@ viam module reload --part-id 123abc45-1234-432c-aabc-z1y111x23a00
11261139
{{% tab name="Python" %}}
11271140

11281141
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**.
11301143

11311144
{{<imgproc src="/registry/restart-module.png" resize="x600" declaredimensions=true alt="Module menu." style="width:300px" class="shadow" >}}
11321145

@@ -1140,7 +1153,7 @@ viam module build local
11401153
```
11411154

11421155
Then restart it in your machine's **CONFIGURE** tab.
1143-
In upper right corner of the module's card, click **...** menu, then click **Restart**.
1156+
In the upper-right corner of the module's card, click **...** menu, then click **Restart**.
11441157

11451158
{{<imgproc src="/registry/restart-module.png" resize="x600" declaredimensions=true alt="Module menu." style="max-width:300px" class="shadow" >}}
11461159

0 commit comments

Comments
 (0)