Gazebo Gazebo

API Reference

6.16.0
TriggeredPublisher.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 #ifndef GZ_GAZEBO_SYSTEMS_TRIGGEREDPUBLISHER_HH_
18 #define GZ_GAZEBO_SYSTEMS_TRIGGEREDPUBLISHER_HH_
19 
20 #include <memory>
21 #include <string>
22 #include <vector>
23 #include <mutex>
24 #include <gz/transport/Node.hh>
25 #include "gz/sim/System.hh"
26 
27 namespace ignition
28 {
29 namespace gazebo
30 {
31 // Inline bracket to help doxygen filtering.
32 inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {
33 namespace systems
34 {
35  // Forward declaration
36  class InputMatcher;
37 
173  class TriggeredPublisher : public System,
174  public ISystemConfigure,
175  public ISystemPreUpdate
176  {
178  public: TriggeredPublisher() = default;
179 
181  public: ~TriggeredPublisher() override;
182 
183  // Documentation inherited
184  public: void Configure(const Entity &_entity,
187  EventManager &_eventMgr) override;
188 
189  // Documentation inherited
190  public: void PreUpdate(
191  const ignition::gazebo::UpdateInfo &_info,
193 
195  public: void DoWork();
196 
198  private: void CallService(std::size_t pendingSrv);
199 
201  private: void PublishMsg(std::size_t pending);
202 
206  public: bool MatchInput(const transport::ProtoMsg &_inputMsg);
207 
209  private: std::string inputMsgType;
210 
212  private: std::string inputTopic;
213 
215  private: struct OutputInfo
216  {
218  std::string msgType;
219 
221  std::string topic;
222 
225  transport::ProtoMsgPtr msgData;
226 
229  };
230 
232  private: struct SrvOutputInfo
233  {
235  std::string srvName;
236 
238  std::string reqType;
239 
241  std::string repType;
242 
244  std::string reqMsg;
245 
247  int timeout;
248  };
249 
252 
254  private: std::vector<OutputInfo> outputInfo;
255 
257  private: std::vector<SrvOutputInfo> srvOutputInfo;
258 
260  private: transport::Node node;
261 
263  private: std::size_t serviceCount{0};
264 
266  private: std::size_t publishCount{0};
267 
269  private: std::mutex publishCountMutex;
270 
272  private: std::mutex triggerSrvMutex;
273 
275  private: std::condition_variable newMatchSignal;
276 
278  private: std::thread workerThread;
279 
282  private: std::atomic<bool> done{false};
283 
285  private: std::chrono::steady_clock::duration delay{0};
286 
289 
291  private: std::mutex publishQueueMutex;
292  };
293 }
294 }
295 }
296 }
297 #endif
uint64_t Entity
An Entity identifies a single object in simulation such as a model, link, or light....
Definition: gz/sim/Entity.hh:58
void Configure(const Entity &_entity, const std::shared_ptr< const sdf::Element > &_sdf, EntityComponentManager &_ecm, EventManager &_eventMgr) override
Configure the system.
This library is part of the Gazebo project.
STL class.
The EntityComponentManager constructs, deletes, and returns components and entities....
Definition: gz/sim/EntityComponentManager.hh:66
STL class.
google::protobuf::Message ProtoMsg
STL class.
void DoWork()
Thread that handles publishing output messages.
The EventManager is used to send/receive notifications of simulator events.
Definition: gz/sim/EventManager.hh:54
void PreUpdate(const ignition::gazebo::UpdateInfo &_info, ignition::gazebo::EntityComponentManager &_ecm) override
The triggered publisher system publishes a user specified message on an output topic in response to a...
Definition: TriggeredPublisher.hh:173
Information passed to systems on the update callback.
Definition: include/gz/sim/Types.hh:38
STL class.
bool MatchInput(const transport::ProtoMsg &_inputMsg)
Helper function that calls Match on every InputMatcher available.
Interface for a system that uses the PreUpdate phase.
Definition: gz/sim/System.hh:121
Interface for a system that implements optional configuration.
Definition: gz/sim/System.hh:90
Base class for a System.
Definition: gz/sim/System.hh:75
STL class.