RobotHealth.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package RobotAPI::ArmarXObjects::RobotHealth
17  * @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu )
18  * @date 2018
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
25 #include <array>
26 #include <atomic>
27 #include <deque>
28 #include <mutex>
29 
36 #include <ArmarXCore/interface/components/EmergencyStopInterface.h>
38 
39 #include <ArmarXGui/interface/RemoteGuiInterface.h>
40 
41 #include <RobotAPI/interface/components/RobotHealthInterface.h>
42 #include <RobotAPI/interface/speech/SpeechInterface.h>
43 #include <RobotAPI/interface/units/RobotUnit/RobotUnitInterface.h>
44 
45 namespace armarx
46 {
47  /**
48  * @defgroup Component-RobotHealth RobotHealth
49  * @ingroup RobotAPI-Components
50  * A description of the component RobotHealth.
51  *
52  * @class RobotHealth
53  * @ingroup Component-RobotHealth
54  * @brief Brief description of class RobotHealth.
55  *
56  * Detailed description of class RobotHealth.
57  */
58  class RobotHealth :
59  virtual public RobotHealthComponentInterface,
60  virtual public armarx::Component,
62  {
63  public:
64  /**
65  * @see armarx::ManagedIceObject::getDefaultName()
66  */
67  std::string
68  getDefaultName() const override
69  {
70  return "RobotHealth";
71  }
72 
73  // RobotHealthInterface interface
74  void signUp(const RobotHealthHeartbeatArgs& args, const Ice::Current& current) override;
75  void unregister(const std::string& identifier, const Ice::Current&) override;
76 
77 
78  void addRequiredTags(const std::string& requesterIdentifier,
79  const std::vector<std::string>& tags,
80  const Ice::Current& current) override;
81  void removeRequiredTags(const std::string& requesterIdentifier,
82  const std::vector<std::string>& tags,
83  const Ice::Current& current) override;
84  void resetRequiredTags(const Ice::Current& current) override;
85 
86 
87  void heartbeat(const std::string& identifier,
88  const core::time::dto::DateTime& referenceTime,
89  const Ice::Current& current) override;
90 
91  std::string getTopicName(const Ice::Current& current) override;
92 
93  RobotHealthInfo getSummary(const Ice::Current& current) override;
94 
95 
96  protected:
97  /**
98  * @see armarx::ManagedIceObject::onInitComponent()
99  */
100  void onInitComponent() override;
101 
102  /**
103  * @see armarx::ManagedIceObject::onConnectComponent()
104  */
105  void onConnectComponent() override;
106 
107  /**
108  * @see armarx::ManagedIceObject::onDisconnectComponent()
109  */
110  void onDisconnectComponent() override;
111 
112  /**
113  * @see armarx::ManagedIceObject::onExitComponent()
114  */
115  void onExitComponent() override;
116 
117  /**
118  * @see PropertyUser::createPropertyDefinitions()
119  */
121 
122  private:
123  struct UpdateEntry
124  {
125  UpdateEntry(const std::string& name,
126  const armarx::core::time::Duration& maximumCycleTimeWarn,
127  const armarx::core::time::Duration& maximumCycleTimeErr) :
128  name(name),
129  maximumCycleTimeWarn(maximumCycleTimeWarn),
130  maximumCycleTimeErr(maximumCycleTimeErr)
131  {
132  }
133 
134  std::string name;
135  std::vector<std::string> tags;
136  RobotHealthState state = HealthOK;
137  std::string description = "";
138 
139  bool required = false;
140  bool enabled = false;
141 
142  mutable std::mutex mutex;
143 
144  struct TimeInfo
145  {
146  //< Timestamp sent by component
148 
149  //< Timestamp on this PC, set by this component
151  };
152 
153  std::deque<TimeInfo> history;
154 
155  armarx::core::time::Duration maximumCycleTimeWarn;
156  armarx::core::time::Duration maximumCycleTimeErr;
157  };
158 
159  void monitorHealthUpdateTaskClb();
160 
161  UpdateEntry* findUpdateEntry(const std::string& name);
162  std::pair<bool, UpdateEntry&> findOrCreateUpdateEntry(const std::string& name);
163 
164  void reportDebugObserver();
165 
166 
167  void updateRequiredElements();
168  std::set<std::string> requestedTags() const;
169 
170  // Mutex to restrict access to all interface / public methods. This ensures that all requests are
171  // handled sequentially.
172  mutable std::mutex updateMutex;
173 
174  std::deque<UpdateEntry> updateEntries;
175 
176  std::map<std::string, std::set<std::string>> tagsPerRequester;
177 
178  PeriodicTask<RobotHealth>::pointer_type monitorUpdateHealthTask;
179 
180  armarx::core::time::Duration defaultMaximumCycleTimeWarn;
181  armarx::core::time::Duration defaultMaximumCycleTimeErr;
182 
183  struct Properties
184  {
185  EmergencyStopListenerPrx emergencyStopTopicPrx;
186  std::string robotHealthTopicName = "RobotHealthTopic";
187  AggregatedRobotHealthInterfacePrx aggregatedRobotHealthTopicPrx;
188  RemoteGuiInterfacePrx remoteGuiPrx;
189  long maximumCycleTimeWarnMS = 50;
190  long maximumCycleTimeErrMS = 100;
191 
192  std::string requiredTags;
193  } p;
194  };
195 } // namespace armarx
armarx::RobotHealth::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: RobotHealth.cpp:190
armarx::RobotHealth::onDisconnectComponent
void onDisconnectComponent() override
Definition: RobotHealth.cpp:178
armarx::RobotHealth::addRequiredTags
void addRequiredTags(const std::string &requesterIdentifier, const std::vector< std::string > &tags, const Ice::Current &current) override
Definition: RobotHealth.cpp:359
DateTime.h
Frequency.h
Duration.h
PeriodicTask.h
armarx::RobotHealth::UpdateEntry::TimeInfo::referenceTime
armarx::core::time::DateTime referenceTime
Definition: RobotHealth.h:147
armarx::RobotHealth::getSummary
RobotHealthInfo getSummary(const Ice::Current &current) override
Definition: RobotHealth.cpp:452
armarx::RobotHealth::unregister
void unregister(const std::string &identifier, const Ice::Current &) override
Definition: RobotHealth.cpp:325
armarx::RobotHealth::onExitComponent
void onExitComponent() override
Definition: RobotHealth.cpp:185
armarx::RobotHealth::heartbeat
void heartbeat(const std::string &identifier, const core::time::dto::DateTime &referenceTime, const Ice::Current &current) override
Definition: RobotHealth.cpp:282
armarx::RobotHealth::signUp
void signUp(const RobotHealthHeartbeatArgs &args, const Ice::Current &current) override
Definition: RobotHealth.cpp:251
enabled
std::atomic< bool > * enabled
Definition: RemoteGuiWidgetController.cpp:75
DebugObserverComponentPlugin.h
armarx::RobotHealth::getDefaultName
std::string getDefaultName() const override
Definition: RobotHealth.h:68
armarx::RobotHealth::removeRequiredTags
void removeRequiredTags(const std::string &requesterIdentifier, const std::vector< std::string > &tags, const Ice::Current &current) override
Definition: RobotHealth.cpp:422
armarx::RobotHealth
Brief description of class RobotHealth.
Definition: RobotHealth.h:58
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:95
armarx::RobotHealth::UpdateEntry::TimeInfo::arrivalTime
armarx::core::time::DateTime arrivalTime
Definition: RobotHealth.h:150
armarx::RobotHealth::onConnectComponent
void onConnectComponent() override
Definition: RobotHealth.cpp:65
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
armarx::RobotHealth::getTopicName
std::string getTopicName(const Ice::Current &current) override
Definition: RobotHealth.cpp:517
TimeUtil.h
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::RobotHealth::resetRequiredTags
void resetRequiredTags(const Ice::Current &current) override
Definition: RobotHealth.cpp:438
armarx::core::time::Duration
Represents a duration.
Definition: Duration.h:17
armarx::DebugObserverComponentPluginUser
Definition: DebugObserverComponentPlugin.h:82
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::RobotHealth::onInitComponent
void onInitComponent() override
Definition: RobotHealth.cpp:46
armarx::RobotHealth::UpdateEntry::TimeInfo
Definition: RobotHealth.h:144