diff --git a/README.md b/README.md index 9bea3b4..742f906 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ R2R - Minimal ROS2 Rust bindings ============= -Minimal bindings for ROS2 that does *not* require hooking in to the ROS2 build infrastructure. If you want a more ROS-oriented approach, see . In these bindings, convenience Rust types are created by calling into the c introspection libraries to circumvent the .msg/.idl pipeline. Another benefit of basing the code entirely on the exported shared libraries is that the native c types are still there when you need to trade convenience for performance. E.g. for looking into a large array of image data you can still get a pointer to the raw message. +Minimal bindings for ROS2 that does *not* require hooking in to the ROS2 build infrastructure. If you want a more ROS-oriented approach, see . In these bindings, convenience Rust types are created by calling into the c introspection libraries to circumvent the .msg/.idl pipeline. The convenience types can of course be ignored when you need to trade convenience for performance, e.g. treating large chunks of data manually. How to use ------------ diff --git a/examples/publish_complex_msgs.rs b/examples/publish_complex_msgs.rs index 99c3c7b..a348c41 100644 --- a/examples/publish_complex_msgs.rs +++ b/examples/publish_complex_msgs.rs @@ -1,11 +1,14 @@ use r2r::*; use builtin_interfaces::msg::Duration; use trajectory_msgs::msg::*; +use std_msgs::msg::Int32; + fn main() -> Result<(), ()> { let mut ctx = rcl_create_context()?; let mut node = rcl_create_node(&mut ctx, "testnode", "")?; let publisher = rcl_create_publisher::(&mut node, "/hej")?; + let publisher2 = rcl_create_publisher::(&mut node, "/native_count")?; let mut c = 0; let cb = move |x:std_msgs::msg::String| { @@ -17,7 +20,11 @@ fn main() -> Result<(), ()> { time_from_start : Duration { sec: c, nanosec: 0 }, ..Default::default() }; + let mut native = WrappedNativeMsg::::new(); + native.data = c; + publish(&publisher, &to_send).unwrap(); + publish_native(&publisher2, &native).unwrap(); }; let cb2 = move |x:JointTrajectoryPoint| { diff --git a/src/lib.rs b/src/lib.rs index 4a442c4..67182da 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -240,6 +240,19 @@ where } } +pub fn publish_native(publisher: &rcl_publisher_t, msg: &WrappedNativeMsg) -> Result<(), ()> +where + T: WrappedTypesupport, +{ + let result = unsafe { rcl_publish(publisher, msg.void_ptr(), std::ptr::null_mut()) }; + if result == RCL_RET_OK as i32 { + Ok(()) + } else { + eprintln!("{}", result); + Err(()) + } +} + pub fn rcl_create_subscription( node: &mut rcl_node_t, topic: &str,