Skip to content

Commit

Permalink
Add rosout logging to rclrs (#422)
Browse files Browse the repository at this point in the history
* Initial logging implementation

* * Moved logging_fini to follow correct call sequence based on rclcpp

* Primary change to fix builder's node variable going out of scope

* Fix linting issue with use statement

* Remove the need to Box rcl_node_t (#5)

Signed-off-by: Michael X. Grey <[email protected]>

* Fix linting issues

* Fix logging lifecycles and clean up tests

Signed-off-by: Michael X. Grey <[email protected]>

* Linting fixes after logging lifecycle improvements

* Introduce Logger and LogParams

Signed-off-by: Michael X. Grey <[email protected]>

* Cleaner logging tests

Signed-off-by: Michael X. Grey <[email protected]>
Signed-off-by: Michael X. Grey <[email protected]>
Signed-off-by: Michael X. Grey <[email protected]>
Co-authored-by: Nathan Wiebe Neufeldt <[email protected]>

* Address feedback for logging PR

Signed-off-by: Michael X. Grey <[email protected]>
Signed-off-by: Michael X. Grey <[email protected]>
Signed-off-by: Michael X. Grey <[email protected]>
Co-authored-by: Nathan Wiebe Neufeldt <[email protected]>

---------

Signed-off-by: Michael X. Grey <[email protected]>
Signed-off-by: Michael X. Grey <[email protected]>
Signed-off-by: Michael X. Grey <[email protected]>
Co-authored-by: Grey <[email protected]>
Co-authored-by: Nathan Wiebe Neufeldt <[email protected]>
  • Loading branch information
3 people authored Nov 24, 2024
1 parent 066dd7c commit 217f42c
Show file tree
Hide file tree
Showing 13 changed files with 1,479 additions and 35 deletions.
1 change: 1 addition & 0 deletions rclrs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ fn main() {
}
};

println!("cargo:rustc-check-cfg=cfg(ros_distro, values(\"humble\", \"iron\", \"jazzy\", \"rolling\"))");
println!("cargo:rustc-cfg=ros_distro=\"{ros_distro}\"");

let mut builder = bindgen::Builder::default()
Expand Down
17 changes: 16 additions & 1 deletion rclrs/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
vec::Vec,
};

use crate::{rcl_bindings::*, RclrsError, ToResult};
use crate::{rcl_bindings::*, LoggingLifecycle, RclrsError, ToResult};

/// This is locked whenever initializing or dropping any middleware entity
/// because we have found issues in RCL and some RMW implementations that
Expand Down Expand Up @@ -56,6 +56,10 @@ unsafe impl Send for rcl_context_t {}
/// - middleware-specific data, e.g. the domain participant in DDS
/// - the allocator used (left as the default by `rclrs`)
///
/// The context also configures the rcl_logging_* layer to allow publication to /rosout
/// (as well as the terminal). TODO: This behaviour should be configurable using an
/// "auto logging initialise" flag as per rclcpp and rclpy.
///
pub struct Context {
pub(crate) handle: Arc<ContextHandle>,
}
Expand All @@ -68,6 +72,10 @@ pub struct Context {
/// bindings in this library.
pub(crate) struct ContextHandle {
pub(crate) rcl_context: Mutex<rcl_context_t>,
/// This ensures that logging does not get cleaned up until after this ContextHandle
/// has dropped.
#[allow(unused)]
logging: Arc<LoggingLifecycle>,
}

impl Context {
Expand Down Expand Up @@ -143,9 +151,16 @@ impl Context {
// Move the check after the last fini()
ret?;
}

// TODO: "Auto set-up logging" is forced but should be configurable as per rclcpp and rclpy
// SAFETY: We created this context a moment ago and verified that it is valid.
// No other conditions are needed.
let logging = unsafe { LoggingLifecycle::configure(&rcl_context)? };

Ok(Self {
handle: Arc::new(ContextHandle {
rcl_context: Mutex::new(rcl_context),
logging,
}),
})
}
Expand Down
2 changes: 2 additions & 0 deletions rclrs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod clock;
mod context;
mod error;
mod executor;
mod logging;
mod node;
mod parameter;
mod publisher;
Expand Down Expand Up @@ -38,6 +39,7 @@ pub use clock::*;
pub use context::*;
pub use error::*;
pub use executor::*;
pub use logging::*;
pub use node::*;
pub use parameter::*;
pub use publisher::*;
Expand Down
Loading

0 comments on commit 217f42c

Please sign in to comment.