Ask Your Question
2

python rosmsg/rospack in ROS2

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

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 -0600

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 -0600

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

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

Seen: 432 times

Last updated: Jun 05