-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update docs for modular driver example consolidation #239
Changes from 8 commits
c666128
7738c46
4993e9b
18a5baa
bdff1ba
18edf25
de662df
e5b7244
c0906e8
110ce9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
# Viam Micro-RDK ESP32 Sensor Modules Example | ||
# Viam Micro-RDK Modular Driver Examples | ||
|
||
## (In)stability Notice | ||
|
||
> **Warning** The Viam Micro-RDK is currently in beta. | ||
|
||
## Overview | ||
|
||
This project in this repository was generated from the [Micro-RDK | ||
Module | ||
Template](https://github.com/viamrobotics/micro-rdk/tree/main/templates/module), | ||
This project in this repository was generated from the | ||
[Micro-RDK Module Template](/templates/module), | ||
and demonstrates how to produce modular resources for the Micro-RDK. | ||
|
||
## Usage | ||
|
@@ -36,11 +35,12 @@ index 79fbc5c..949b5ab 100644 | |
smol = "1.2" | ||
futures-lite = "1.12.0" | ||
micro-rdk = {version = "0.0.3", git = "https://github.com/viamrobotics/micro-rdk.git", features = ["esp32"]} | ||
+micro-rdk-esp32-sensor-examples = { git = "https://github.com/viam-labs/micro-rdk-esp32-sensor-examples" } | ||
+micro-rdk-modular-driver-example = { git = "https://github.com/viamrobotics/micro-rdk/tree/main/examples/modular-drivers" } | ||
``` | ||
|
||
Rebuild the project per the above Micro-RDK Development Setup | ||
instructions and reflash the board. | ||
instructions and reflash the board. We will be using the Wifi | ||
RSSI Sensor and free heap sensor for this example. | ||
|
||
### Instantiating the Sensors | ||
|
||
|
@@ -94,7 +94,7 @@ can find this code on the `Code Sample` page for your robot): | |
## Implementation Walkthrough | ||
|
||
This project was created by using the [Micro-RDK Module | ||
Template](https://github.com/viamrobotics/micro-rdk/tree/main/templates/module) | ||
Template](/templates/module) | ||
and `cargo generate`: | ||
|
||
``` shell | ||
|
@@ -103,33 +103,39 @@ $ cargo generate --git https://github.com/viamrobotics/micro-rdk templates/modul | |
``` | ||
|
||
When prompted by the template, the project was named | ||
`micro-rdk-esp32-sensor-examples` and `esp32` selected for the target | ||
`micro-rdk-modular-driver-example` and `esp32` selected for the target | ||
platform. The generated project has the form of a library crate, where | ||
`src/lib.rs` defines an initially empty implementation of the | ||
well-known Micro-RDK module entry point `register_models`: | ||
|
||
https://github.com/viam-labs/micro-rdk-esp32-sensor-examples/blob/02d7c8e487a48ac7c8d527a5c7b750d6c2357a27/src/lib.rs#L3-L5 | ||
``` rust | ||
use micro_rdk::common::registry::{ComponentRegistry, RegistryError}; | ||
|
||
pub fn register_models(_registry: &mut ComponentRegistry) -> Result<(), RegistryError> { | ||
Ok(()) | ||
} | ||
``` | ||
|
||
The generated project also includes a `package.metadata` section in | ||
its `Cargo.toml` which identifies the library crate as being a | ||
Micro-RDK module: | ||
|
||
https://github.com/viam-labs/micro-rdk-esp32-sensor-examples/blob/02d7c8e487a48ac7c8d527a5c7b750d6c2357a27/Cargo.toml#L12-L13 | ||
https://github.com/viamrobotics/micro-rdk/blob/fbc1783258bfefc027fd25a8cc9a1b37f6ea0524/examples/modular-drivers/Cargo.toml#L18-L19 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be relative? |
||
A subsequent commit adds definitions of the | ||
[FreeHeapSensor](https://github.com/viam-labs/micro-rdk-esp32-sensor-examples/blob/9cc59d56cc35ab7cf0c471b613c5f3c2ab2ed95b/src/wifi_rssi_sensor.rs) | ||
[FreeHeapSensor](src/free_heap_sensor.rs) | ||
and | ||
[WifiRSSISensor](https://github.com/viam-labs/micro-rdk-esp32-sensor-examples/blob/9cc59d56cc35ab7cf0c471b613c5f3c2ab2ed95b/src/free_heap_sensor.rs) | ||
[WifiRSSISensor](src/wifi_rssi_sensor.rs) | ||
|
||
That commit also introduces a crate-local `register_model` function | ||
That commit also introduces a crate-local `register_models` function | ||
for each sensor: | ||
|
||
- `FreeHeapSensor`: https://github.com/viam-labs/micro-rdk-esp32-sensor-examples/blob/9cc59d56cc35ab7cf0c471b613c5f3c2ab2ed95b/src/free_heap_sensor.rs#L21-L25 | ||
- `WifiRSSISensor`: https://github.com/viam-labs/micro-rdk-esp32-sensor-examples/blob/9cc59d56cc35ab7cf0c471b613c5f3c2ab2ed95b/src/wifi_rssi_sensor.rs#L19-L23 | ||
- `FreeHeapSensor`: https://github.com/viamrobotics/micro-rdk/blob/main/examples/modular-drivers/src/free_heap_sensor.rs#L23-L27 | ||
- `WifiRSSISensor`: https://github.com/viamrobotics/micro-rdk/blob/main/examples/modular-drivers/src/wifi_rssi_sensor.rs#L23-L27 | ||
|
||
Finally, the top level `register_models` entry point is updated to delegate to the `register_model` function for both sensors: | ||
Finally, the top level `register_models` entry point is updated to delegate to the `register_models` function for both sensors: | ||
|
||
https://github.com/viam-labs/micro-rdk-esp32-sensor-examples/blob/9cc59d56cc35ab7cf0c471b613c5f3c2ab2ed95b/src/lib.rs#L6-L10 | ||
https://github.com/viamrobotics/micro-rdk/blob/main/examples/modular-drivers/src/lib.rs#L10-L18 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The three links here should also reference fbc1783, not |
||
The Micro-RDK module is now ready to be used in a Micro-RDK project, | ||
just by adding it as an ordinary dependency in the `dependencies` | ||
|
@@ -138,6 +144,5 @@ section of the project's `Cargo.toml` file, as noted in the | |
|
||
## Related Reading | ||
|
||
Please see | ||
https://github.com/viam-labs/micro-rdk-modular-driver-examples for | ||
another example of modular Micro-RDK sensors. | ||
Please see the [moisture sensor](src/moisture_sensor.rs) and [water pump](src/water_pump.rs) for | ||
more examples of modular Micro-RDK drivers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⬆️ - This still says
micro-rdk-esp32-sensor-examples
.