ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org

# rviz not clearing markers after lifetime

Hi everyone,

I'm trying to display objects' velocities that I get from a radar sensor at a rate of 5Hz as a visualization_msgs::MarkerArray of visualization_msgs::Marker::ARROW. Basically I receive the point cloud, I cluster it and then I calcule the average velocity of each cluster. The markers work well (I can see they are well oriented and I set the length of the arrow based on the speed of the cluster). I set the markers lifetime to be 0.2 s, but markers are not cleared unless I publish a new one with the same id (which implicitly deletes the previous one, I think). The thing is that I cannot know how many markers I will publish in each frame because that depends on the objects present in the scene, so I'd like to rely on the lifetime attribute to clear the markers.

I've seen this question that is quite related but does not provide a solution. It does remark the fact that the countdown resets everytime a marker with the same id is published, but that should not bother me, I suppose, as if I publish a new velocity with an id it will indeed delete the last one. It is mainly when there are no dynamic objects in the scene that the arrows remain (even though they have a certain lifetime). Any suggestions on this problem? I leave an snipet of my code where I create the markers (I create an arrow for each cluster and velocities is my visualization_msgs::MarkerArray):

 ...
// Cluster velocity
temp_vel = temp_vel/j;

if (std::abs(temp_vel) > 0.05)
{
Eigen::Vector4f min, max;
pcl::getMinMax3D(*pcloud_mrg, *it, min, max);

centroid.x = (max(0) + min(0))/2;
centroid.y = (max(1) + min(1))/2;
centroid.z = (max(2) + min(2))/2;

Eigen::VectorXf temp_vec(3);
temp_vec(0) = centroid.x;
temp_vec(1) = centroid.y;
temp_vec(2) = centroid.z;
float norm = temp_vec.norm();

visualization_msgs::Marker m;
m.id = id;
m.type = visualization_msgs::Marker::ARROW;

m.color.a = 0.5;
m.color.r = 0.0;
m.color.g = 0.0;
m.color.b = 0.0;

m.scale.x = 0.02;
m.scale.y = 0.04;
m.scale.z = 0.02;

m.points.push_back(centroid);

velocities.markers.push_back(m);

}
id++;
...


Don't know if it is relevant but I'm running ROS Kinetic on Ubuntu 16.04

edit retag close merge delete

1

Do you clear the vector velocities.markers at some point ? If not you do have a different id for each marker but you still publish the previous ones since push_back simply add the new markers at the end of the vector. Moreover if you publish the markers at the rate of your sensor (5Hz which means every 0.2 second then you won't be able to see if the markers have been deleted.

( 2020-02-12 08:36:31 -0600 )edit

I cannot believe I lost so much time on this! I didn't pay attention to that, now it is working just fine! Thank you a lot

( 2020-02-12 08:45:17 -0600 )edit

( 2020-02-12 08:52:34 -0600 )edit

It was solved by clearing the vector before adding the new frame's velocities (velocities.markers.clear()). I did not understand why would the lifetime set to 0.2s be an issue (as I know I'll receive new a new pointcloud at 0.2s I want old markers to be cleared at that same rate), could you tell me if I'm missing something here?

( 2020-02-12 09:08:56 -0600 )edit

That was a guess but as you pointed from another question :

The countdown resets if another marker of the same namespace/id is received.

Not sure if the lack of namespace imply that the reset only rely on the id. If it's not the case, they (hypothetically) share the same namespace (nothing) so all the countdowns would be reset every 0.2 sec.

( 2020-02-12 09:21:39 -0600 )edit

Sort by » oldest newest most voted

As @Delb pointed out, I was not clearing velocities.markers vector but just adding markers to it. A simple velocities.markers.clear() before adding new velocities solved the problem!

more