"Native" publishers

This commit is contained in:
Martin Dahl 2019-08-20 13:43:33 +02:00
parent 05959d1fe8
commit f427e06b02
3 changed files with 21 additions and 1 deletions

View File

@ -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 <https://github.com/ros2-rust/ros2_rust>. 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 <https://github.com/ros2-rust/ros2_rust>. 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
------------

View File

@ -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::<JointTrajectoryPoint>(&mut node, "/hej")?;
let publisher2 = rcl_create_publisher::<Int32>(&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::<Int32>::new();
native.data = c;
publish(&publisher, &to_send).unwrap();
publish_native(&publisher2, &native).unwrap();
};
let cb2 = move |x:JointTrajectoryPoint| {

View File

@ -240,6 +240,19 @@ where
}
}
pub fn publish_native<T>(publisher: &rcl_publisher_t, msg: &WrappedNativeMsg<T>) -> 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<T>(
node: &mut rcl_node_t,
topic: &str,