Skip to content

Commit

Permalink
Merge pull request #419 from dora-rs/ros2-forward-slash
Browse files Browse the repository at this point in the history
Use forward slash as it is default way of defining ros2 topic
  • Loading branch information
haixuanTao authored Jan 26, 2024
2 parents c417aa4 + e12b29d commit 8082739
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
6 changes: 2 additions & 4 deletions examples/python-ros2-dataflow/random_turtle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions libraries/extensions/ros2-bridge/python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,13 @@ impl Ros2Node {
message_type: String,
qos: qos::Ros2QosPolicies,
) -> eyre::Result<Ros2Topic> {
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}"))?;
Expand Down

0 comments on commit 8082739

Please sign in to comment.