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/control/web-app.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -38,7 +38,7 @@ Refer to the [Viam TypeScript SDK](https://ts.viam.dev/) documentation for avail
38
38
39
39
The following files create an example TypeScript web app that connects to a machine and displays the latest image from the machine's camera, and the latest sensor readings.
40
40
41
-
{{<imgprocsrc="/operate/ts-dashboard.png"resize="x1100"declaredimensions=truealt="A web browser displaying a dashboard with a camera feed and sensor readings."style="max-width:450px"class="imgzoom" >}}
41
+
{{<imgprocsrc="/operate/ts-dashboard.png"resize="x1100"declaredimensions=truealt="A web browser displaying a dashboard with a camera feed and sensor readings."style="width:450px"class="imgzoom" >}}
Copy file name to clipboardExpand all lines: docs/operate/get-started/other-hardware/_index.md
+70-44
Original file line number
Diff line number
Diff line change
@@ -180,21 +180,31 @@ Edit the generated files to add your logic:
180
180
{{< tabs >}}
181
181
{{% tab name="Python" %}}
182
182
183
-
1. Open <file>/src/models/<model-name>.py</file> and add any necessary imports.
184
-
1.**Edit the `validate_config` function** to do the following:
183
+
{{< table >}}
184
+
{{< tablestep number=1 >}}
185
+
Open <file>/src/models/<model-name>.py</file> and add any necessary imports.
186
+
{{% /tablestep %}}
187
+
{{< tablestep number=2 >}}
188
+
**Edit the `validate_config` function** to do the following:
189
+
190
+
- Check that the user has configured required attributes and return errors if they are missing.
191
+
- Return a map of any dependencies.
185
192
186
-
- Check that the user has configured required attributes and return errors if they are missing.
187
-
- Return a map of any dependencies.
188
-
- For more information, see [Module dependencies](/operate/get-started/other-hardware/dependencies/).
193
+
For more information, see [Module dependencies](/operate/get-started/other-hardware/dependencies/).
189
194
190
-
1.**Edit the `reconfigure` function**, which gets called when the user changes the configuration.
191
-
This function should do the following:
195
+
{{% /tablestep %}}
196
+
{{< tablestep number=3 >}}
197
+
198
+
**Edit the `reconfigure` function**, which gets called when the user changes the configuration.
199
+
This function should do the following:
192
200
193
-
- If you assigned any configuration attributes to global variables, get the values from the latest `config` object and update the values of the global variables.
194
-
- Assign default values as necessary to any optional attributes if the user hasn't configured them.
195
-
- If your module has dependencies, get the dependencies from the `dependencies` map and cast each resource according to which API it implements, as in [this <file>ackermann.py</file> example](https://github.com/mcvella/viam-ackermann-base/blob/main/src/ackermann.py).
201
+
- If you assigned any configuration attributes to global variables, get the values from the latest `config` object and update the values of the global variables.
202
+
- Assign default values as necessary to any optional attributes if the user hasn't configured them.
203
+
- If your module has dependencies, get the dependencies from the `dependencies` map and cast each resource according to which API it implements, as in [this <file>ackermann.py</file> example](https://github.com/mcvella/viam-ackermann-base/blob/main/src/ackermann.py).
204
+
{{% /tablestep %}}
205
+
{{< tablestep number=4 >}}
196
206
197
-
<ol><listyle="counter-reset: item 3"><strong>Edit the methods you want to implement</strong>:
207
+
**Edit the methods you want to implement**:
198
208
199
209
For each method you want to implement, replace the body of the method with your relevant logic.
200
210
Make sure you return the correct type in accordance with the function's return signature.
@@ -323,10 +333,11 @@ if __name__ == "__main__":
323
333
324
334
You can find more examples by looking at the source code GitHub repos linked from each module in the [Viam Registry](https://app.viam.com/registry).
325
335
326
-
</li></ol>
336
+
{{% /tablestep %}}
337
+
{{< tablestep number=5 >}}
327
338
328
-
<ol><listyle="counter-reset: item 4"><strong>Add logging</strong> messages as desired.
329
-
The following log severity levels are available for resource logs:
339
+
**Add logging** messages as desired.
340
+
The following log severity levels are available for resource logs:
<ol><listyle="counter-reset: item 5"><strong>Edit the generated <file>requirements.txt</file> file</strong> to include any packages that must be installed for the module to run.
373
-
Depending on your use case, you may not need to add anything here beyond <code>viam-sdk</code> which is auto-populated.
384
+
**Edit the generated <file>requirements.txt</file> file** to include any packages that must be installed for the module to run.
385
+
Depending on your use case, you may not need to add anything here beyond <code>viam-sdk</code> which is auto-populated.
This error doesn't exist in the other SDKs, so `AlwaysRebuild` is not supported in those SDKs.
383
396
{{% /hiddencontent %}}
384
397
385
-
1. Open <file>module.go</file> and add necessary imports.
398
+
{{< table >}}
399
+
{{< tablestep number=1 >}}
400
+
Open <file>module.go</file> and add necessary imports.
401
+
{{% /tablestep %}}
402
+
{{< tablestep number=2 >}}
403
+
**Add any configurable attributes to the `Config` struct.**
404
+
{{% /tablestep %}}
405
+
{{< tablestep number=3 >}}
406
+
**Edit the `Validate` function** to do the following:
386
407
387
-
1.**Add any configurable attributes to the `Config` struct.**
408
+
- Check that the user has configured required attributes and return errors if they are missing.
409
+
- Return any dependencies.
388
410
389
-
1.**Edit the `Validate` function** to do the following:
411
+
For more information, see [Module dependencies](/operate/get-started/other-hardware/dependencies/).
412
+
{{% /tablestep %}}
413
+
{{< tablestep number=4 >}}
414
+
415
+
**(Optional) Create and edit a `Reconfigure` function**:
390
416
391
-
- Check that the user has configured required attributes and return errors if they are missing.
392
-
- Return any dependencies.
393
-
- For more information, see [Module dependencies](/operate/get-started/other-hardware/dependencies/).<br><br>
417
+
In most cases, you can omit this function and leave `resource.AlwaysRebuild` in the `Config` struct.
418
+
This will cause `viam-server` to fully rebuild the resource each time the user changes the configuration.
394
419
395
-
1.**(Optional) Create and edit a `Reconfigure` function**:
420
+
If you need to maintain the state of the resource, for example if you are implementing a board and need to keep the software PWM loops running, you should implement this function so that `viam-server` updates the configuration without rebuilding the resource from scratch.
421
+
In this case, your `Reconfigure` function should do the following:
396
422
397
-
In most cases, you can omit this function and leave `resource.AlwaysRebuild` in the `Config` struct.
398
-
This will cause `viam-server`to fully rebuild the resource each time the user changes the configuration.
423
+
- If you assigned any configuration attributes to global variables, get the values from the latest `config` object and update the values of the global variables.
424
+
- Assign default values as necessary to any optional attributes if the user hasn't configured them.
399
425
400
-
If you need to maintain the state of the resource, for example if you are implementing a board and need to keep the software PWM loops running, you should implement this function so that `viam-server` updates the configuration without rebuilding the resource from scratch.
401
-
In this case, your `Reconfigure` function should do the following:
426
+
For an example that implements the `Reconfigure` method, see [<file>mybase.go</file> on GitHub](https://github.com/viamrobotics/rdk/blob/main/examples/customresources/models/mybase/mybase.go).
402
427
403
-
- If you assigned any configuration attributes to global variables, get the values from the latest `config` object and update the values of the global variables.
404
-
- Assign default values as necessary to any optional attributes if the user hasn't configured them.<br><br>
428
+
{{% /tablestep %}}
429
+
{{< tablestep number=5 >}}
405
430
406
-
For an example that implements the `Reconfigure` method, see [<file>mybase.go</file> on GitHub](https://github.com/viamrobotics/rdk/blob/main/examples/customresources/models/mybase/mybase.go).
431
+
**Edit the constructor** to do the following:
407
432
408
-
1.**Edit the constructor** to do the following:
433
+
- If you didn't create a `Reconfigure` function, use the constructor to assign default values as necessary to any optional attributes if the user hasn't configured them.
434
+
- If you created a `Reconfigure` function, make your constructor call `Reconfigure`.
409
435
410
-
- If you didn't create a `Reconfigure` function, use the constructor to assign default values as necessary to any optional attributes if the user hasn't configured them.
411
-
- If you created a `Reconfigure` function, make your constructor call `Reconfigure`.<br><br>
436
+
{{% /tablestep %}}
437
+
{{< tablestep number=6 >}}
412
438
413
-
<ol><listyle="counter-reset: item 4"><strong>Edit the methods you want to implement</strong>:
439
+
**Edit the methods you want to implement**:
414
440
415
441
For each method you want to implement, replace the body of the method with your relevant logic.
416
442
Make sure you return the correct type in accordance with the function's return signature.
@@ -553,10 +579,9 @@ func (s *helloWorldHelloCamera) Close(context.Context) error {
553
579
{{< /expand >}}
554
580
555
581
You can find more examples by looking at the source code GitHub repos linked from each module in the [Viam Registry](https://app.viam.com/registry).
556
-
557
-
</li></ol>
558
-
559
-
<ol><listyle="counter-reset: item 5"><strong>Add logging</strong> messages as desired.
582
+
{{% /tablestep %}}
583
+
{{< tablestep number=7 >}}
584
+
**Add logging** messages as desired.
560
585
561
586
You can add log messages with various levels of severity:
@@ -792,7 +818,7 @@ Configure any required attributes using proper JSON syntax.
792
818
Click the **TEST** bar at the bottom of your modular component configuration, and check whether it works as expected.
793
819
For example, if you created a sensor component, check whether readings are displayed.
794
820
795
-
{{<imgprocsrc="/how-tos/sensor-test.png"resize="x1100"declaredimensions=truealt="The test section of an example modular sensor, with readings displayed."style="max-width:600px"class="shadow" >}}
821
+
{{<imgprocsrc="/how-tos/sensor-test.png"resize="x1100"declaredimensions=truealt="The test section of an example modular sensor, with readings displayed."style="width:600px"class="shadow" >}}
796
822
797
823
{{% /tablestep %}}
798
824
{{% tablestep number=5 %}}
@@ -825,7 +851,7 @@ viam module build local
825
851
Then restart it in your machine's **CONFIGURE** tab in the Viam app.
826
852
In upper right corner of the module's card, click **...** menu, then click **Restart**.
0 commit comments