Skip to content

Commit 977259a

Browse files
committed
Add dynamic message functionality
1 parent ec85565 commit 977259a

28 files changed

+4250
-13
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.2", 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
@@ -13,12 +13,16 @@ path = "src/lib.rs"
1313
# Please keep the list of dependencies alphabetically sorted,
1414
# and also state why each dependency is needed.
1515
[dependencies]
16+
# Needed for dynamically finding type support libraries
17+
ament_rs = { version = "0.2", optional = true }
18+
# Needed for clients
19+
futures = "0.3"
20+
# Needed for dynamic messages
21+
libloading = { version = "0.7", optional = true }
1622
# Needed for FFI
1723
libc = "0.2.43"
1824
# Needed for the Message trait, among others
1925
rosidl_runtime_rs = "0.2.0"
20-
# Needed for clients
21-
futures = "0.3"
2226

2327
[dev-dependencies]
2428
# Needed for e.g. writing yaml files in tests
@@ -27,3 +31,7 @@ tempfile = "3.3.0"
2731
[build-dependencies]
2832
# Needed for FFI
2933
bindgen = "0.59.1"
34+
35+
[features]
36+
default = ["dyn_msg"]
37+
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)