HeartbeatComponentPlugin.cpp
Go to the documentation of this file.
2 
7 
8 #include <RobotAPI/interface/components/RobotHealthInterface.h>
9 
10 namespace 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,
28  const armarx::core::time::Duration& error,
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
45  const armarx::core::time::Duration& error,
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
133  {
134  ARMARX_CHECK_NOT_NULL(robotHealthComponentPrx);
135  }
136 
137  void
139  {
140  if (!properties->hasDefinition(makePropertyName(healthPropertyName)))
141  {
142  properties->component(
143  robotHealthComponentPrx, "RobotHealth", healthPropertyName, "Name of the robot health component.");
144  }
145 
146  if (not properties->hasDefinition(makePropertyName(maximumCycleTimeWarningMSPropertyName)))
147  {
148  properties->optional(p.maximumCycleTimeWarningMS,
149  maximumCycleTimeWarningMSPropertyName,
150  "maximum cycle time before warning is emitted");
151  }
152 
153  if (not properties->hasDefinition(makePropertyName(maximumCycleTimeErrorMSPropertyName)))
154  {
155  properties->optional(p.maximumCycleTimeErrorMS,
156  maximumCycleTimeErrorMSPropertyName,
157  "maximum cycle time before error is emitted");
158  }
159  }
160 
161 } // namespace armarx::plugins
armarx::plugins::HeartbeatComponentPlugin::heartbeat
void heartbeat()
Sends out a heartbeat using the default config.
Definition: HeartbeatComponentPlugin.cpp:80
armarx::plugins::HeartbeatComponentPlugin::signUp
void signUp(const std::string &channelName="", const std::vector< std::string > &aliases={}, const std::string &description="")
register component to heartbeat
Definition: HeartbeatComponentPlugin.cpp:14
armarx::ManagedIceObjectPlugin::parent
ManagedIceObject & parent()
Definition: ManagedIceObjectPlugin.cpp:69
armarx::core::time::DateTime::Now
static DateTime Now()
Definition: DateTime.cpp:55
armarx::plugins::HeartbeatComponentPlugin::preOnInitComponent
void preOnInitComponent() override
Definition: HeartbeatComponentPlugin.cpp:110
DateTime.h
ARMARX_CHECK_NOT_NULL
#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...
Definition: ExpressionException.h:206
armarx::core::time::toIce
void toIce(dto::ClockType::ClockTypeEnum &dto, const ClockType &bo)
Definition: ice_conversions.cpp:33
armarx::plugins::HeartbeatComponentPlugin::postOnConnectComponent
void postOnConnectComponent() override
Definition: HeartbeatComponentPlugin.cpp:132
ice_conversions.h
armarx::toIce
void toIce(std::map< IceKeyT, IceValueT > &iceMap, const boost::container::flat_map< CppKeyT, CppValueT > &cppMap)
Definition: ice_conversions_boost_templates.h:15
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:69
armarx::plugins
This file is part of ArmarX.
Definition: DebugObserverComponentPlugin.cpp:28
HeartbeatComponentPlugin.h
Component.h
ExpressionException.h
armarx::plugins::HeartbeatComponentPlugin::postOnInitComponent
void postOnInitComponent() override
Definition: HeartbeatComponentPlugin.cpp:122
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::core::time::Duration
Represents a duration.
Definition: Duration.h:17
armarx::plugins::HeartbeatComponentPlugin::heartbeatOnChannel
void heartbeatOnChannel(const std::string &channelName)
Sends out a heartbeat for a subchannel.
Definition: HeartbeatComponentPlugin.cpp:95
armarx::ManagedIceObjectPlugin::makePropertyName
std::string makePropertyName(const std::string &name)
Definition: ManagedIceObjectPlugin.cpp:53
armarx::ManagedIceObject::getName
std::string getName() const
Retrieve name of object.
Definition: ManagedIceObject.cpp:107
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::plugins::HeartbeatComponentPlugin::postCreatePropertyDefinitions
void postCreatePropertyDefinitions(PropertyDefinitionsPtr &properties) override
Definition: HeartbeatComponentPlugin.cpp:138
armarx::core::time::Duration::MilliSeconds
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
Definition: Duration.cpp:55