Append data to vector3[] array - custom message
Hey guys out there,
with lovely help of ROSanswers I got into creating and defining custom messages. My aim is to create a custom message which contains of an array of vector3(). I basically got a couple of points, which i want to publish in a single message.
So I created a custom message which looks like:
geometry_msgs/Vector3[] Vector3DArray
I was able to create a package with catkin and I'm able to use the message.
I got the following code:
...
from geometry_msgs.msg import Vector3
from vector_3_array.msg import Vector3DArray
...
self.stelldaten = rospy.Publisher('Stelldaten', Vector3DArray, queue_size=10)
self.vectordaten_tabelle = Vector3DArray()
...
vec3 = Vector3()
for i in range(0, self.anzahl_punkte):
print 'Vektor ' + str(i)
vec3.x = self.q1_v[i]
vec3.y = self.q2_v[i]
vec3.z = self.tges[i]
print vec3
self.vectordaten_tabelle.Vector3DArray.append(vec3)
print self.q1_v
print self.q2_v
print self.vectordaten_tabelle
self.stelldaten.publish(self.vectordaten_tabelle)
So the problem right now is, that self.vectordaten_tabelle has anzahl_punkte entries of vector3() (which is perfect), but each entry gets overridden by the last vec3 which is added. Just to show you an example:
The prints in the for loop show smth like this:
...
Vektor 11
x: -35.2332092159
y: 2.95642070607
z: 0.057369297869
Vektor 12
x: -29.4943008067
y: 3.36452718727
z: 0.0590352126953
Vektor 13
x: -29.4943008067
y: 3.36452718727
z: 0.0518744285557
Vektor 14
x: 0.0
y: 0.0
z: 0.0518744285557
But the self.vectordaten_tabelle looks like:
...
x: 0.0
y: 0.0
z: 0.0518744285557
-
x: 0.0
y: 0.0
z: 0.0518744285557
-
x: 0.0
y: 0.0
z: 0.0518744285557
-
x: 0.0
y: 0.0
z: 0.0518744285557
Does somebody now what exactly is going wrong here? Thanks alot in advance!