37 const int UNDERVOLT_ERROR = 18;
38 const int UNDERVOLT_WARN = 19;
39 const int OVERVOLT_ERROR = 30;
40 const int OVERVOLT_WARN = 29;
41 const int DRIVER_OVERTEMP_ERROR = 50;
42 const int DRIVER_OVERTEMP_WARN = 30;
43 const int MOTOR_OVERTEMP_ERROR = 80;
44 const int MOTOR_OVERTEMP_WARN = 70;
45 const double LOWPOWER_ERROR = 0.2;
46 const double LOWPOWER_WARN = 0.3;
47 const int CONTROLFREQ_WARN = 90;
48 const unsigned int SAFETY_TIMEOUT = 0x1;
49 const unsigned int SAFETY_LOCKOUT = 0x2;
50 const unsigned int SAFETY_ESTOP = 0x8;
51 const unsigned int SAFETY_CCI = 0x10;
52 const unsigned int SAFETY_PSU = 0x20;
53 const unsigned int SAFETY_CURRENT = 0x40;
54 const unsigned int SAFETY_WARN = (SAFETY_TIMEOUT | SAFETY_CCI | SAFETY_PSU);
55 const unsigned int SAFETY_ERROR = (SAFETY_LOCKOUT | SAFETY_ESTOP | SAFETY_CURRENT);
64 DiagnosticTask(
"system_status"),
74 msg_.uptime = system_status->getUptime();
76 msg_.battery_voltage = system_status->getVoltage(0);
77 msg_.left_driver_voltage = system_status->getVoltage(1);
78 msg_.right_driver_voltage = system_status->getVoltage(2);
80 msg_.mcu_and_user_port_current = system_status->getCurrent(0);
81 msg_.left_driver_current = system_status->getCurrent(1);
82 msg_.right_driver_current = system_status->getCurrent(2);
84 msg_.left_driver_temp = system_status->getTemperature(0);
85 msg_.right_driver_temp = system_status->getTemperature(1);
86 msg_.left_motor_temp = system_status->getTemperature(2);
87 msg_.right_motor_temp = system_status->getTemperature(3);
88 stat.
add(
"Uptime",
msg_.uptime);
90 stat.
add(
"Battery Voltage",
msg_.battery_voltage);
91 stat.
add(
"Left Motor Driver Voltage",
msg_.left_driver_voltage);
92 stat.
add(
"Right Motor Driver Voltage",
msg_.right_driver_voltage);
94 stat.
add(
"MCU and User Port Current",
msg_.mcu_and_user_port_current);
95 stat.
add(
"Left Motor Driver Current",
msg_.left_driver_current);
96 stat.
add(
"Right Motor Driver Current",
msg_.right_driver_current);
98 stat.
add(
"Left Motor Driver Temp (C)",
msg_.left_driver_temp);
99 stat.
add(
"Right Motor Driver Temp (C)",
msg_.right_driver_temp);
100 stat.
add(
"Left Motor Temp (C)",
msg_.left_motor_temp);
101 stat.
add(
"Right Motor Temp (C)",
msg_.right_motor_temp);
102 ROS_DEBUG_STREAM(
"Received Uptime:"<<
msg_.uptime<<
", Battery Voltage:"<<
msg_.battery_voltage<<
", Left Motor Driver Voltage:"<<
msg_.left_driver_voltage<<
", Right Motor Driver Voltage:"<<
msg_.right_driver_voltage<<
", " 103 "MCU and User Port Current:"<<
msg_.mcu_and_user_port_current<<
", Left Motor Driver Current:"<<
msg_.left_driver_current<<
",Right Motor Driver Current:"<<
msg_.right_driver_current<<
", " 104 "Left Motor Driver Temp (C):"<<
msg_.left_driver_temp<<
", Right Motor Driver Temp (C):"<<
msg_.right_driver_temp<<
", Left Motor Temp (C):"<<
msg_.left_motor_temp<<
", Right Motor Temp (C):"<<
msg_.right_motor_temp<<
" .");
106 stat.
summary(diagnostic_msgs::DiagnosticStatus::OK,
"System Status OK");
107 if (
msg_.battery_voltage > OVERVOLT_ERROR)
109 stat.
mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Main battery voltage too high");
111 else if (
msg_.battery_voltage > OVERVOLT_WARN)
113 stat.
mergeSummary(diagnostic_msgs::DiagnosticStatus::WARN,
"Main battery voltage too high");
115 else if (
msg_.battery_voltage < UNDERVOLT_ERROR)
117 stat.
mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Main battery voltage too low");
119 else if (
msg_.battery_voltage < UNDERVOLT_WARN)
121 stat.
mergeSummary(diagnostic_msgs::DiagnosticStatus::WARN,
"Main battery voltage too low");
125 stat.
mergeSummary(diagnostic_msgs::DiagnosticStatus::OK,
"Voltage OK");
128 if (std::max(
msg_.left_driver_temp,
msg_.right_driver_temp) > DRIVER_OVERTEMP_ERROR)
130 stat.
mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Motor drivers too hot");
132 else if (std::max(
msg_.left_driver_temp,
msg_.right_driver_temp) > DRIVER_OVERTEMP_WARN)
134 stat.
mergeSummary(diagnostic_msgs::DiagnosticStatus::WARN,
"Motor drivers too hot");
136 else if (std::max(
msg_.left_motor_temp,
msg_.right_motor_temp) > MOTOR_OVERTEMP_ERROR)
138 stat.
mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Motors too hot");
140 else if (std::max(
msg_.left_motor_temp,
msg_.right_motor_temp) > MOTOR_OVERTEMP_WARN)
142 stat.
mergeSummary(diagnostic_msgs::DiagnosticStatus::WARN,
"Motors too hot");
146 stat.
mergeSummary(diagnostic_msgs::DiagnosticStatus::OK,
"Temperature OK");
162 msg_.charge_estimate = power_status->getChargeEstimate(0);
163 msg_.capacity_estimate = power_status->getCapacityEstimate(0);
165 stat.
add(
"Charge (%)",
msg_.charge_estimate);
166 stat.
add(
"Battery Capacity (Wh)",
msg_.capacity_estimate);
167 ROS_DEBUG_STREAM(
"Received Charge (%%): "<<
msg_.charge_estimate<<
", Battery Capacity (Wh): "<<
msg_.capacity_estimate<<
" .");
169 stat.
summary(diagnostic_msgs::DiagnosticStatus::OK,
"Power System OK");
170 if (
msg_.charge_estimate < LOWPOWER_ERROR)
172 stat.
mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Low power");
174 else if (
msg_.charge_estimate < LOWPOWER_WARN)
176 stat.
mergeSummary(diagnostic_msgs::DiagnosticStatus::WARN,
"Low power");
180 stat.
mergeSummary(diagnostic_msgs::DiagnosticStatus::OK,
"Charge OK");
186 roch_msgs::RochStatus &msg)
197 uint16_t flags = safety_status->getFlags();
198 msg_.timeout = (flags & SAFETY_TIMEOUT) > 0;
199 msg_.lockout = (flags & SAFETY_LOCKOUT) > 0;
200 msg_.e_stop = (flags & SAFETY_ESTOP) > 0;
201 msg_.ros_pause = (flags & SAFETY_CCI) > 0;
202 msg_.no_battery = (flags & SAFETY_PSU) > 0;
203 msg_.current_limit = (flags & SAFETY_CURRENT) > 0;
205 stat.
add(
"Timeout", static_cast<bool>(
msg_.timeout));
206 stat.
add(
"Lockout", static_cast<bool>(
msg_.lockout));
207 stat.
add(
"Emergency Stop", static_cast<bool>(
msg_.e_stop));
208 stat.
add(
"ROS Pause", static_cast<bool>(
msg_.ros_pause));
209 stat.
add(
"No battery", static_cast<bool>(
msg_.no_battery));
210 stat.
add(
"Current limit", static_cast<bool>(
msg_.current_limit));
211 ROS_DEBUG_STREAM(
"Received Safety System Status, Timeout:"<<
msg_.timeout<<
", Lockout:"<<
msg_.lockout<<
", Emergency Stop:"<<
msg_.e_stop<<
", ROS Pause:"<<
msg_.ros_pause<<
", No battery:"<<
msg_.no_battery<<
", Current limit:"<<
msg_.current_limit<<
" .");
213 stat.
summary(diagnostic_msgs::DiagnosticStatus::OK,
"Safety System OK");
214 if ((flags & SAFETY_ERROR) > 0)
216 stat.
mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Safety System Error");
218 else if ((flags & SAFETY_WARN) > 0)
220 stat.
mergeSummary(diagnostic_msgs::DiagnosticStatus::WARN,
"Safety System Warning");
228 target_control_freq_(target_control_freq)
242 stat.
add(
"ROS Control Loop Frequency",
msg_.ros_control_loop_freq);
246 stat.
summary(diagnostic_msgs::DiagnosticStatus::OK,
"Software OK");
247 if (margin < CONTROLFREQ_WARN)
250 message <<
"Control loop executing " << 100 -
static_cast<int>(margin) <<
"% slower than desired";
251 stat.
mergeSummary(diagnostic_msgs::DiagnosticStatus::WARN, message.str());
void summary(unsigned char lvl, const std::string s)
void update(diagnostic_updater::DiagnosticStatusWrapper &stat, typename core::Channel< T >::Ptr &status)
void updateControlFrequency(double frequency)
rochSoftwareDiagnosticTask(roch_msgs::RochStatus &msg, double target_control_freq)
rochHardwareDiagnosticTask(roch_msgs::RochStatus &msg)
roch_msgs::RochStatus & msg_
void run(diagnostic_updater::DiagnosticStatusWrapper &stat)
def message(msg, args, kwargs)
#define ROS_DEBUG_STREAM(args)
void mergeSummary(unsigned char lvl, const std::string s)
DiagnosticTask(const std::string name)
void add(const std::string &key, const T &val)
double target_control_freq_
roch_msgs::RochStatus & msg_