Skip to content

Commit f3817fe

Browse files
committed
Add dynamic message functionality
1 parent 4956c31 commit f3817fe

25 files changed

+4261
-9
lines changed

examples/dynamic_pub_sub/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "dynamic_pub_sub"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
rclrs = { version = "0.3", features = ["dyn_msg"] }
10+
anyhow = {version = "1", features = ["backtrace"]}

examples/dynamic_pub_sub/src/main.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use anyhow::{Error, Result};
2+
use std::env;
3+
4+
fn main() -> Result<(), Error> {
5+
let context = rclrs::Context::new(env::args())?;
6+
7+
let mut node = rclrs::create_node(&context, "dynamic_subscriber")?;
8+
9+
let mut num_messages: usize = 0;
10+
11+
let _subscription = node.create_dynamic_subscription(
12+
"topic",
13+
"rclrs_example_msgs/msg/VariousTypes",
14+
rclrs::QOS_PROFILE_DEFAULT,
15+
move |msg| {
16+
num_messages += 1;
17+
println!("I heard: '{:#?}'", msg.structure());
18+
},
19+
)?;
20+
21+
rclrs::spin(&node).map_err(|err| err.into())
22+
}

rclrs/Cargo.toml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ path = "src/lib.rs"
1414
# Please keep the list of dependencies alphabetically sorted,
1515
# and also state why each dependency is needed.
1616
[dependencies]
17+
# Needed for dynamically finding type support libraries
18+
ament_rs = { version = "0.2", optional = true }
19+
# Needed for clients
20+
futures = "0.3"
21+
# Needed for dynamic messages
22+
libloading = { version = "0.7", optional = true }
1723
# Needed for FFI
1824
libc = "0.2.43"
1925
# Needed for the Message trait, among others
2026
rosidl_runtime_rs = "0.3"
21-
# Needed for clients
22-
futures = "0.3"
2327

2428
[dev-dependencies]
2529
# Needed for e.g. writing yaml files in tests
@@ -28,3 +32,7 @@ tempfile = "3.3.0"
2832
[build-dependencies]
2933
# Needed for FFI
3034
bindgen = "0.59.1"
35+
36+
[features]
37+
default = ["dyn_msg"]
38+
dyn_msg = ["ament_rs", "libloading"]

rclrs/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@ fn main() {
2727
.allowlist_type("rcl_.*")
2828
.allowlist_type("rmw_.*")
2929
.allowlist_type("rcutils_.*")
30+
.allowlist_type("rosidl_.*")
3031
.allowlist_function("rcl_.*")
3132
.allowlist_function("rmw_.*")
3233
.allowlist_function("rcutils_.*")
34+
.allowlist_function("rosidl_.*")
3335
.allowlist_var("rcl_.*")
3436
.allowlist_var("rmw_.*")
3537
.allowlist_var("rcutils_.*")
38+
.allowlist_var("rosidl_.*")
3639
.layout_tests(false)
3740
.size_t_is_usize(true)
3841
.default_enum_style(bindgen::EnumVariation::Rust {

0 commit comments

Comments
 (0)