0
$\begingroup$

Rosanswers logo

I am trying to create two markers and add them to a MarkerArray and then publish it. However, only the last marker shows up. Any help with this is much appreciated!

pub = rospy.Publisher('site_markers', MarkerArray, queue_size=10)
rospy.init_node('mission_manager')

markerArray = MarkerArray
  
marker1 = Marker()
marker1.header.stamp = rospy.Time.now()
marker1.header.frame_id = "/vicon"
marker1.type = marker1.CYLINDER
marker1.action = marker1.ADD
marker1.pose.position.x = -9
marker1.pose.position.y = 0
marker1.pose.position.z = 0
marker1.scale.x = 1.0
marker1.scale.y = 1.0
marker1.scale.z = 0.01
marker1.color.r = 1.0
marker1.color.g = 0
marker1.color.b = 0
marker1.color.a = 0.7
marker1.lifetime = rospy.Duration.from_sec(0)
marker1.frame_locked = 0
markerArray.markers.append(marker1)

marker2 = Marker()
marker2.header.stamp = rospy.Time.now()
marker2.header.frame_id = "/vicon"
marker2.type = marker2.CYLINDER
marker2.action = marker2.ADD
marker2.pose.position.x = -5
marker2.pose.position.y = 4
marker2.pose.position.z = 0
marker2.scale.x = 1.0
marker2.scale.y = 1.0
marker2.scale.z = 0.01
marker2.color.r = 1.0
marker2.color.g = 0
marker2.color.b = 0
marker2.color.a = 0.7
marker2.lifetime = rospy.Duration.from_sec(0)
marker2.frame_locked = 0
markerArray.markers.append(marker2)

while not rospy.is_shutdown():
    pub.publish(markerArray)

Also when I do rostopic echo on the topic, it shows both markers being published, so that confused me as well.


Originally posted by Thalaiva on ROS Answers with karma: 15 on 2016-06-13

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

You're not setting the id field (see docs/api/visualization_msgs/Marker), so it will default to 0 and makes both your markers use the same id. RViz receives a message containing a marker with the same id, and interprets it as an 'update' to the same marker it saw before. Result: you see only a single marker.


Originally posted by gvdhoorn with karma: 86574 on 2016-06-13

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by Thalaiva on 2016-06-13:
This fixed it, thank you!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.