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
45namespace 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 */
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
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition Component.h:94
IceUtil::Handle< PeriodicTask< T > > pointer_type
Shared pointer type for convenience.
Brief description of class RobotHealth.
Definition RobotHealth.h:62
void onInitComponent() override
void unregister(const std::string &identifier, const Ice::Current &) override
void removeRequiredTags(const std::string &requesterIdentifier, const std::vector< std::string > &tags, const Ice::Current &current) override
void onDisconnectComponent() override
RobotHealthInfo getSummary(const Ice::Current &current) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void resetRequiredTags(const Ice::Current &current) override
void signUp(const RobotHealthHeartbeatArgs &args, const Ice::Current &current) override
void onConnectComponent() override
void heartbeat(const std::string &identifier, const core::time::dto::DateTime &referenceTime, const Ice::Current &current) override
void addRequiredTags(const std::string &requesterIdentifier, const std::vector< std::string > &tags, const Ice::Current &current) override
std::string getTopicName(const Ice::Current &current) override
void onExitComponent() override
std::string getDefaultName() const override
Definition RobotHealth.h:68
Represents a point in time.
Definition DateTime.h:25
Represents a duration.
Definition Duration.h:17
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
armarx::core::time::DateTime referenceTime
armarx::core::time::DateTime arrivalTime