Skip to content

Commit ac8db5a

Browse files
committed
Update flow
1 parent 99cdc0d commit ac8db5a

File tree

1 file changed

+39
-41
lines changed
  • docs/operate/modules/support-hardware

1 file changed

+39
-41
lines changed

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

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -110,29 +110,29 @@ print(random_number)
110110
package main
111111

112112
import (
113-
"fmt"
114-
"math/rand"
115-
"os"
113+
"fmt"
114+
"math/rand"
115+
"os"
116116
)
117117

118118
func main() {
119-
// Open an image
120-
imgFile, err := os.Open("example.png")
121-
if err != nil {
122-
fmt.Printf("Error opening image file: %v\n", err)
123-
return
124-
}
125-
defer imgFile.Close()
126-
imgByte, err := os.ReadFile("example.png")
127-
fmt.Printf("Image file type: %T\n", imgByte)
128-
if err != nil {
129-
fmt.Printf("Error reading image file: %v\n", err)
130-
return
131-
}
132-
133-
// Return a random number
134-
number := rand.Float64()
135-
fmt.Printf("Random number: %f\n", number)
119+
// Open an image
120+
imgFile, err := os.Open("example.png")
121+
if err != nil {
122+
fmt.Printf("Error opening image file: %v\n", err)
123+
return
124+
}
125+
defer imgFile.Close()
126+
imgByte, err := os.ReadFile("example.png")
127+
fmt.Printf("Image file type: %T\n", imgByte)
128+
if err != nil {
129+
fmt.Printf("Error reading image file: %v\n", err)
130+
return
131+
}
132+
133+
// Return a random number
134+
number := rand.Float64()
135+
fmt.Printf("Random number: %f\n", number)
136136
}
137137
```
138138

@@ -147,7 +147,7 @@ The module takes the functionality of the script and maps it to a standardized A
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.
150-
See [Run control logic](/docs/operate/modules/support-hardware/) for more information.
150+
See [Run control logic](/docs/operate/modules/control-logic/) for more information.
151151

152152
**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.
@@ -336,13 +336,12 @@ from viam.module.module import Module
336336
try:
337337
from models.hello_camera import HelloCamera
338338
from models.hello_sensor import HelloSensor
339-
except ModuleNotFoundError: # when running as local module with run.sh
339+
except ModuleNotFoundError: # when running as local module with run.sh
340340
from .models.hello_camera import HelloCamera
341341
from .models.hello_sensor import HelloSensor
342342

343343
if __name__ == '__main__':
344344
asyncio.run(Module.run_from_registry())
345-
346345
```
347346

348347
Save the file.
@@ -423,19 +422,19 @@ This file must add resource imports and register the module's models:
423422
package main
424423

425424
import (
426-
"helloworld"
427-
"go.viam.com/rdk/module"
428-
"go.viam.com/rdk/resource"
429-
camera "go.viam.com/rdk/components/camera"
430-
sensor "go.viam.com/rdk/components/sensor"
425+
"helloworld"
426+
"go.viam.com/rdk/module"
427+
"go.viam.com/rdk/resource"
428+
camera "go.viam.com/rdk/components/camera"
429+
sensor "go.viam.com/rdk/components/sensor"
431430
)
432431

433432
func main() {
434-
// ModularMain can take multiple APIModel arguments, if your module implements multiple models.
435-
module.ModularMain(
436-
resource.APIModel{ camera.API, helloworld.HelloCamera},
437-
resource.APIModel{ sensor.API, helloworld.HelloSensor},
438-
)
433+
// ModularMain can take multiple APIModel arguments, if your module implements multiple models.
434+
module.ModularMain(
435+
resource.APIModel{ camera.API, helloworld.HelloCamera},
436+
resource.APIModel{ sensor.API, helloworld.HelloSensor},
437+
)
439438
}
440439
```
441440

@@ -585,7 +584,7 @@ In <file>/src/models/&lt;model-name&gt;.py</file>, edit the `validate_config` fu
585584
In <file>hello-world/hello-camera.go</file> edit the `Validate` function to:
586585

587586
```go {class="line-numbers linkable-line-numbers" data-start="51" data-line="2-10" }
588-
func (cfg *Config) Validate(path string) ([]string, error) {
587+
func (cfg *Config) Validate(path string) ([]string, []string, error) {
589588
var deps []string
590589
if cfg.ImagePath == "" {
591590
return nil, nil, resource.NewConfigValidationFieldRequiredError(path, "image_path")
@@ -808,10 +807,10 @@ We recommend using the pattern the generator follows:
808807
import asyncio
809808
from viam.module.module import Module
810809
try:
811-
from models.hello_camera import MyCamera
810+
from models.hello_camera import HelloCamera
812811
except ModuleNotFoundError:
813812
# when running as local module with run.sh
814-
from .models.hello_camera import MyCamera
813+
from .models.hello_camera import HelloCamera
815814

816815
if __name__ == '__main__':
817816
asyncio.run(Module.run_from_registry())
@@ -853,7 +852,7 @@ func (s *helloWorldHelloCamera) Images(ctx context.Context, filterSourceNames []
853852
return nil, responseMetadataRetVal, err
854853
}
855854

856-
named, err := camera.NamedImageFromBytes(imgByte, "default", "image/png")
855+
named, err := camera.NamedImageFromBytes(imgByte, "default", "image/png")
857856
if err != nil {
858857
return nil, responseMetadataRetVal, err
859858
}
@@ -1018,7 +1017,7 @@ For local modules, `viam-server` uses this path to start the module.
10181017
**Example module**:
10191018
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.
10201019

1021-
Save your config.
1020+
Save the config.
10221021

10231022
{{% /tab %}}
10241023
{{% tab name="Go" %}}
@@ -1036,11 +1035,10 @@ For local modules, `viam-server` uses this path to start the module.
10361035

10371036
**Example module**:
10381037
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.
10401038

10411039
Click **Create**.
10421040

1043-
Save your config.
1041+
Save the config.
10441042

10451043
{{% /tab %}}
10461044
{{< /tabs >}}
@@ -1138,7 +1136,7 @@ viam module reload --part-id 123abc45-1234-432c-aabc-z1y111x23a00
11381136
{{< tabs >}}
11391137
{{% tab name="Python" %}}
11401138

1141-
As you iterate, save your code changes, then restart the module in your machine's **CONFIGURE** tab:
1139+
As you iterate, save the code changes, then restart the module in your machine's **CONFIGURE** tab:
11421140
In the upper-right corner of the module's card, click **...** menu, then click **Restart**.
11431141

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

0 commit comments

Comments
 (0)