Gazebo Gazebo

API Reference

6.18.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 
174  class TriggeredPublisher : public System,
175  public ISystemConfigure,
176  public ISystemPreUpdate
177  {
179  public: TriggeredPublisher() = default;
180 
182  public: ~TriggeredPublisher() override;
183 
184  // Documentation inherited
185  public: void Configure(const Entity &_entity,
188  EventManager &_eventMgr) override;
189 
190  // Documentation inherited
191  public: void PreUpdate(
192  const ignition::gazebo::UpdateInfo &_info,
194 
196  public: void DoWork();
197 
199  private: void CallService(std::size_t pendingSrv);
200 
202  private: void PublishMsg(std::size_t pending);
203 
207  public: bool MatchInput(const transport::ProtoMsg &_inputMsg);
208 
210  private: std::string inputMsgType;
211 
213  private: std::string inputTopic;
214 
216  private: struct OutputInfo
217  {
219  std::string msgType;
220 
222  std::string topic;
223 
226  transport::ProtoMsgPtr msgData;
227 
229  transport::Node::Publisher pub;
230  };
231 
233  private: struct SrvOutputInfo
234  {
236  std::string srvName;
237 
239  std::string reqType;
240 
242  std::string repType;
243 
245  std::string reqMsg;
246 
248  int timeout;
249  };
250 
253 
255  private: std::vector<OutputInfo> outputInfo;
256 
258  private: std::vector<SrvOutputInfo> srvOutputInfo;
259 
261  private: transport::Node node;
262 
264  private: std::size_t serviceCount{0};
265 
267  private: std::size_t publishCount{0};
268 
270  private: std::mutex publishCountMutex;
271 
273  private: std::mutex triggerSrvMutex;
274 
276  private: std::condition_variable newMatchSignal;
277 
279  private: std::thread workerThread;
280 
283  private: std::atomic<bool> done{false};
284 
286  private: std::chrono::steady_clock::duration delay{0};
287 
290 
292  private: std::mutex publishQueueMutex;
293  };
294 }
295 }
296 }
297 }
298 #endif
The EntityComponentManager constructs, deletes, and returns components and entities....
Definition: gz/sim/EntityComponentManager.hh:67
The EventManager is used to send/receive notifications of simulator events.
Definition: gz/sim/EventManager.hh:55
Interface for a system that implements optional configuration.
Definition: gz/sim/System.hh:90
Interface for a system that uses the PreUpdate phase.
Definition: gz/sim/System.hh:121
Base class for a System.
Definition: gz/sim/System.hh:76
The triggered publisher system publishes a user specified message on an output topic in response to a...
Definition: TriggeredPublisher.hh:177
void Configure(const Entity &_entity, const std::shared_ptr< const sdf::Element > &_sdf, EntityComponentManager &_ecm, EventManager &_eventMgr) override
Configure the system.
void DoWork()
Thread that handles publishing output messages.
bool MatchInput(const transport::ProtoMsg &_inputMsg)
Helper function that calls Match on every InputMatcher available.
void PreUpdate(const ignition::gazebo::UpdateInfo &_info, ignition::gazebo::EntityComponentManager &_ecm) override
uint64_t Entity
An Entity identifies a single object in simulation such as a model, link, or light....
Definition: gz/sim/Entity.hh:58
This library is part of the Gazebo project.
Definition: gz/sim/Actor.hh:34
Information passed to systems on the update callback.
Definition: include/gz/sim/Types.hh:39