From c87886296676ddd28eff9213d3b09370cbd11bd3 Mon Sep 17 00:00:00 2001 From: haixuanTao Date: Thu, 25 Jan 2024 13:52:33 +0100 Subject: [PATCH 1/2] Use forward slash as it is default way of defining ros2 topic --- examples/python-ros2-dataflow/random_turtle.py | 6 ++---- libraries/extensions/ros2-bridge/python/src/lib.rs | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/examples/python-ros2-dataflow/random_turtle.py b/examples/python-ros2-dataflow/random_turtle.py index 3e97228b5..e6fa2c75f 100755 --- a/examples/python-ros2-dataflow/random_turtle.py +++ b/examples/python-ros2-dataflow/random_turtle.py @@ -21,14 +21,12 @@ # Create a publisher to cmd_vel topic turtle_twist_topic = ros2_node.create_topic( - "/turtle1/cmd_vel", "geometry_msgs::Twist", topic_qos + "/turtle1/cmd_vel", "geometry_msgs/Twist", topic_qos ) twist_writer = ros2_node.create_publisher(turtle_twist_topic) # Create a listener to pose topic -turtle_pose_topic = ros2_node.create_topic( - "/turtle1/pose", "turtlesim::Pose", topic_qos -) +turtle_pose_topic = ros2_node.create_topic("/turtle1/pose", "turtlesim/Pose", topic_qos) pose_reader = ros2_node.create_subscription(turtle_pose_topic) # Create a dora node diff --git a/libraries/extensions/ros2-bridge/python/src/lib.rs b/libraries/extensions/ros2-bridge/python/src/lib.rs index 9d06bbaf5..f072ceb88 100644 --- a/libraries/extensions/ros2-bridge/python/src/lib.rs +++ b/libraries/extensions/ros2-bridge/python/src/lib.rs @@ -101,7 +101,7 @@ impl Ros2Node { message_type: String, qos: qos::Ros2QosPolicies, ) -> eyre::Result { - let (namespace_name, message_name) = message_type.split_once("::").with_context(|| { + let (namespace_name, message_name) = message_type.split_once("/").with_context(|| { format!( "message type must be of form `package::type`, is `{}`", message_type From e12b29dcc6b16aba72b0a33db6cd5d7bf1aba3db Mon Sep 17 00:00:00 2001 From: haixuanTao Date: Fri, 26 Jan 2024 09:57:00 +0100 Subject: [PATCH 2/2] Make type setting available for both forward slash and `::` --- libraries/extensions/ros2-bridge/python/src/lib.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libraries/extensions/ros2-bridge/python/src/lib.rs b/libraries/extensions/ros2-bridge/python/src/lib.rs index f072ceb88..c9492dcab 100644 --- a/libraries/extensions/ros2-bridge/python/src/lib.rs +++ b/libraries/extensions/ros2-bridge/python/src/lib.rs @@ -101,12 +101,13 @@ impl Ros2Node { message_type: String, qos: qos::Ros2QosPolicies, ) -> eyre::Result { - let (namespace_name, message_name) = message_type.split_once("/").with_context(|| { - format!( - "message type must be of form `package::type`, is `{}`", - message_type - ) - })?; + let (namespace_name, message_name) = + match (message_type.split_once("/"), message_type.split_once("::")) { + (Some(msg), None) => msg, + (None, Some(msg)) => msg, + _ => eyre::bail!("Expected message type in the format `namespace/message` or `namespace::message`, such as `std_msgs/UInt8` but got: {}", message_type), + }; + let message_type_name = ros2_client::MessageTypeName::new(namespace_name, message_name); let topic_name = ros2_client::Name::parse(name) .map_err(|err| eyre!("failed to parse ROS2 topic name: {err}"))?;