How to use use rviz_visual_tools deleteAllMarkers?

asked 2019-07-26 08:04:08 -0600

usamamaq gravatar image

updated 2019-07-26 08:05:25 -0600

Hello

I am publishing visualization_msgs::MarkerArray on a topic "/xyz" with frame_id "map" which is being displayed on rviz. But i want to delete previous MarkerArray before displaying new one. For that i am trying to use rviz_visual_tools. Here is my function which i want to do this task:

void Server::publishMarkerArray(const ros::Time& rostime, KeySet& c_Cells)
{
    visualization_msgs::Marker frontierNode;
    visualization_msgs::MarkerArray frontierNodesVis;
    geometry_msgs::Point32 candidate_center;

   // Delete previous markers before new one
    rviz_visual_tools::RvizVisualTools rviz("map", "/xyz");
    rviz.deleteAllMarkers();

   // Make new Markers
    for (KeySet::iterator iter= c_Cells.begin(), end=c_Cells.end(); iter !=end; ++iter)
    {
        octomap::point3d f_can_point;
        f_can_point = m_octree->keyToCoord(*iter);
        geometry_msgs::Point cubeCenter;
        cubeCenter.x = f_can_point.x();
        cubeCenter.y = f_can_point.y();
        cubeCenter.z = f_can_point.z();
        frontierNode.points.push_back(cubeCenter);
    }
    frontierNodesVis.markers.push_back(frontierNode);

    // Make MarkerArray
    for (unsigned i= 0; i < frontierNodesVis.markers.size(); ++i)
    {
        frontierNodesVis.markers[i].header.frame_id = m_worldFrameId;
        frontierNodesVis.markers[i].header.stamp = rostime;
        frontierNodesVis.markers[i].ns = "map";
        frontierNodesVis.markers[i].id = i;
        frontierNodesVis.markers[i].type = visualization_msgs::Marker::CUBE_LIST;
        frontierNodesVis.markers[i].scale.x = 0.1;
        frontierNodesVis.markers[i].scale.y = 0.1;
        frontierNodesVis.markers[i].scale.z = 0.1;
        frontierNodesVis.markers[i].color = m_colorFrontier;

        if (frontierNodesVis.markers[i].points.size() > 0)
            frontierNodesVis.markers[i].action = visualization_msgs::Marker::ADD;
        else
            frontierNodesVis.markers[i].action = visualization_msgs::Marker::DELETE;
    }

   // Publish MarkerArray
    markerPub.publish(frontierNodesVis);

   //Clear MarkerArray
    frontierNodesVis.markers.clear();
    }

And my publisher def is

markerPub = m_nh.advertise<visualization_msgs::MarkerArray>("xyz", 1, false);

Markers are being published but previous ones are not getting deleted. Pls advice.

edit retag flag offensive close merge delete