diagnostic_updater.cpp
Go to the documentation of this file.
00001 
00024 #include <string>
00025 
00026 #include "boost/foreach.hpp"
00027 #include "diagnostic_updater/update_functions.h"
00028 #include "puma_motor_driver/diagnostic_updater.h"
00029 #include "puma_motor_msgs/Status.h"
00030 
00031 namespace puma_motor_driver
00032 {
00033 
00034   typedef diagnostic_msgs::DiagnosticStatus Status;
00035 
00036 PumaMotorDriverDiagnosticUpdater::PumaMotorDriverDiagnosticUpdater()
00037 {
00038   initialized_ = false;
00039   setHardwareID("none");
00040   status_sub_ = nh_.subscribe("status", 5, &PumaMotorDriverDiagnosticUpdater::statusCallback, this);
00041 }
00042 
00043 const char* PumaMotorDriverDiagnosticUpdater::getModeString(uint8_t mode)
00044 {
00045   switch (mode)
00046   {
00047     case puma_motor_msgs::Status::MODE_VOLTAGE:
00048       return "Voltage Control";
00049     case puma_motor_msgs::Status::MODE_CURRENT:
00050       return "Current Control";
00051     case puma_motor_msgs::Status::MODE_SPEED:
00052       return "Speed control";
00053     case puma_motor_msgs::Status::MODE_POSITION:
00054       return "Position control";
00055     case puma_motor_msgs::Status::MODE_VCOMP:
00056       return "Vcomp control";
00057     default:
00058       return "Unknown control";
00059   }
00060 }
00061 
00062 const char* PumaMotorDriverDiagnosticUpdater::getFaultString(uint8_t fault)
00063 {
00064   switch (fault)
00065   {
00066     case puma_motor_msgs::Status::FAULT_CURRENT:
00067       return "current fault";
00068     case puma_motor_msgs::Status::FAULT_TEMPERATURE:
00069       return "temperature fault";
00070     case puma_motor_msgs::Status::FAULT_BUS_VOLTAGE:
00071       return "bus voltage failt";
00072     case puma_motor_msgs::Status::FAULT_BRIDGE_DRIVER:
00073       return "bridge driver fault";
00074     default:
00075       return "unknown fault";
00076   }
00077 }
00078 
00079 void PumaMotorDriverDiagnosticUpdater::driverDiagnostics(diagnostic_updater::DiagnosticStatusWrapper& stat, int driver)
00080 {
00081   if (last_status_->drivers[driver].fault == 0)
00082   {
00083     stat.summary(Status::OK, "Motor driver is OK.");
00084   }
00085   else
00086   {
00087     stat.summaryf(Status::ERROR, "'%s' driver (%i) has a %s.",
00088       (last_status_->drivers[driver].device_name.c_str()),
00089        last_status_->drivers[driver].device_number,
00090        getFaultString(last_status_->drivers[driver].fault));
00091   }
00092 
00093   stat.add("Driver CAN ID", static_cast<int>(last_status_->drivers[driver].device_number));
00094   stat.add("Driver Role", last_status_->drivers[driver].device_name.c_str());
00095   stat.add("Driver Mode", getModeString(last_status_->drivers[driver].mode));
00096 
00097   stat.add("Input terminal voltage (V)", last_status_->drivers[driver].bus_voltage);
00098   stat.add("Internal driver temperature (degC)", last_status_->drivers[driver].temperature);
00099   stat.add("Voltage as output to the motor (V)", last_status_->drivers[driver].output_voltage);
00100   stat.add("Value of the auxiliary ADC (V)", last_status_->drivers[driver].analog_input);
00101 }
00102 
00103 void PumaMotorDriverDiagnosticUpdater::statusCallback(const puma_motor_msgs::MultiStatus::ConstPtr& status_msg)
00104 {
00105   last_status_ = status_msg;
00106   if (!initialized_)
00107   {
00108     for (int i = 0; i < status_msg->drivers.size(); i++)
00109     {
00110       char name[100];
00111       snprintf(name, sizeof(name), "Puma motor driver on: %s with CAN ID (%d)",
00112         last_status_->drivers[i].device_name.c_str(), last_status_->drivers[i].device_number);
00113       add(name, boost::bind(&PumaMotorDriverDiagnosticUpdater::driverDiagnostics, this, _1, i));
00114     }
00115     initialized_ = true;
00116   }
00117   else
00118   {
00119     update();
00120   }
00121 }
00122 
00123 }  // namespace puma_motor_driver


puma_motor_driver
Author(s):
autogenerated on Sat Jun 8 2019 18:55:15