diff --git a/CMakeLists.txt b/CMakeLists.txt index b61f207ab6..719d8b1784 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,7 @@ set(IGN_PLUGIN_VER ${ignition-plugin1_VERSION_MAJOR}) #-------------------------------------- # Find ignition-transport -ign_find_package(ignition-transport9 REQUIRED COMPONENTS log) +ign_find_package(ignition-transport9 REQUIRED COMPONENTS log VERSION 9.1) set(IGN_TRANSPORT_VER ${ignition-transport9_VERSION_MAJOR}) #-------------------------------------- diff --git a/src/systems/breadcrumbs/Breadcrumbs.cc b/src/systems/breadcrumbs/Breadcrumbs.cc index ba98482007..fd740eb10d 100644 --- a/src/systems/breadcrumbs/Breadcrumbs.cc +++ b/src/systems/breadcrumbs/Breadcrumbs.cc @@ -141,13 +141,28 @@ void Breadcrumbs::Configure(const Entity &_entity, topics.push_back("/model/" + this->model.Name(_ecm) + "/breadcrumbs/" + this->modelRoot.ModelByIndex(0)->Name() + "/deploy"); - auto topic = validTopic(topics); + this->topic = validTopic(topics); - this->node.Subscribe(topic, &Breadcrumbs::OnDeploy, this); - this->remainingPub = this->node.Advertise(topic + "/remaining"); + this->topicStatistics = _sdf->Get("topic_statistics", + this->topicStatistics).first; - ignmsg << "Breadcrumbs subscribing to deploy messages on [" << topic << "]" - << std::endl; + // Enable topic statistics when requested. + if (this->topicStatistics) + { + if (!node.EnableStats(this->topic, true)) + { + ignerr << "Unable to enable topic statistics on topic[" + << this->topic << "]." << std::endl; + this->topicStatistics = false; + } + } + + this->node.Subscribe(this->topic, &Breadcrumbs::OnDeploy, this); + this->remainingPub = this->node.Advertise( + this->topic + "/remaining"); + + ignmsg << "Breadcrumbs subscribing to deploy messages on [" + << this->topic << "]" << std::endl; this->creator = std::make_unique(_ecm, _eventMgr); @@ -390,8 +405,32 @@ void Breadcrumbs::OnDeploy(const msgs::Empty &) IGN_PROFILE("Breadcrumbs::PreUpdate"); { std::lock_guard lock(this->pendingCmdsMutex); + this->pendingCmds.push_back(true); } + + // Check topic statistics for dropped messages + if (this->topicStatistics) + { + ignmsg << "Received breadcrumb deployment for " << + this->modelRoot.ModelByIndex(0)->Name() << std::endl; + std::optional stats = + this->node.TopicStats(this->topic); + if (stats) + { + if (stats->DroppedMsgCount() > 0) + { + ignwarn << "Dropped message count of " << stats->DroppedMsgCount() + << " for breadcrumbs on model " + << this->modelRoot.ModelByIndex(0)->Name() << std::endl; + } + } + else + { + ignerr << "Unable to get topic statistics for topic[" + << this->topic << "]." << std::endl; + } + } } IGNITION_ADD_PLUGIN(Breadcrumbs, diff --git a/src/systems/breadcrumbs/Breadcrumbs.hh b/src/systems/breadcrumbs/Breadcrumbs.hh index bb34021344..4800c2d4e4 100644 --- a/src/systems/breadcrumbs/Breadcrumbs.hh +++ b/src/systems/breadcrumbs/Breadcrumbs.hh @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -79,6 +80,9 @@ namespace systems /// Defaults to false. /// ``: This is the model used as a template for deploying /// breadcrumbs. + /// ``: If true, then topic statistics are enabled on + /// `` and error messages will be generated when messages are + /// dropped. Default to false. class IGNITION_GAZEBO_VISIBLE Breadcrumbs : public System, public ISystemConfigure, @@ -163,6 +167,12 @@ namespace systems /// \brief Publishes remaining deployments. public: transport::Node::Publisher remainingPub; + + /// \brief True when topic statistics are enabled. + public: bool topicStatistics{false}; + + /// \brief Name of the deploy topic. + public: std::string topic; }; } }