Skip to content
Snippets Groups Projects
Commit c29929c0 authored by Simon Ottenhaus's avatar Simon Ottenhaus
Browse files

added setMaximumCycleTime

parent 042103f8
No related branches found
No related tags found
No related merge requests found
...@@ -65,42 +65,42 @@ void RobotHealth::monitorHealthTaskClb() ...@@ -65,42 +65,42 @@ void RobotHealth::monitorHealthTaskClb()
RobotHealthState healthState = RobotHealthState::HealthOK; RobotHealthState healthState = RobotHealthState::HealthOK;
for(size_t i = 0; i < validEntries; i++) for (size_t i = 0; i < validEntries; i++)
{ {
Entry& e = entries.at(i); Entry& e = entries.at(i);
long delta = std::max(now - e.lastUpdate, e.lastDelta); long delta = std::max(now - e.lastUpdate, e.lastDelta);
if(e.required && delta > e.maximumCycleTimeErr) if (e.required && delta > e.maximumCycleTimeErr)
{ {
healthState = RobotHealthState::HealthError; healthState = RobotHealthState::HealthError;
} }
if(!e.enabled) if (!e.enabled)
{ {
continue; continue;
} }
if(delta > e.maximumCycleTimeErr) if (delta > e.maximumCycleTimeErr)
{ {
healthState = RobotHealthState::HealthError; healthState = RobotHealthState::HealthError;
if(e.isRunning) if (e.isRunning)
{ {
ARMARX_ERROR << deactivateSpam(0.1, e.name) << "Component " << e.name << " has died."; ARMARX_ERROR << deactivateSpam(0.1, e.name) << "Component " << e.name << " has died.";
hasNewErr = true; hasNewErr = true;
e.isRunning = false; e.isRunning = false;
} }
} }
else if(e.isRunning && delta > e.maximumCycleTimeWarn) else if (e.isRunning && delta > e.maximumCycleTimeWarn)
{ {
ARMARX_WARNING << deactivateSpam(0.1, e.name) << "Component " << e.name << " is running too slow."; ARMARX_WARNING << deactivateSpam(0.1, e.name) << "Component " << e.name << " is running too slow.";
if(healthState == RobotHealthState::HealthOK) if (healthState == RobotHealthState::HealthOK)
{ {
healthState = RobotHealthState::HealthWarning; healthState = RobotHealthState::HealthWarning;
} }
} }
} }
if(hasNewErr) if (hasNewErr)
{ {
emergencyStopTopicPrx->reportEmergencyStopState(EmergencyStopState::eEmergencyStopActive); emergencyStopTopicPrx->reportEmergencyStopState(EmergencyStopState::eEmergencyStopActive);
} }
...@@ -130,14 +130,14 @@ void RobotHealth::onExitComponent() ...@@ -130,14 +130,14 @@ void RobotHealth::onExitComponent()
armarx::PropertyDefinitionsPtr RobotHealth::createPropertyDefinitions() armarx::PropertyDefinitionsPtr RobotHealth::createPropertyDefinitions()
{ {
return armarx::PropertyDefinitionsPtr(new RobotHealthPropertyDefinitions( return armarx::PropertyDefinitionsPtr(new RobotHealthPropertyDefinitions(
getConfigIdentifier())); getConfigIdentifier()));
} }
RobotHealth::Entry& RobotHealth::findOrCreateEntry(const std::string& name) RobotHealth::Entry& RobotHealth::findOrCreateEntry(const std::string& name)
{ {
for(size_t i = 0; i < entries.size(); i++) for (size_t i = 0; i < entries.size(); i++)
{ {
if(entries.at(i).name == name) if (entries.at(i).name == name)
{ {
return entries.at(i); return entries.at(i);
} }
...@@ -155,7 +155,7 @@ void armarx::RobotHealth::heartbeat(const std::string& componentName, const Ice: ...@@ -155,7 +155,7 @@ void armarx::RobotHealth::heartbeat(const std::string& componentName, const Ice:
{ {
Entry& e = findOrCreateEntry(componentName); Entry& e = findOrCreateEntry(componentName);
long now = TimeUtil::GetTime().toMicroSeconds(); long now = TimeUtil::GetTime().toMicroSeconds();
if(!e.isRunning) if (!e.isRunning)
{ {
ARMARX_INFO << "'" << componentName << "' is now alive and running"; ARMARX_INFO << "'" << componentName << "' is now alive and running";
e.lastDelta = 0; e.lastDelta = 0;
...@@ -166,9 +166,10 @@ void armarx::RobotHealth::heartbeat(const std::string& componentName, const Ice: ...@@ -166,9 +166,10 @@ void armarx::RobotHealth::heartbeat(const std::string& componentName, const Ice:
} }
e.lastUpdate = now; e.lastUpdate = now;
e.isRunning = true; e.isRunning = true;
e.enabled = true;
} }
void armarx::RobotHealth::reportState(const std::string& componentName, RobotHealthState state, const std::string&message, const Ice::Current&) void armarx::RobotHealth::reportState(const std::string& componentName, RobotHealthState state, const std::string& message, const Ice::Current&)
{ {
Entry& e = findOrCreateEntry(componentName); Entry& e = findOrCreateEntry(componentName);
e.state = state; e.state = state;
...@@ -184,36 +185,43 @@ void armarx::RobotHealth::unregister(const std::string& componentName, const Ice ...@@ -184,36 +185,43 @@ void armarx::RobotHealth::unregister(const std::string& componentName, const Ice
ARMARX_INFO << "unregistering " << componentName; ARMARX_INFO << "unregistering " << componentName;
} }
void RobotHealth::setMaximumCycleTime(const std::string& componentName, int warningMS, int errorMS, const Ice::Current&)
{
Entry& e = findOrCreateEntry(componentName);
e.maximumCycleTimeWarn = warningMS * 1000;
e.maximumCycleTimeErr = errorMS * 1000;
}
std::string RobotHealth::getSummary(const Ice::Current&) std::string RobotHealth::getSummary(const Ice::Current&)
{ {
long now = TimeUtil::GetTime().toMicroSeconds(); long now = TimeUtil::GetTime().toMicroSeconds();
std::stringstream ss; std::stringstream ss;
for(size_t i = 0; i < validEntries; i++) for (size_t i = 0; i < validEntries; i++)
{ {
Entry& e = entries.at(i); Entry& e = entries.at(i);
long delta = std::max(now - e.lastUpdate, e.lastDelta); long delta = std::max(now - e.lastUpdate, e.lastDelta);
ss << e.name; ss << e.name;
if(e.required) if (e.required)
{ {
ss << ", required"; ss << ", required";
} }
if(!e.required && !e.enabled) if (!e.required && !e.enabled)
{ {
ss << ": disabled\n"; ss << ": disabled\n";
} }
else if(delta > e.maximumCycleTimeErr) else if (delta > e.maximumCycleTimeErr)
{ {
ss << ": ERROR (" << (delta/1000) << "ms)\n"; ss << ": ERROR (" << (delta / 1000) << "ms)\n";
} }
else if(delta > e.maximumCycleTimeWarn) else if (delta > e.maximumCycleTimeWarn)
{ {
ss << ": warning (" << (delta/1000) << "ms)\n"; ss << ": warning (" << (delta / 1000) << "ms)\n";
} }
else else
{ {
ss << ": ok (" << (delta/1000) << "ms)\n"; ss << ": ok (" << (delta / 1000) << "ms)\n";
} }
} }
......
...@@ -90,7 +90,7 @@ namespace armarx ...@@ -90,7 +90,7 @@ namespace armarx
: name(name), maximumCycleTimeWarn(maximumCycleTimeWarn), maximumCycleTimeErr(maximumCycleTimeErr) : name(name), maximumCycleTimeWarn(maximumCycleTimeWarn), maximumCycleTimeErr(maximumCycleTimeErr)
{ } { }
Entry(Entry&&) = default; Entry(Entry&&) = default;
Entry& operator=(Entry&&) = default; Entry& operator=(Entry &&) = default;
std::string name; std::string name;
long maximumCycleTimeWarn; long maximumCycleTimeWarn;
...@@ -101,7 +101,7 @@ namespace armarx ...@@ -101,7 +101,7 @@ namespace armarx
std::string message = ""; std::string message = "";
bool isRunning = false; bool isRunning = false;
bool required = false; bool required = false;
bool enabled = true; bool enabled = false;
}; };
protected: protected:
...@@ -135,7 +135,7 @@ namespace armarx ...@@ -135,7 +135,7 @@ namespace armarx
Mutex mutex; Mutex mutex;
std::deque<Entry> entries; std::deque<Entry> entries;
std::atomic_size_t validEntries{0}; std::atomic_size_t validEntries {0};
PeriodicTask<RobotHealth>::pointer_type monitorHealthTask; PeriodicTask<RobotHealth>::pointer_type monitorHealthTask;
int defaultMaximumCycleTimeWarn; int defaultMaximumCycleTimeWarn;
int defaultMaximumCycleTimeErr; int defaultMaximumCycleTimeErr;
...@@ -150,6 +150,7 @@ namespace armarx ...@@ -150,6 +150,7 @@ namespace armarx
void heartbeat(const std::string& componentName, const Ice::Current&) override; void heartbeat(const std::string& componentName, const Ice::Current&) override;
void reportState(const std::string& componentName, RobotHealthState state, const std::string& message, const Ice::Current&) override; void reportState(const std::string& componentName, RobotHealthState state, const std::string& message, const Ice::Current&) override;
void unregister(const std::string& componentName, const Ice::Current&) override; void unregister(const std::string& componentName, const Ice::Current&) override;
void setMaximumCycleTime(const std::string& componentName, int warningMS, int errorMS, const Ice::Current&) override;
std::string getSummary(const Ice::Current&) override; std::string getSummary(const Ice::Current&) override;
}; };
......
...@@ -34,6 +34,7 @@ module armarx ...@@ -34,6 +34,7 @@ module armarx
void heartbeat(string componentName); void heartbeat(string componentName);
void reportState(string componentName, RobotHealthState state, string message); void reportState(string componentName, RobotHealthState state, string message);
void unregister(string componentName); void unregister(string componentName);
void setMaximumCycleTime(string componentName, int warningMS, int errorMS);
}; };
interface AggregatedRobotHealthInterface interface AggregatedRobotHealthInterface
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment