How to fill up a PointCloud Message with data in Python?
Hey guys,
I want to set up a PointCloud Message in my python main. I already read the docs: http://docs.ros.org/api/sensor_msgs/h... But I don't catch it. This is what I got so far (spread over the different classes):
import rospy
from geometry_msgs.msg import Point
from sensor_msgs.msg import PointCloud
self.stelldaten = self.rospy.Publisher('Stelldaten', PointCloud, queue_size=10)
rospy.init_node('LaserCutter GUI', anonymous=True)
try:
rospy.spin()
except KeyboardInterrupt:
print "Shutting Down"
I don't understand how to fill up the PointCloud with data. I googled quite a bit, but the most, if not all, examples are for C++. Can somebody enlighten me, please?
edit according to marguedas comment/answer:
I think i got the basic idea, the problem is that the program shuts down without any error which makes debugging quite hard. First of all, let me answer your questions. The points are generated in a Kivy based gui, so I basically got three arrays (one for x, one for y and one for the time - so I am using the z coordinate to transmit information about the time). The information i collect in the x and y vectors are speed values for a stepper motor. To conlude: for each point I have two speed values and one time value. I tryed to use the PointCloud, cause I don't like the way to publish matrices in ROS (at least so far...). The following shows the code i got so far (only the parts important for this specific problem):
import rospy
import std_msgs.msg
from geometry_msgs.msg import Point
from sensor_msgs.msg import PointCloud
class Lasercutter(TabbedPanel):
def __init__(self, **kwargs):
super(Lasercutter, self).__init__(**kwargs)
self.stelldaten = rospy.Publisher('Stelldaten', PointCloud, queue_size=10)
self.stelldaten_tabelle = PointCloud()
self.h = std_msgs.msg.Header()
self.h.stamp = rospy.Time.now()
def bahnberechnung(self):
anzahl_punkte = 10 # i got 10 points, for example
self.stelldaten_tabelle.header = self.h
self.stelldaten_tabelle.points = anzahl_punkte
self.stelldaten_tabelle.channels = 3
point = Point()
for i in range(0, anzahl_punkte):
point.x = self.q1_v[i]
point.y = self.q2_v[i]
point.z = self.tges[i]
self.stelldaten_tabelle.points[i] = point.x
self.stelldaten_tabelle.points[i] = point.y
self.stelldaten_tabelle.points[i] = point.z
self.stelldaten.publish(self.stelldaten_tabelle)
class TabbedPanelApp(App):
def build(self):
# diese Node arbeitet unter folgendem Namen
rospy.init_node('LaserCutterGUI', anonymous=True)
return Lasercutter()
if __name__ == '__main__':
TabbedPanelApp().run()
As I mentioned i get no errors, the program just gets killed (sometimes you can blame it on Kivy, but that doesnt help me to find the problem, right? :D). I get prints until the line : point = Point()
Thanks again for any advice, I really appreciate it!