Skip to content

Commit bed241c

Browse files
authored
Update README.md for sensor module (#363)
1 parent 6103459 commit bed241c

File tree

2 files changed

+42
-33
lines changed

2 files changed

+42
-33
lines changed

src/viam/examples/README.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# Viam C++ SDK Examples
2+
3+
This directory contains some examples for working with the Viam SDK, ranging from component and service examples to module examples which show how to create modular resources.
4+
5+
Note that with the exception of examples in the [`project`](./project) directory, all these examples are _part of the C++ SDK build tree_, which means that their build files only work if you are using them within an existing SDK build. For learning about SDK features and concepts this is fine, but it is **not** what you should use for starter code if you want, for example, to develop and deploy a standalone C++ module which lives outside of the SDK build tree. For that look in the [`project`](./project) directory, where you will find CMake and Makefile code which adapts the source code from the simple module example to work as a standalone project which consumes the Viam C++ SDK as a dependency.
6+
7+
8+
19
# Component & Service Examples
210
Examples:
311
- camera
@@ -16,9 +24,15 @@ This will setup a server running on `localhost:8080` that has a mock setup of th
1624

1725
Download and build the C++ SDK by following the instructions [here](https://github.com/viamrobotics/viam-cpp-sdk#getting-started).
1826

19-
Then run:
27+
Then run the executable for whichever component you chose to build above. This will be
2028
``` shell
21-
viam-cpp-sdk/build/viam/examples/[component name]/example_[component name]
29+
# Camera
30+
viam-cpp-sdk/build/viam/examples/camera/example_camera
31+
```
32+
or
33+
```shell
34+
# Motor
35+
viam-cpp-sdk/build/viam/examples/motor/example_motor
2236
```
2337

2438
# Module examples
@@ -27,14 +41,9 @@ Examples:
2741
- complex
2842
- tflite
2943

30-
These examples go through how to create custom modular resources using Viam's C++ SDK, and how to connect them to a Robot. Refer to each directory's README file for more information.
31-
32-
# Generic Examples
33-
34-
## Project example
35-
This example shows how to setup a simple CMake-based project that uses Viam's C++ SDK.
44+
These examples go through how to create custom modular resources using Viam's C++ SDK, and how to connect them to a Robot. Refer to each directory's README file for more information. As mentioned above, these can either be built as part of the SDK build tree, or you can use some of the build code in [`project`](./project) to build the simple module example as a standalone project which consumes the SDK as a dependency.
3645

37-
## Dial Example
46+
# Dial Example
3847

3948
If you are connecting to a robot with authentication you will need to
4049
add credentials. Update path code :

src/viam/examples/modules/simple/README.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ For more information, see the [documentation](https://docs.viam.com/registry/).
1111
For a list of example modules in different Viam SDKs, take a look [here](https://github.com/viamrobotics/upload-module/#example-repos).
1212

1313
## Project structure
14-
The `main.cpp` file contains the definition of a new generic model and code to register it. It also has the optional validator function and implements reconfigure. The validator function is defined upon resource registration, and the reconfigure method is implemented on the resource class.
14+
The `main.cpp` file contains the definition of a new sensor component and code to register it. It also has the optional validator function and implements reconfigure. The validator function is defined upon resource registration, and the reconfigure method is implemented on the resource class.
1515

16-
The validator function can throw errors that are triggered due to errors in the configuration. It also returns a vector of strings representing the implicit dependencies of the resource. Note that printers have no implicit dependencies; see the [complex module example](https://github.com/viamrobotics/viam-cpp-sdk/tree/main/src/viam/examples/modules/complex) for examples of modular resources with implicit dependencies.
16+
The validator function can throw errors that are triggered due to errors in the configuration. It also returns a vector of strings representing the implicit dependencies of the resource. Note that this sensor has no implicit dependencies; see the [complex module example](https://github.com/viamrobotics/viam-cpp-sdk/tree/main/src/viam/examples/modules/complex) for examples of modular resources with implicit dependencies.
1717

1818
The reconfiguration method reconfigures the resource based on the new configuration passed in.
1919

@@ -22,28 +22,28 @@ When simple_module is run, the main function creates and starts the module. Read
2222
## Configuring and using the module
2323
The `simple_module` binary generated after building is the entrypoint for this module. To connect this module with your robot, you must add this module's entrypoint to the robot's config. For example, this could be `/home/viam-cpp-sdk/build/install/bin/simple_module`. See the [documentation](https://docs.viam.com/registry/configure/#add-a-local-module) for more details.
2424

25-
Once the module has been added to your robot, you will then need to add a component that uses the `viam:generic:printer` model. See the [documentation](https://docs.viam.com/registry/configure/#add-a-local-modular-resource) for more details.
26-
27-
An example configuration for a printer could look like this:
28-
```json
29-
{
30-
"modules": [
31-
{
32-
"name": "MyModule",
33-
"executable_path": "/home/viam-cpp-sdk/build/install/bin/simple_module"
34-
}
35-
],
36-
"components": [
37-
{
38-
"namespace": "rdk",
39-
"type": "generic",
40-
"name": "printer1",
41-
"model": "viam:generic:printer",
42-
"attributes": {
43-
"to_print": "foo"
44-
}
45-
}
46-
]
25+
Once the module has been added to your robot, you will then need to add a component that uses the `viam:sensor:mysensor` model. See the [documentation](https://docs.viam.com/registry/configure/#add-a-local-modular-resource) for more details.
26+
27+
An example configuration for our sensor could look like this:
28+
```json{
29+
"components": [
30+
{
31+
"name": "mysensor",
32+
"api": "rdk:component:sensor",
33+
"model": "viam:sensor:mysensor",
34+
"attributes": {
35+
"multiplier": 2
36+
}
37+
}
38+
],
39+
"modules": [
40+
{
41+
"type": "local",
42+
"name": "my-module",
43+
"executable_path": "/home/viam-cpp-sdk/build/install/bin/simple_module"
44+
}
45+
]
4746
}
4847
```
4948

49+
Note in particular that our sensor has a `multiplier` attribute whose presence is checked in the `validate` and `reconfigure` methods, defaulting to 1.0 if not present.

0 commit comments

Comments
 (0)