HeartbeatComponentPlugin.cpp
Go to the documentation of this file.
2
7
8#include <RobotAPI/interface/components/RobotHealthInterface.h>
9
10namespace armarx::plugins
11{
12
13 void
14 HeartbeatComponentPlugin::signUp(const std::string& identifier,
15 const std::vector<std::string>& tags,
16 const std::string& description)
17 {
18 RobotHealthHeartbeatArgs argsCopy = defaultHeartbeatArgs;
19 argsCopy.description = description;
20 argsCopy.identifier = identifier;
21 argsCopy.tags = tags;
22 signUp(argsCopy);
23 }
24
25 void
26 HeartbeatComponentPlugin::signUp(const std::string& identifier,
27 const armarx::core::time::Duration& warning,
29 const std::vector<std::string>& tags,
30 const std::string& description)
31 {
32 RobotHealthHeartbeatArgs argsCopy = defaultHeartbeatArgs;
33 argsCopy.description = description;
34 argsCopy.tags = tags;
35 argsCopy.identifier = identifier;
36 toIce(argsCopy.maximumCycleTimeWarning, warning);
37 toIce(argsCopy.maximumCycleTimeError, error);
38
40 signUp(argsCopy);
41 }
42
43 void
46 const std::vector<std::string>& tags,
47 const std::string& description)
48 {
49 RobotHealthHeartbeatArgs argsCopy = defaultHeartbeatArgs;
50 argsCopy.description = description;
51 argsCopy.tags = tags;
52 toIce(argsCopy.maximumCycleTimeWarning, warning);
53 toIce(argsCopy.maximumCycleTimeError, error);
54 // argsCopy.requiredByDefault = required;
55 signUp(argsCopy);
56 }
57
58 void
59 HeartbeatComponentPlugin::signUp(const RobotHealthHeartbeatArgs& args)
60 {
62 ARMARX_CHECK_NOT_NULL(robotHealthComponentPrx);
63
64 if (args.identifier.empty())
65 {
66 RobotHealthHeartbeatArgs argsCopy = args;
67 argsCopy.identifier = parent().getName();
68 robotHealthComponentPrx->signUp(argsCopy);
69 }
70 else
71 {
72 // add component name prefix to identifier
73 RobotHealthHeartbeatArgs argsCopy = args;
74 argsCopy.identifier = parent().getName() + "_" + argsCopy.identifier;
75 robotHealthComponentPrx->signUp(argsCopy);
76 }
77 }
78
79 void
81 {
82 if (robotHealthComponentPrx)
83 {
84 armarx::core::time::dto::DateTime now;
86 robotHealthComponentPrx->heartbeat(parent().getName(), now);
87 }
88 else
89 {
90 ARMARX_WARNING << "No robot health proxy available!";
91 }
92 }
93
94 void
95 HeartbeatComponentPlugin::heartbeatOnChannel(const std::string& channelName)
96 {
97 if (robotHealthComponentPrx)
98 {
99 armarx::core::time::dto::DateTime now;
101 robotHealthComponentPrx->heartbeat(parent().getName() + "_" + channelName, now);
102 }
103 else
104 {
105 ARMARX_WARNING << "No robot health proxy available!";
106 }
107 }
108
109 void
111 {
112 // defaultHeartbeatArgs.requiredByDefault = true;
113
114 // if (topicName.empty())
115 // {
116 // parent<Component>().getProperty(topicName, makePropertyName(topicPropertyName));
117 // }
118 // parent<Component>().offeringTopic(topicName);
119 }
120
121 void
123 {
124 // set default args
125 auto warn = armarx::core::time::Duration::MilliSeconds(p.maximumCycleTimeWarningMS);
126 auto err = armarx::core::time::Duration::MilliSeconds(p.maximumCycleTimeErrorMS);
127 armarx::core::time::toIce(defaultHeartbeatArgs.maximumCycleTimeWarning, warn);
128 armarx::core::time::toIce(defaultHeartbeatArgs.maximumCycleTimeError, err);
129 }
130
131 void
136
137 void
139 {
140 if (!properties->hasDefinition(makePropertyName(healthPropertyName)))
141 {
142 properties->component(robotHealthComponentPrx,
143 "RobotHealth",
144 healthPropertyName,
145 "Name of the robot health component.");
146 }
147
148 if (not properties->hasDefinition(makePropertyName(maximumCycleTimeWarningMSPropertyName)))
149 {
150 properties->optional(p.maximumCycleTimeWarningMS,
151 maximumCycleTimeWarningMSPropertyName,
152 "maximum cycle time before warning is emitted");
153 }
154
155 if (not properties->hasDefinition(makePropertyName(maximumCycleTimeErrorMSPropertyName)))
156 {
157 properties->optional(p.maximumCycleTimeErrorMS,
158 maximumCycleTimeErrorMSPropertyName,
159 "maximum cycle time before error is emitted");
160 }
161 }
162
163} // namespace armarx::plugins
std::string makePropertyName(const std::string &name)
std::string getName() const
Retrieve name of object.
static DateTime Now()
Definition DateTime.cpp:51
Represents a duration.
Definition Duration.h:17
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
Definition Duration.cpp:48
void postCreatePropertyDefinitions(PropertyDefinitionsPtr &properties) override
void signUp(const std::string &channelName="", const std::vector< std::string > &aliases={}, const std::string &description="")
register component to heartbeat
void heartbeatOnChannel(const std::string &channelName)
Sends out a heartbeat for a subchannel.
void heartbeat()
Sends out a heartbeat using the default config.
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
void toIce(dto::ClockType::ClockTypeEnum &dto, const ClockType &bo)
This file is part of ArmarX.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
void toIce(std::map< IceKeyT, IceValueT > &iceMap, const boost::container::flat_map< CppKeyT, CppValueT > &cppMap)
#define ARMARX_TRACE
Definition trace.h:77