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,608 times
Last updated: Mar 17 '11
Any good examples of using dynamic_reconfigure for a python node?
how is rosh's ok() different from rospy.is_shutdown()?
Subscriber gets older timestamped messages
How can I use custom python functions in other ROS packages?
Do I need to know any specific computer language or framework to use ROS?
Is anybody in ROS community using PySide?
is there a python equivalent of fromROSMsg/toROSMsg (pcl stack)