Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions r2r/src/action_servers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,21 +429,28 @@ where

fn handle_goal_expired(&mut self) {
let mut goal_info = WrappedNativeMsg::<action_msgs::msg::GoalInfo>::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)
};
if ret != RCL_RET_OK as i32 {
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);
}
Expand Down
1 change: 0 additions & 1 deletion r2r/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![allow(non_camel_case_types)]
use r2r_actions::*;
use r2r_rcl::*;
use thiserror::Error;

Expand Down
3 changes: 3 additions & 0 deletions r2r/src/msg_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>() -> Self
where
T: WrappedActionTypeSupport,
Expand Down
20 changes: 19 additions & 1 deletion r2r/src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl Node {

/// Creates a ROS node.
pub fn create(ctx: Context, name: &str, namespace: &str) -> Result<Node> {
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();
Expand All @@ -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 = {
Expand Down Expand Up @@ -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());
}
}
Expand Down
5 changes: 5 additions & 0 deletions r2r_rcl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
4 changes: 4 additions & 0 deletions r2r_rcl/src/rcl_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
// logging
#include <rcl/logging.h>

// 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 <rcl/logging_rosout.h>

// errors
#include <rcutils/error_handling.h>

Expand Down