ros2_rust icon indicating copy to clipboard operation
ros2_rust copied to clipboard

support `rclrs::SerializedMessage`

Open fawdlstty opened this issue 2 years ago • 0 comments

Hi all,

In rosbag2, receiving topic messages of unknown types is achieved through type rclcpp::SerializedMessage, which is not effective in rust through type std_msgs::msg::ByteMultiArray. I hope to add support for type rclcpp::SerializedMessage, so that after specifying a topic, I can receive messages of any unknown type.

example code:

fn main() -> Result<(), rclrs::RclrsError> {
    let context = rclrs::Context::new(std::env::args())?;

    let node = rclrs::create_node(&context, "test_rosbag")?;

    let _subscription = node.create_subscription::<std_msgs::msg::ByteMultiArray, _>(
        "/odom",
        rclrs::QOS_PROFILE_DEFAULT,
        move |msg: rclrs::ReadOnlyLoanedMessage<'_, std_msgs::msg::ByteMultiArray>| {
            println!("I heard {} bytes", msg.data.len());
        },
    )?;

    rclrs::spin(node).map_err(|err| err.into())
}

then publish:

ros2 topic pub /odom std_msgs/String "{data: aabbcc}"

and then the node cannot received the message

fawdlstty avatar Aug 17 '23 09:08 fawdlstty