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/get-started/other-hardware/_index.md
+44-18Lines changed: 44 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -155,8 +155,8 @@ Edit the generated files to add your logic:
155
155
1. Open <file>/src/models/<model-name>.py</file> and add any necessary imports.
156
156
1.**Edit the `validate_config` function** to do the following:
157
157
158
-
- Check that the user has configured required attributes
159
-
- Return any implicit dependencies
158
+
- Check that the user has configured required attributes and return errors if they are missing.
159
+
- Return a map of any implicit dependencies.
160
160
161
161
<details>
162
162
<summary><strong>Explicit versus implicit dependencies</strong></summary>
@@ -177,9 +177,12 @@ Edit the generated files to add your logic:
177
177
178
178
</details><br>
179
179
180
-
1.**Edit the `reconfigure` function** to do the following:
180
+
1.**Edit the `reconfigure` function**, which gets called when the user changes the configuration.
181
+
This function should do the following:
181
182
182
-
- Assign any default values as necessary to any optional attributes if the user hasn't configured them.<br><br>
183
+
- 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.
184
+
- Assign default values as necessary to any optional attributes if the user hasn't configured them.
185
+
- 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).
183
186
184
187
<ol><listyle="counter-reset: item 3"><strong>Edit the methods you want to implement</strong>:
1.**Edit the `Reconfigure` function** to do the following:
398
+
1.**(Optional) Create and edit a `Reconfigure` function**:
396
399
397
-
- Assign any default values as necessary to any optional attributes if the user hasn't configured them.<br><br>
400
+
In most cases, you can omit this function and leave `resource.AlwaysRebuild` in the `Config` struct.
401
+
This will cause `viam-server` to fully rebuild the resource each time the user changes the configuration.
402
+
403
+
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.
404
+
In this case, your `Reconfigure` function should do the following:
405
+
406
+
- 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.
407
+
- Assign default values as necessary to any optional attributes if the user hasn't configured them.<br><br>
408
+
409
+
1.**Edit the constructor** to do the following:
410
+
411
+
- 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.
412
+
- If you created a `Reconfigure` function, make your constructor call `Reconfigure`.<br><br>
398
413
399
414
<ol><listyle="counter-reset: item 4"><strong>Edit the methods you want to implement</strong>:
400
415
@@ -404,6 +419,7 @@ You can find details about the return types at [go.viam.com/rdk/components](http
404
419
405
420
{{< expand "Example code for a camera module" >}}
406
421
This example from [Hello World module](/operate/get-started/other-hardware/hello-world-module/) implements only one method of the camera API by returning a static image.
422
+
It demonstrates a required configuration attribute (`image_path`) and an optional configuration attribute (`example_value`).
0 commit comments