ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Tutorials-Markers: Do not overwrite last marker

asked 2016-04-30 02:47:49 -0500

user23fj239 gravatar image

updated 2016-04-30 03:16:20 -0500

I try to have mulitple markers via several publishes and then let them fade away if their lifetime is over. Unfortune if I publish a new marker the old marker disappears before its lifetime is up.
I did the basic tutorial on markers, but what bugs me is this line

If a new marker message is received before the lifetime has been reached, the lifetime will be reset to the value in the new marker message.

How do I add another marker on the same topic but not overwrite the marker from the previous publish.

  59     marker.action = visualization_msgs::Marker::ADD;

Above action should add but the default behaviour (I guess is), create the marker if not already there, if its already displayed in rviz then overwrite the last one. How to prevent overwriting. Could someone confirm there is no other way than needing a message array or another solution multiple topics

When using an array it also only displays the last marker of the array:

    visualization_msgs::MarkerArray marker_array;
for(int i=0; i<2; i++) {
    make_markerf(marker_array.markers[i], frame_ids[i], pars[i]);

with this function making the markers:

void make_markerf(visualization_msgs::Marker &marker,  std::basic_string<char> frame_id, double *pars){
marker.header.frame_id = frame_id;
marker.header.stamp = ros::Time::now();
marker.ns = "sensor_processor"; = 2;

marker.pose.position.x = pars[0];
marker.pose.position.y = pars[1];
marker.pose.position.z = pars[2];
marker.pose.orientation.x = pars[3];
marker.pose.orientation.y = pars[4];
marker.pose.orientation.z = pars[5];
marker.pose.orientation.w = pars[6];
marker.scale.x = pars[7];
marker.scale.y = pars[8];
marker.scale.z = pars[9];
marker.color.r = pars[10];
marker.color.g = pars[11];
marker.color.b = pars[12];
marker.color.a = pars[13];
marker.type = pars[14];
marker.action = pars[15]; //always 0
marker.lifetime = ros::Duration(pars[16],pars[17]); //tried 0, and 10,0


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-04-30 03:32:09 -0500

user23fj239 gravatar image

Argl, beginner mistake, this answer helped me out. I need to assign a different id for every marker in the array. = 2; //needs to be 0 1
edit flag offensive delete link more

Question Tools

1 follower


Asked: 2016-04-30 02:47:49 -0500

Seen: 5,581 times

Last updated: Apr 30 '16