Skip to content

Call "RMW-compatible" messages "RMW-native" instead #159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2022
Merged
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
8 changes: 4 additions & 4 deletions rclrs_examples/src/message_demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn demonstrate_printing() {
println!("{:?}", default_msg);
println!("================== Pretty debug representation ===================");
println!("{:#?}", default_msg);
// The RMW-compatible message type has the same output
// The RMW-native message type has the same output
let default_rmw_msg = rclrs_example_msgs::msg::rmw::VariousTypes::default();
assert_eq!(
format!("{:?}", default_msg),
Expand Down Expand Up @@ -111,7 +111,7 @@ fn demonstrate_sequences() {

fn demonstrate_pubsub() -> Result<(), Error> {
println!("================== Interoperability demo ==================");
// Demonstrate interoperability between idiomatic and RMW-compatible message types
// Demonstrate interoperability between idiomatic and RMW-native message types
let context = rclrs::Context::new(env::args())?;
let mut node = context.create_node("message_demo")?;

Expand All @@ -135,13 +135,13 @@ fn demonstrate_pubsub() -> Result<(), Error> {
"topic",
rclrs::QOS_PROFILE_DEFAULT,
move |_msg: rclrs_example_msgs::msg::rmw::VariousTypes| {
println!("Got RMW-compatible message!")
println!("Got RMW-native message!")
},
)?;
println!("Sending idiomatic message.");
idiomatic_publisher.publish(rclrs_example_msgs::msg::VariousTypes::default())?;
rclrs::spin_once(&node, None)?;
println!("Sending RMW-compatible message.");
println!("Sending RMW-native message.");
direct_publisher.publish(rclrs_example_msgs::msg::rmw::VariousTypes::default())?;
rclrs::spin_once(&node, None)?;

Expand Down
22 changes: 11 additions & 11 deletions rosidl_runtime_rs/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub trait SequenceAlloc: Sized {
fn sequence_copy(in_seq: &crate::Sequence<Self>, out_seq: &mut crate::Sequence<Self>) -> bool;
}

/// Trait for RMW-compatible messages.
/// Trait for RMW-native messages.
///
/// See the documentation for the [`Message`] trait, which is the trait that should generally be
/// used by user code.
Expand All @@ -46,22 +46,22 @@ pub trait RmwMessage: Clone + Debug + Default {
///
/// `rosidl_generator_rs` generates two types of messages that implement this trait:
/// - An "idiomatic" message type, in the `${package_name}::msg` module
/// - An "RMW-compatible" message type, in the `${package_name}::msg::rmw` module
/// - An "RMW-native" message type, in the `${package_name}::msg::rmw` module
///
/// # Idiomatic message type
/// The idiomatic message type aims to be familiar to Rust developers and ROS 2 developers coming
/// from `rclcpp`.
/// To this end, it translates the original ROS 2 message into a version that uses idiomatic Rust
/// structs: [`std::vec::Vec`] for sequences and [`std::string::String`] for strings. All other
/// fields are the same as in an RMW-compatible message.
/// fields are the same as in an RMW-native message.
///
/// This conversion incurs some overhead when reading and publishing messages.
///
/// It's possible to use the idiomatic type for a publisher and the RMW-compatible type for a
/// It's possible to use the idiomatic type for a publisher and the RMW-native type for a
/// corresponding subscription, and vice versa.
///
/// # RMW-compatible message type
/// The RMW-compatible message type aims to achieve higher performance by avoiding the conversion
/// # RMW-native message type
/// The RMW-native message type aims to achieve higher performance by avoiding the conversion
/// step to an idiomatic message.
///
/// It uses the following type mapping:
Expand All @@ -88,7 +88,7 @@ pub trait RmwMessage: Clone + Debug + Default {
/// iteration and all of the functionality of slices. However, it doesn't have an equivalent of
/// [`Vec::push()`], among others.
///
/// ## What does "RMW-compatible" mean in detail?
/// ## What does "RMW-native" mean in detail?
/// The message can be directly passed to and from the RMW layer because (1) its layout is
/// identical to the layout of the type generated by `rosidl_generator_c` and (2) the dynamic
/// memory inside the message is owned by the C allocator.
Expand Down Expand Up @@ -127,19 +127,19 @@ pub trait RmwMessage: Clone + Debug + Default {
/// The `Drop` impl for any sequence or string will call `fini()`.

pub trait Message: Clone + Debug + Default + 'static {
/// The corresponding RMW-compatible message type.
/// The corresponding RMW-native message type.
type RmwMsg: RmwMessage;

/// Converts the idiomatic message into an RMW-compatible message.
/// Converts the idiomatic message into an RMW-native message.
///
/// If the idiomatic message is owned, a slightly more efficient conversion is possible.
/// This is why the function takes a `Cow`.
///
/// If this function receives a borrowed message that is already RMW-compatible, it should
/// If this function receives a borrowed message that is already RMW-native, it should
/// directly return that borrowed message.
/// This is why the return type is also `Cow`.
fn into_rmw_message(msg_cow: Cow<'_, Self>) -> Cow<'_, Self::RmwMsg>;

/// Converts the RMW-compatible message into an idiomatic message.
/// Converts the RMW-native message into an idiomatic message.
fn from_rmw_message(msg: Self::RmwMsg) -> Self;
}