Skip to content

Commit

Permalink
Add methods for subscribing/unsubscribing to map update separately
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin-Idel committed Sep 19, 2019
1 parent 9584141 commit a060815
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ protected Q_SLOTS:

void clear();

void subscribeToUpdateTopic();
void unsubscribeToUpdateTopic();

void showValidMap();
void resetSwatchesIfNecessary(size_t width, size_t height, float resolution);
void createSwatches();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,16 @@ void MapDisplay::subscribe()

MFDClass::subscribe();

subscribeToUpdateTopic();
}

void MapDisplay::subscribeToUpdateTopic()
{
try {
update_subscription_ = rviz_ros_node_.lock()->get_raw_node()->
update_subscription_ =
rviz_ros_node_.lock()->get_raw_node()->
template create_subscription<map_msgs::msg::OccupancyGridUpdate>(
update_topic_property_->getTopicStd(),
update_profile_,
update_topic_property_->getTopicStd(), update_profile_,
[this](const map_msgs::msg::OccupancyGridUpdate::ConstSharedPtr message) {
incomingUpdate(message);
});
Expand All @@ -224,6 +229,11 @@ void MapDisplay::subscribe()
void MapDisplay::unsubscribe()
{
MFDClass::unsubscribe();
unsubscribeToUpdateTopic();
}

void MapDisplay::unsubscribeToUpdateTopic()
{
update_subscription_.reset();
}

Expand Down Expand Up @@ -288,7 +298,6 @@ void MapDisplay::processMessage(nav_msgs::msg::OccupancyGrid::ConstSharedPtr msg
Q_EMIT mapUpdated();
}

// TODO(wjwwood): Use again once map_msgs are ported
void MapDisplay::incomingUpdate(const map_msgs::msg::OccupancyGridUpdate::ConstSharedPtr update)
{
// Only update the map if we have gotten a full one first.
Expand Down Expand Up @@ -607,13 +616,12 @@ void MapDisplay::onEnable()

void MapDisplay::updateMapUpdateTopic()
{
unsubscribe();
unsubscribeToUpdateTopic();
reset();
subscribe();
subscribeToUpdateTopic();
context_->queueRender();
}


} // namespace displays
} // namespace rviz_default_plugins

Expand Down

0 comments on commit a060815

Please sign in to comment.