18 #include <diagnostic_msgs/DiagnosticArray.h> 25 const std::vector<std::string> &joints_all_names,
26 const std::string &robot):
28 joints_all_names_(joints_all_names),
29 temperature_warn_level_(68.0
f),
30 temperature_error_level_(73.0
f)
37 status_.name = std::string(
"naoqi_dcm_driver:Status");
39 status_.level = diagnostic_msgs::DiagnosticStatus::OK;
47 catch (
const std::exception& e)
49 ROS_ERROR(
"DIAGNOSTICS: Failed to connect to Memory Proxy!\n\tTrace: %s", e.what());
53 keys_tocheck_.push_back(
"Device/SubDeviceList/Battery/Charge/Sensor/Value");
57 keys_tocheck_.push_back(
"Device/SubDeviceList/" + *it +
"/Temperature/Sensor/Value");
58 keys_tocheck_.push_back(
"Device/SubDeviceList/" + *it +
"/Hardness/Actuator/Value");
59 keys_tocheck_.push_back(
"Device/SubDeviceList/" + *it +
"/ElectricCurrent/Sensor/Value");
64 keys_tocheck_.push_back(
"Device/SubDeviceList/" + *it_cntrl +
"/ElectricCurrent/Sensor/Value");
69 if ((robot ==
"pepper") || (robot ==
"juliette") || (robot ==
"nao")) {
70 qi::AnyObject body_temperature_ = session->service(
"ALBodyTemperature");
71 body_temperature_.call<
void>(
"setEnableNotifications",
true);
74 catch (
const std::exception& e)
76 ROS_WARN(
"DIAGNOSTICS: Failed to connect to ALBodyTemperature!\n\tTrace: %s", e.what());
82 if (status.level == diagnostic_msgs::DiagnosticStatus::OK) {
83 status.message =
"OK";
84 }
else if (status.level == diagnostic_msgs::DiagnosticStatus::WARN) {
85 status.message =
"WARN";
87 status.message =
"ERROR";
93 if(status.level >
status_.level) {
95 status_.message = status.message;
101 diagnostic_msgs::DiagnosticArray
msg;
105 status_.level = diagnostic_msgs::DiagnosticStatus::OK;
109 float maxTemperature = 0.0f;
110 float maxStiffness = 0.0f;
111 float minStiffness = 1.0f;
112 float minStiffnessWoHands = 1.0f;
113 float maxCurrent = 0.0f;
114 float minCurrent = 10.0f;
115 std::stringstream hotJointsSS;
116 diagnostic_msgs::DiagnosticStatus::_level_type max_level = diagnostic_msgs::DiagnosticStatus::OK;
118 std::vector<float>
values;
124 catch(
const std::exception& e)
126 ROS_ERROR(
"DIAGNOSTICS: Could not get joint data from the robot \n\tTrace: %s", e.what());
132 float batteryCharge =
static_cast<float>(values[val++]);
135 status_battery.name = std::string(
"naoqi_dcm_driver:Battery");
136 status_battery.hardware_id =
"battery";
137 status_battery.
add(
"BatteryCharge", batteryCharge);
140 if (batteryCharge > 5.0
f)
142 status_battery.level = diagnostic_msgs::DiagnosticStatus::OK;
143 status_battery.message =
"OK";
147 status_battery.level = diagnostic_msgs::DiagnosticStatus::ERROR;
148 status_battery.message =
"LOW Battery Charge";
150 msg.status.push_back(status_battery);
157 status.name = std::string(
"naoqi_dcm_driver:") + *it_name;
159 float temperature =
static_cast<float>(values[val++]);
160 float stiffness =
static_cast<float>(values[val++]);
161 *it_current =
static_cast<float>(values[val++]);
164 status.hardware_id = *it_name;
165 status.
add(
"Temperature", temperature);
166 status.
add(
"Stiffness", stiffness);
167 status.
add(
"ElectricCurrent", *it_current);
172 status.level = diagnostic_msgs::DiagnosticStatus::OK;
173 status.message =
"OK";
177 status.level = diagnostic_msgs::DiagnosticStatus::WARN;
178 status.message =
"Hot";
182 status.level = diagnostic_msgs::DiagnosticStatus::ERROR;
183 status.message =
"HIGH JOINT TEMPERATURE : " + *it_name;
186 msg.status.push_back(status);
190 max_level = std::max(max_level, status.level);
191 maxTemperature = std::max(maxTemperature, temperature);
192 maxStiffness = std::max(maxStiffness, stiffness);
193 minStiffness = std::min(minStiffness, stiffness);
194 if((*it_name).find(
"Hand") == std::string::npos)
195 minStiffnessWoHands = std::min(minStiffnessWoHands, stiffness);
196 maxCurrent = std::max(maxCurrent, *it_current);
197 minCurrent = std::min(minCurrent, *it_current);
198 if(status.level >= (
int) diagnostic_msgs::DiagnosticStatus::WARN) {
199 hotJointsSS << std::endl << *it_name <<
": " << temperature <<
"°C";
205 status.name = std::string(
"naoqi_dcm_driver:Status");
206 status.hardware_id =
"joints";
207 status.level = max_level;
210 status.
add(
"Highest Temperature", maxTemperature);
211 status.
add(
"Highest Stiffness", maxStiffness);
212 status.
add(
"Lowest Stiffness", minStiffness);
213 status.
add(
"Lowest Stiffness without Hands", minStiffnessWoHands);
214 status.
add(
"Highest Electric Current", maxCurrent);
215 status.
add(
"Lowest Electric current", minCurrent);
216 status.
add(
"Hot Joints", hotJointsSS.str());
218 msg.status.push_back(status);
222 if(
status_.level >= (
int) diagnostic_msgs::DiagnosticStatus::ERROR)
Diagnostics(const qi::SessionPtr &session, ros::Publisher *pub, const std::vector< std::string > &joints_all_names, const std::string &robot)
Constructor.
void setMessageFromStatus(diagnostic_updater::DiagnosticStatusWrapper &status)
set the message based on level
void publish(const boost::shared_ptr< M > &message) const
void setAggregatedMessage(diagnostic_updater::DiagnosticStatusWrapper &status)
set the aggregated message
std::vector< double > values
std::vector< std::string > joints_all_names_
std::string getStatusMsg()
return the status message
qi::AnyObject memory_proxy_
std::vector< float > joints_current_
std::vector< std::string > keys_tocheck_
bool publish()
publish the newly received data
float temperature_error_level_
diagnostic_updater::DiagnosticStatusWrapper status_
void add(const std::string &key, const T &val)
#define ROS_ERROR_STREAM(args)
float temperature_warn_level_