rviz2 slows down over time when updating sphere list

asked 2022-12-19 10:38:54 -0500

goksankobe gravatar image

I'm calling the below function in a timer callback to get an updated visualzation of the particles in a particle filter implementation. Rviz starts off quite fast but over time (after 10 seconds), it visibly slows down and increasingly eats up memory.

As far as I understand, visualization_msgs::msg::Marker::ADD; is supposed to modify the render elements instead of recreating. But the behavior feels like there's some leftover draw-calls being made in an increasing manner.

    void PublishParticleViz(const std::vector<ParticleFilter::Particle> &particles)
{
    auto particleMarkers = visualization_msgs::msg::Marker();

    // Generic marker properties
    particleMarkers.header.frame_id = "map";
    particleMarkers.header.stamp    = this->now();
    particleMarkers.ns              = "particles";
    particleMarkers.id              = 1;
    particleMarkers.type            = visualization_msgs::msg::Marker::SPHERE_LIST;
    particleMarkers.action          = visualization_msgs::msg::Marker::ADD;
    // particleMarkers.lifetime        = rclcpp::Duration::from_nanoseconds(0); // forever
    particleMarkers.scale.x = 0.06;
    particleMarkers.scale.y = 0.06;
    particleMarkers.scale.z = 0.06;
    particleMarkers.color.a = 1.0;
    particleMarkers.color.r = 1.0;
    particleMarkers.color.g = 1.0;
    particleMarkers.color.b = 1.0;

    for (const auto &particle : particles)
    {
        geometry_msgs::msg::Point pointParticle;
        pointParticle.x = particle.pose.posX;
        pointParticle.y = particle.pose.posY;
        pointParticle.z = 0.0;

        particleMarkers.points.push_back(pointParticle);
    }
    particleVizPub_->publish(particleMarkers);
}
edit retag flag offensive close merge delete

Comments

By any chance, may the particles vector passed in argument not be cleared/reset correctly ? (ie. old particules not updated or removed ?)

PatoInso gravatar image PatoInso  ( 2022-12-20 07:21:48 -0500 )edit

nope, have verified that number of particles are the same at each call. Also, I can visually confirm that the old spheres do not remain in the old positions, i.e. they're updated.

goksankobe gravatar image goksankobe  ( 2022-12-20 07:30:00 -0500 )edit