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

How to know from where to import and the message type?

asked 2016-11-28 20:53:55 -0600

kapoor_amita gravatar image

I am new to ROS, wanted to experiment with publishing and subscribing. The basic codes available are easy to run. Now let us say I have downloaded a package, My_Pkg, in its msg folder there is a file my_msg.msg where they have defined a message by name MSG.

My question is how do i publish or subscribe for this message: The simple statement : pub=rospy.Publisher('topic_name', MSG) Results in error that MSG is not defined. If I import: from My_Pkg.MSG import MSG Still error no module named Console.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2016-11-28 21:00:35 -0600

kapoor_amita gravatar image

Solved it: First Run rosmsg list, it will list all the messages, choose the one you were looking for so in above case it is simply: from my_pkg.msg import MSG and it works

edit flag offensive delete link more
0

answered 2023-01-06 11:47:40 -0600

peci1 gravatar image

With our cras_py_common library, it's actually quite easy:

from cras import get_msg_type
t = get_msg_type("sensor_msgs/Image")
print(t)
# prints <class 'sensor_msgs.msg._Image.Image'>

Install via sudo apt install ros-${ROS_DISTRO}-cras-py-common.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-11-28 20:53:55 -0600

Seen: 117 times

Last updated: Jan 06 '23