How to recieve an array over Publisher and Subscriber? (Python)
Examples would be useful.
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
Examples would be useful.
This tutorial might be what you're after. In general, arrays are not much different than anything else--you just need a msg that has an array in it. Suppose e.g. you have a message file, your_package/Foo.msg
:
int32[100] some_integers # array of 100 int32's
float64[] some_floats # variable-sized array of floats
Then a publisher would look like:
from your_package.msg import Foo
mypub = rospy.Publisher('mytopic', Foo)
msg_to_send = Foo()
msg_to_send.some_integers = range(100)
msg_to_send.some_floats = [1.0, -3.14, 42.0]
mypub.publish(msg_to_send)
A subscriber could look like:
from your_package.msg import Foo
def mytopic_callback(msg):
print "Here are some integers:", str(msg.some_integers)
print "Here are some floats:", str(msg.some_floats)
mysub = rospy.Subscriber('mytopic', Foo, mytopic_callback)
This isn't fully working code--you'll need to initialize the nodes, spin, etc but hopefully you get the idea.
@kk, @ctguell: this answer might help you guys: http://answers.ros.org/question/60614/how-to-publish-a-vector-of-unknown-length-of-structs-in-ros/
Asked: 2011-03-17 16:20:55 -0600
Seen: 30,350 times
Last updated: Mar 17 '11
How to block subscriber callback?
Start a node from python code - rospy equivalence rosrun - rosgui qt
rospy subscriber buffer length
Visualize collada file on rviz [closed]
Build C++ Library and use in Python Package (Node)
Python namespace ignored in MoveIt
catkin_make failure due to Python Anaconda
Rviz Marker LINE_STRIP is not displayed
Processing PoseStamped message as an integer (or something similar)