ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
2

python rosmsg/rospack in ROS2

asked 2019-04-14 06:03:38 -0500

federico.ferri gravatar image

I have some python code using rosmsg and rospkg, i.e.

rospack = rospkg.RosPack()
lines = rosmsg.get_msg_text(msg_name, False, rospack)

how to do the same in ROS2 with rclpy?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2020-06-05 09:33:54 -0500

fferri gravatar image

Here's what I do:

from rosidl_runtime_py import get_interface_path
from rosidl_adapter.parser import parse_message_file
m = parse_message_file('std_msgs', get_interface_path('std_msgs/msg/Bool'))

it's actually better than what you do with RosPack as parse_message_file parses the lines for you and returns a nice object with all the info in it.

edit flag offensive delete link more
0

answered 2019-04-16 01:38:39 -0500

William gravatar image

Right now, you can use the public API for ros2 msg, which can locate the file for you:

https://github.com/ros2/ros2cli/blob/...

But then you'll need to open the file and read the contents for yourself.

Additionally, there should be a Python API which will parse the file for you and give you a Python object representation of it, part of rosidl_adapter.parser:

https://github.com/ros2/rosidl/blob/3...

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2019-04-14 06:03:38 -0500

Seen: 2,184 times

Last updated: Jun 05 '20