Robotics StackExchange | Archived questions

How to publish and visualise a constantly updated MarkerArray in Rviz?

When publishing markers to visualise, RViz gives the following warning:

Adding marker '/some_id_number' multiple times.

The function I use to publish the marker array is called lots of times in a callback used to respond to some data input. I'm therefore constantly publishing a new MarkerArray with one more marker in it. The function is defined as:

def pub_marker(self, pose):
    self.marker_counter = self.marker_counter + 1
    self.marker.header.stamp = rospy.Time(0)
    self.marker.id = self.marker_counter
    self.marker.action = self.detector_marker.MODIFY
    self.marker.pose.position.x = pose.pose.position.x
    self.marker.pose.position.y = pose.pose.position.y
    self.marker.pose.position.z = 0
    self.marker.pose.orientation = pose.pose.orientation
    self.marker.color.a = 1
    self.marker_array.markers.append(self.marker)
    self.marker_publisher.publish(self.marker_array)

Could anyone suggest what I'm doing wrong or suggest a better approach? Seems like I need to clear the previously published MarkerArray before publishing a new one. How might I do this?

Asked by Py on 2021-03-17 06:13:31 UTC

Comments

Answers