diff --git a/r2r/src/action_servers.rs b/r2r/src/action_servers.rs index d9ecdf0e3..373262af6 100644 --- a/r2r/src/action_servers.rs +++ b/r2r/src/action_servers.rs @@ -429,9 +429,12 @@ where fn handle_goal_expired(&mut self) { let mut goal_info = WrappedNativeMsg::::new(); - let mut num_expired = 1; + let mut num_expired = 0; - while num_expired > 1 { + // Must run until nothing is left to expire: this call is what re-arms + // or cancels the expire timer, which otherwise stays ready and makes + // every rcl_wait return at once. + loop { let ret = unsafe { rcl_action_expire_goals(&self.rcl_handle, &mut *goal_info, 1, &mut num_expired) }; @@ -439,11 +442,15 @@ where log::debug!("action server: could not expire goal."); return; } + if num_expired == 0 { + return; + } let gi = action_msgs::msg::GoalInfo::from_native(&goal_info); let uuid = uuid_msg_to_uuid(&gi.goal_id); log::debug!("goal expired: {} - {}", uuid, num_expired); - // todo - // self.goals.remove(&uuid); + // rcl has freed the goal handle, so the pointer must go too. + self.goals.remove(&uuid); + self.cancel_senders.remove(&uuid); self.result_msgs.remove(&uuid); self.result_requests.remove(&uuid); } diff --git a/r2r/src/error.rs b/r2r/src/error.rs index 64b351b5e..e2da35f11 100644 --- a/r2r/src/error.rs +++ b/r2r/src/error.rs @@ -1,5 +1,4 @@ #![allow(non_camel_case_types)] -use r2r_actions::*; use r2r_rcl::*; use thiserror::Error; diff --git a/r2r/src/msg_types.rs b/r2r/src/msg_types.rs index 524dff0aa..dca8670de 100644 --- a/r2r/src/msg_types.rs +++ b/r2r/src/msg_types.rs @@ -281,6 +281,9 @@ pub struct UntypedActionSupport { } impl UntypedActionSupport { + // Only called from the generated `new_from`, whose body has no call sites when + // the workspace exposes no action types. + #[allow(dead_code)] fn new() -> Self where T: WrappedActionTypeSupport, diff --git a/r2r/src/nodes.rs b/r2r/src/nodes.rs index 11b78448e..2f209ae06 100644 --- a/r2r/src/nodes.rs +++ b/r2r/src/nodes.rs @@ -182,7 +182,7 @@ impl Node { /// Creates a ROS node. pub fn create(ctx: Context, name: &str, namespace: &str) -> Result { - let (res, node_handle) = { + let (res, mut node_handle) = { let mut ctx_handle = ctx.context_handle.lock().unwrap(); let c_node_name = CString::new(name).unwrap(); @@ -203,6 +203,20 @@ impl Node { }; if res == RCL_RET_OK as i32 { + // rcl_node_init() does not create the node's /rosout publisher -- + // the client library has to, exactly as rclcpp and rclpy do. Without + // this, rcl_logging_rosout_output_handler() finds no publisher + // registered for the node's logger name and silently drops every + // record, so logs only ever reach the console. + if unsafe { rcl_logging_rosout_enabled() } { + let ret = unsafe { rcl_logging_rosout_init_publisher_for_node(node_handle.as_mut()) }; + if ret != RCL_RET_OK as i32 { + log::error!("could not create /rosout publisher for node ({})", ret); + unsafe { rcl_node_fini(node_handle.as_mut()) }; + return Err(Error::from_rcl_error(ret)); + } + } + let ros_clock = Arc::new(Mutex::new(Clock::create(ClockType::RosTime)?)); #[cfg(r2r__rosgraph_msgs__msg__Clock)] let time_source = { @@ -1694,6 +1708,10 @@ impl Drop for Node { p.destroy(self.node_handle.as_mut()); } unsafe { + if rcl_logging_rosout_enabled() { + // Mirrors the init in Node::create; must happen before node_fini. + rcl_logging_rosout_fini_publisher_for_node(self.node_handle.as_mut()); + } rcl_node_fini(self.node_handle.as_mut()); } } diff --git a/r2r_rcl/src/lib.rs b/r2r_rcl/src/lib.rs index b55335fd0..b6a7648e8 100644 --- a/r2r_rcl/src/lib.rs +++ b/r2r_rcl/src/lib.rs @@ -7,6 +7,11 @@ // It could be good to still warn if building with an older rust version. #![allow(improper_ctypes)] #![allow(improper_ctypes_definitions)] +// bindgen derives PartialEq on structs holding C function pointers, which rustc +// >= 1.85 flags because function addresses are not guaranteed to be unique. The +// comparisons live in generated code we do not control, and nothing in r2r relies +// on them being meaningful. +#![allow(unpredictable_function_pointer_comparisons)] include!(concat!(env!("OUT_DIR"), "/rcl_bindings.rs")); use std::ffi::{CStr, CString}; diff --git a/r2r_rcl/src/rcl_wrapper.h b/r2r_rcl/src/rcl_wrapper.h index d72a24d43..52b32404d 100644 --- a/r2r_rcl/src/rcl_wrapper.h +++ b/r2r_rcl/src/rcl_wrapper.h @@ -14,6 +14,10 @@ // logging #include +// per-node /rosout publisher (rcl does not create it in rcl_node_init; +// the client library has to do it, like rclcpp/rclpy do) +#include + // errors #include