Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit scene broadcast publications when paused #497

Merged
merged 12 commits into from
Feb 26, 2021
26 changes: 18 additions & 8 deletions src/systems/scene_broadcaster/SceneBroadcaster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ class ignition::gazebo::systems::SceneBroadcasterPrivate

/// \brief A list of async state requests
public: std::unordered_set<std::string> stateRequests;

/// \brief Stores change event information during PreUpdate.
public: bool changeEvent{false};
};

//////////////////////////////////////////////////
Expand Down Expand Up @@ -234,6 +237,16 @@ void SceneBroadcaster::Configure(
}
}

//////////////////////////////////////////////////
void SceneBroadcaster::PreUpdate(const UpdateInfo &_info,
EntityComponentManager &_ecm)
{
bool jumpBackInTime = _info.dt < std::chrono::steady_clock::duration::zero();
this->dataPtr->changeEvent = _ecm.HasEntitiesMarkedForRemoval() ||
_ecm.HasNewEntities() || _ecm.HasOneTimeComponentChanges() ||
jumpBackInTime;
chapulina marked this conversation as resolved.
Show resolved Hide resolved
}

//////////////////////////////////////////////////
void SceneBroadcaster::PostUpdate(const UpdateInfo &_info,
const EntityComponentManager &_manager)
Expand Down Expand Up @@ -266,15 +279,11 @@ void SceneBroadcaster::PostUpdate(const UpdateInfo &_info,
// * jump back in time
// Throttle here instead of using transport::AdvertiseMessageOptions so that
// we can skip the ECM serialization
bool jumpBackInTime = _info.dt < std::chrono::steady_clock::duration::zero();
auto now = std::chrono::system_clock::now();
bool changeEvent = _manager.HasEntitiesMarkedForRemoval() ||
_manager.HasNewEntities() || _manager.HasOneTimeComponentChanges() ||
jumpBackInTime;
bool itsPubTime = now - this->dataPtr->lastStatePubTime >
this->dataPtr->statePublishPeriod;
bool itsPubTime = !_info.paused && (now - this->dataPtr->lastStatePubTime >
this->dataPtr->statePublishPeriod);
auto shouldPublish = this->dataPtr->statePub.HasConnections() &&
(changeEvent || itsPubTime);
(this->dataPtr->changeEvent || itsPubTime);

if (this->dataPtr->stateServiceRequest || shouldPublish)
{
Expand All @@ -284,7 +293,7 @@ void SceneBroadcaster::PostUpdate(const UpdateInfo &_info,
set(this->dataPtr->stepMsg.mutable_stats(), _info);

// Publish full state if there are change events
if (changeEvent || this->dataPtr->stateServiceRequest)
if (this->dataPtr->changeEvent || this->dataPtr->stateServiceRequest)
{
_manager.State(*this->dataPtr->stepMsg.mutable_state(), {}, {}, true);
}
Expand Down Expand Up @@ -912,6 +921,7 @@ void SceneBroadcasterPrivate::RemoveFromGraph(const Entity _entity,
IGNITION_ADD_PLUGIN(SceneBroadcaster,
ignition::gazebo::System,
SceneBroadcaster::ISystemConfigure,
SceneBroadcaster::ISystemPreUpdate,
SceneBroadcaster::ISystemPostUpdate)

// Add plugin alias so that we can refer to the plugin without the version
Expand Down
7 changes: 7 additions & 0 deletions src/systems/scene_broadcaster/SceneBroadcaster.hh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace systems
class IGNITION_GAZEBO_VISIBLE SceneBroadcaster:
public System,
public ISystemConfigure,
public ISystemPreUpdate,
public ISystemPostUpdate
{
/// \brief Constructor
Expand All @@ -55,6 +56,12 @@ namespace systems
EntityComponentManager &_ecm,
EventManager &_eventMgr) final;

// Documentation inherited
public: void PreUpdate(
const ignition::gazebo::UpdateInfo &_info,
ignition::gazebo::EntityComponentManager &_ecm) override;

// Documentation inherited
public: void PostUpdate(const UpdateInfo &_info,
const EntityComponentManager &_ecm) final;

Expand Down