diff --git a/README.md b/README.md index af5a100..5f04345 100644 --- a/README.md +++ b/README.md @@ -5,14 +5,15 @@ Minimal bindings for ROS2 that do *not* require hooking in to the ROS2 build inf How to use -------------------- -1. Depend on this package: r2r = { git = "https://github.com/sequenceplanner/r2r" }. -2. You need to source your ROS2 installation before building/running. -3. The bindings will rebuild automatically if/when you source your workspace(s). -4. If you make changes to existing message types, run cargo clean -p msg_gen to force recompilation of the rust message types on the next build. +1. Make sure you have libclang installed. (e.g. libclang-dev on ubuntu) +2. Depend on this package: r2r = { git = "https://github.com/sequenceplanner/r2r" }. +3. You need to source your ROS2 installation before building/running. +4. The bindings will rebuild automatically if/when you source your workspace(s). +5. If you make changes to existing message types, run cargo clean -p msg_gen to force recompilation of the rust message types on the next build. A couple of examples are included in examples/ ``` -. /opt/ros/eloquent/setup.sh +. /opt/ros/foxy/setup.sh cargo build cargo run --example subscriber_with_thread ``` @@ -20,7 +21,7 @@ An example application can be found here Vec { if let Some(file_name_str) = file_name.to_str() { let substr = &l[4..l.len()-4]; let srv_name = format!("{}/srv/{}", file_name_str, substr); - println!("srv_name: {}", srv_name); msgs.push(srv_name); } } @@ -85,9 +84,15 @@ fn test_msg_list() { pub fn parse_msgs(msgs: &Vec) -> Vec { let v: Vec> = msgs.iter().map(|l| l.split("/").into_iter().take(3).collect()).collect(); - v.iter().filter(|v|v.len() == 3). - map(|v| RosMsg { module: v[0].into(), prefix: v[1].into(), name: v[2].into()}).collect() + let v: Vec<_> = v.iter().filter(|v|v.len() == 3). + map(|v| RosMsg { module: v[0].into(), prefix: v[1].into(), name: v[2].into()}).collect(); + // hack because I don't have time to find out the root cause of this at the moment. + // for some reason the library files generated to this are called + // liblibstatistics_collector_test_msgs__..., but I don't know where test_msgs come from. + // (this seems to be a useless package anyway) + // also affects message generation below. + v.into_iter().filter(|v| v.module != "libstatistics_collector").collect() } pub fn as_map(included_msgs: &[RosMsg]) -> HashMap<&str, HashMap<&str, Vec<&str>>> { diff --git a/msg_gen/build.rs b/msg_gen/build.rs index 84017a0..4137c8a 100644 --- a/msg_gen/build.rs +++ b/msg_gen/build.rs @@ -44,7 +44,7 @@ fn main() { &msg.module, &msg.prefix, &include_filename )); includes.push_str(&format!( - "#include <{}/{}/{}__rosidl_typesupport_introspection_c.h>\n", + "#include <{}/{}/detail/{}__rosidl_typesupport_introspection_c.h>\n", &msg.module, &msg.prefix, &include_filename )); @@ -78,27 +78,27 @@ fn main() { // blacklist types that are handled by rcl bindings .blacklist_type("rosidl_message_type_support_t") .blacklist_type("rosidl_service_type_support_t") - .blacklist_type("rosidl_generator_c__String") - .blacklist_type("rosidl_generator_c__String__Sequence") - .blacklist_type("rosidl_generator_c__U16String") - .blacklist_type("rosidl_generator_c__U16String__Sequence") - .blacklist_type("rosidl_generator_c__float32__Sequence") - .blacklist_type("rosidl_generator_c__float__Sequence") - .blacklist_type("rosidl_generator_c__float64__Sequence") - .blacklist_type("rosidl_generator_c__double__Sequence") - .blacklist_type("rosidl_generator_c__long_double__Sequence") - .blacklist_type("rosidl_generator_c__char__Sequence") - .blacklist_type("rosidl_generator_c__wchar__Sequence") - .blacklist_type("rosidl_generator_c__boolean__Sequence") - .blacklist_type("rosidl_generator_c__octet__Sequence") - .blacklist_type("rosidl_generator_c__uint8__Sequence") - .blacklist_type("rosidl_generator_c__int8__Sequence") - .blacklist_type("rosidl_generator_c__uint16__Sequence") - .blacklist_type("rosidl_generator_c__int16__Sequence") - .blacklist_type("rosidl_generator_c__uint32__Sequence") - .blacklist_type("rosidl_generator_c__int32__Sequence") - .blacklist_type("rosidl_generator_c__uint64__Sequence") - .blacklist_type("rosidl_generator_c__int64__Sequence") + .blacklist_type("rosidl_runtime_c__String") + .blacklist_type("rosidl_runtime_c__String__Sequence") + .blacklist_type("rosidl_runtime_c__U16String") + .blacklist_type("rosidl_runtime_c__U16String__Sequence") + .blacklist_type("rosidl_runtime_c__float32__Sequence") + .blacklist_type("rosidl_runtime_c__float__Sequence") + .blacklist_type("rosidl_runtime_c__float64__Sequence") + .blacklist_type("rosidl_runtime_c__double__Sequence") + .blacklist_type("rosidl_runtime_c__long_double__Sequence") + .blacklist_type("rosidl_runtime_c__char__Sequence") + .blacklist_type("rosidl_runtime_c__wchar__Sequence") + .blacklist_type("rosidl_runtime_c__boolean__Sequence") + .blacklist_type("rosidl_runtime_c__octet__Sequence") + .blacklist_type("rosidl_runtime_c__uint8__Sequence") + .blacklist_type("rosidl_runtime_c__int8__Sequence") + .blacklist_type("rosidl_runtime_c__uint16__Sequence") + .blacklist_type("rosidl_runtime_c__int16__Sequence") + .blacklist_type("rosidl_runtime_c__uint32__Sequence") + .blacklist_type("rosidl_runtime_c__int32__Sequence") + .blacklist_type("rosidl_runtime_c__uint64__Sequence") + .blacklist_type("rosidl_runtime_c__int64__Sequence") .default_enum_style(bindgen::EnumVariation::Rust { non_exhaustive: false, }); diff --git a/rcl/build.rs b/rcl/build.rs index fe5f727..a9848cc 100644 --- a/rcl/build.rs +++ b/rcl/build.rs @@ -30,7 +30,7 @@ fn main() { println!("cargo:rustc-link-lib=dylib=rmw"); println!("cargo:rustc-link-lib=dylib=rmw_implementation"); println!("cargo:rustc-link-lib=dylib=rosidl_typesupport_c"); - println!("cargo:rustc-link-lib=dylib=rosidl_generator_c"); + println!("cargo:rustc-link-lib=dylib=rosidl_runtime_c"); let bindings = builder.generate().expect("Unable to generate bindings"); diff --git a/rcl/src/lib.rs b/rcl/src/lib.rs index d6063ba..334e8ea 100644 --- a/rcl/src/lib.rs +++ b/rcl/src/lib.rs @@ -11,6 +11,8 @@ use std::ffi::CString; impl Default for rmw_message_info_t { fn default() -> Self { rmw_message_info_t { + source_timestamp: 0, + received_timestamp: 0, publisher_gid: rmw_gid_t { implementation_identifier: std::ptr::null(), data: [0; 24], @@ -39,7 +41,7 @@ impl Default for rmw_qos_profile_t { // special treatment to convert to/from rust strings. // ros strings are owned by ros, assignment is a copy -impl rosidl_generator_c__String { +impl rosidl_runtime_c__String { pub fn to_str(&self) -> &str { let s = unsafe { CStr::from_ptr(self.data as *mut i8) }; s.to_str().unwrap_or("") @@ -49,13 +51,13 @@ impl rosidl_generator_c__String { let q = CString::new(other).unwrap(); let to_send_ptr = q.as_ptr() as *const i8; unsafe { - rosidl_generator_c__String__assign(self as *mut _, to_send_ptr); + rosidl_runtime_c__String__assign(self as *mut _, to_send_ptr); } } } use widestring::U16String; -impl rosidl_generator_c__U16String { +impl rosidl_runtime_c__U16String { pub fn to_str(&self) -> String { let s = unsafe { U16String::from_ptr(self.data, self.size) }; // U16Str = U16String::from_ptr(buffer, strlen as usize); @@ -68,15 +70,15 @@ impl rosidl_generator_c__U16String { let wstr = U16String::from_str(other); let to_send_ptr = wstr.as_ptr() as *const uint_least16_t; unsafe { - rosidl_generator_c__U16String__assignn(self as *mut _, to_send_ptr, wstr.len()); + rosidl_runtime_c__U16String__assignn(self as *mut _, to_send_ptr, wstr.len()); } } } -impl rosidl_generator_c__U16String__Sequence { +impl rosidl_runtime_c__U16String__Sequence { pub fn update(&mut self, values: &[String]) { - unsafe { rosidl_generator_c__U16String__Sequence__fini(self as *mut _); } - unsafe { rosidl_generator_c__U16String__Sequence__init(self as *mut _, values.len()); } + unsafe { rosidl_runtime_c__U16String__Sequence__fini(self as *mut _); } + unsafe { rosidl_runtime_c__U16String__Sequence__init(self as *mut _, values.len()); } let strs = unsafe { std::slice::from_raw_parts_mut(self.data, values.len()) }; for (target, source) in strs.iter_mut().zip(values) { target.assign(&source); @@ -93,10 +95,10 @@ impl rosidl_generator_c__U16String__Sequence { } } -impl rosidl_generator_c__String__Sequence { +impl rosidl_runtime_c__String__Sequence { pub fn update(&mut self, values: &[String]) { - unsafe { rosidl_generator_c__String__Sequence__fini(self as *mut _); } - unsafe { rosidl_generator_c__String__Sequence__init(self as *mut _, values.len()); } + unsafe { rosidl_runtime_c__String__Sequence__fini(self as *mut _); } + unsafe { rosidl_runtime_c__String__Sequence__init(self as *mut _, values.len()); } let strs = unsafe { std::slice::from_raw_parts_mut(self.data, values.len()) }; for (target, source) in strs.iter_mut().zip(values) { target.assign(&source); @@ -136,18 +138,18 @@ macro_rules! primitive_sequence { } } -primitive_sequence!(rosidl_generator_c__float32, f32); -primitive_sequence!(rosidl_generator_c__float64, f64); -primitive_sequence!(rosidl_generator_c__long_double, u128); -primitive_sequence!(rosidl_generator_c__char, i8); -primitive_sequence!(rosidl_generator_c__wchar, u16); -primitive_sequence!(rosidl_generator_c__boolean, bool); -primitive_sequence!(rosidl_generator_c__octet, u8); -primitive_sequence!(rosidl_generator_c__uint8, u8); -primitive_sequence!(rosidl_generator_c__int8, i8); -primitive_sequence!(rosidl_generator_c__uint16, u16); -primitive_sequence!(rosidl_generator_c__int16, i16); -primitive_sequence!(rosidl_generator_c__uint32, u32); -primitive_sequence!(rosidl_generator_c__int32, i32); -primitive_sequence!(rosidl_generator_c__uint64, u64); -primitive_sequence!(rosidl_generator_c__int64, i64); +primitive_sequence!(rosidl_runtime_c__float32, f32); +primitive_sequence!(rosidl_runtime_c__float64, f64); +primitive_sequence!(rosidl_runtime_c__long_double, u128); +primitive_sequence!(rosidl_runtime_c__char, i8); +primitive_sequence!(rosidl_runtime_c__wchar, u16); +primitive_sequence!(rosidl_runtime_c__boolean, bool); +primitive_sequence!(rosidl_runtime_c__octet, u8); +primitive_sequence!(rosidl_runtime_c__uint8, u8); +primitive_sequence!(rosidl_runtime_c__int8, i8); +primitive_sequence!(rosidl_runtime_c__uint16, u16); +primitive_sequence!(rosidl_runtime_c__int16, i16); +primitive_sequence!(rosidl_runtime_c__uint32, u32); +primitive_sequence!(rosidl_runtime_c__int32, i32); +primitive_sequence!(rosidl_runtime_c__uint64, u64); +primitive_sequence!(rosidl_runtime_c__int64, i64); diff --git a/rcl/src/rcl_wrapper.h b/rcl/src/rcl_wrapper.h index 7ae661a..14dd4aa 100644 --- a/rcl/src/rcl_wrapper.h +++ b/rcl/src/rcl_wrapper.h @@ -8,16 +8,16 @@ #include // low level msg type handling -#include -#include +#include +#include -#include -#include +#include +#include -#include -#include +#include +#include -#include +#include #include #include