Skip to content

Commit

Permalink
FIX: gridmaps were published at a too high rate in the ROS 2 node
Browse files Browse the repository at this point in the history
  • Loading branch information
jlblancoc committed Mar 12, 2024
1 parent 4f432a3 commit 698b0fb
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions mvsim_node_src/mvsim_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,10 +497,13 @@ void MVSimNode::publishVehicles([[maybe_unused]] mvsim::VehicleBase& veh)
void MVSimNode::publishWorldElements(mvsim::WorldElementBase& obj)
{
// GridMaps --------------
static mrpt::system::CTicTac lastMapPublished;
if (mvsim::OccupancyGridMap* grid =
dynamic_cast<mvsim::OccupancyGridMap*>(&obj);
grid)
grid && lastMapPublished.Tac() > 2.0)
{
lastMapPublished.Tic();

static Msg_OccupancyGrid ros_map;
static mvsim::OccupancyGridMap* cachedGrid = nullptr;

Expand Down Expand Up @@ -542,11 +545,12 @@ void MVSimNode::notifyROSWorldIsUpdated()
static mrpt::system::CTicTac lastMapPublished;
if (lastMapPublished.Tac() > 2.0)
{
lastMapPublished.Tic();

mvsim_world_->runVisitorOnWorldElements(
[this](mvsim::WorldElementBase& obj) {
publishWorldElements(obj);
});
lastMapPublished.Tic();
}
#endif

Expand Down

0 comments on commit 698b0fb

Please sign in to comment.