mrp2_analyzer.cpp
Go to the documentation of this file.
00001 #include "mrp2_analyzer/mrp2_analyzer.h"
00002 
00003 using namespace diagnostic_aggregator;
00004 using namespace std;
00005 
00006 PLUGINLIB_EXPORT_CLASS(diagnostic_aggregator::MRP2Analyzer,
00007                        diagnostic_aggregator::Analyzer)
00008 
00009 MRP2Analyzer::MRP2Analyzer() :
00010   l_motor_path_(""), r_motor_path_(""), battery_path_(""), lights_path_(""), power_board_name_(""), 
00011   runstop_hit_(false), has_initialized_(false), has_motor_l_data_(false), has_motor_r_data_(false),  
00012   has_battery_data_(false), has_lights_data_(false)
00013 { }
00014 
00015 MRP2Analyzer::~MRP2Analyzer() { }
00016 
00017 bool MRP2Analyzer::init(const string base_name, const ros::NodeHandle &n)
00018 { 
00019   // path_ = BASE_NAME/Motors
00020   motors_path_ = base_name + "Motors";
00021   l_motor_path_ = motors_path_ + "/Motor Left";
00022   r_motor_path_ = motors_path_ + "/Motor Right";
00023   battery_path_ = base_name + "Battery";
00024   lights_path_ = base_name + "Lights";
00025 
00026   if (!n.getParam("power_board_name", power_board_name_))
00027   {
00028      ROS_ERROR("No powerboard name was specified in MRP2Analyzer! Powerboard must be \"MRP2 Powerboard XX\". Namespace: %s", n.getNamespace().c_str());
00029      return false;
00030   }
00031 
00032   boost::shared_ptr<StatusItem> item_l_motor(new StatusItem("Motor Left"));
00033   boost::shared_ptr<StatusItem> item_r_motor(new StatusItem("Motor Right"));
00034   boost::shared_ptr<StatusItem> item_battery(new StatusItem("Battery"));
00035   boost::shared_ptr<StatusItem> item_lights(new StatusItem("Lights"));
00036 
00037   motor_l_item_ = item_l_motor;
00038   motor_r_item_ = item_r_motor;
00039   battery_item_ = item_battery;
00040   lights_item_ = item_lights;
00041 
00042   has_initialized_ = true;
00043   
00044   return true;
00045 }
00046 
00047 bool MRP2Analyzer::match(const std::string name)
00048 {
00049   if (name == "Motor Left" || name == "Motor Right" || name == "Battery" || name == "Lights" )
00050     return true;
00051 
00052   return name == power_board_name_;
00053 }
00054 
00055 bool MRP2Analyzer::analyze(const boost::shared_ptr<StatusItem> item)
00056 {
00057 
00058   if(item->getName() == "Motor Left")
00059   {
00060         has_motor_l_data_ = true;
00061         stall_l_ = item->getValue("Stall") == "True";
00062         motors_controller_halt_ = item->getValue("Controller Halt") == "True";
00063 
00064         has_motor_l_data_ = true;
00065 
00066         motor_l_item_ = item;
00067         return true;
00068   }
00069 
00070   if(item->getName() == "Motor Right")
00071   {
00072         has_motor_r_data_ = true;
00073         stall_r_ = item->getValue("Stall") == "True";
00074         motors_controller_halt_ = item->getValue("Controller Halt") == "True";
00075 
00076         has_motor_r_data_ = true;
00077 
00078         motor_r_item_ = item;
00079         return true;
00080   }
00081 
00082   if(item->getName() == "Battery")
00083   {
00084         has_battery_data_ = true;
00085         batt_high_ = item->getValue("Over Voltage") == "True";
00086         batt_low_ = item->getValue("Under Voltage") == "True";
00087         battery_item_ = item;
00088         return true;    
00089   }
00090 
00091   if(item->getName() == "Lights")
00092   {
00093         has_lights_data_ = true;
00094         lights_controller_halt_ = item->getValue("Controller Halt") == "True";
00095         lights_item_ = item;
00096         return true;
00097   }
00098 
00099   return false;
00100 }
00101 
00102 vector<boost::shared_ptr<diagnostic_msgs::DiagnosticStatus> > MRP2Analyzer::report()
00103 {
00104   boost::shared_ptr<diagnostic_msgs::DiagnosticStatus> motor_l_stat = motor_l_item_->toStatusMsg(l_motor_path_);
00105   boost::shared_ptr<diagnostic_msgs::DiagnosticStatus> motor_r_stat = motor_r_item_->toStatusMsg(r_motor_path_);
00106   boost::shared_ptr<diagnostic_msgs::DiagnosticStatus> battery_stat = battery_item_->toStatusMsg(battery_path_);
00107   boost::shared_ptr<diagnostic_msgs::DiagnosticStatus> lights_stat = lights_item_->toStatusMsg(lights_path_);
00108 
00109   boost::shared_ptr<diagnostic_msgs::DiagnosticStatus> motors_stat(new diagnostic_msgs::DiagnosticStatus());
00110 
00111   motors_stat->name = motors_path_;
00112   motor_l_stat->name = l_motor_path_;
00113   motor_r_stat->name = r_motor_path_;
00114   battery_stat->name = battery_path_;
00115   lights_stat->name = lights_path_;
00116 
00117   if (has_motor_l_data_ && !stall_l_ && !motors_controller_halt_)
00118   {
00119     motor_l_stat->level = diagnostic_msgs::DiagnosticStatus::OK;
00120   }else{
00121     motor_l_stat->level = diagnostic_msgs::DiagnosticStatus::ERROR;
00122   }
00123 
00124   if (has_motor_r_data_ && !stall_r_ && !motors_controller_halt_)
00125   {
00126     motor_r_stat->level = diagnostic_msgs::DiagnosticStatus::OK;
00127   }else{
00128     motor_r_stat->level = diagnostic_msgs::DiagnosticStatus::ERROR;
00129   }
00130 
00131   if (motor_l_stat->level == diagnostic_msgs::DiagnosticStatus::ERROR || motor_r_stat->level == diagnostic_msgs::DiagnosticStatus::ERROR)
00132   {
00133     motors_stat->level = diagnostic_msgs::DiagnosticStatus::ERROR;
00134   }else{
00135     motors_stat->level = diagnostic_msgs::DiagnosticStatus::OK;
00136   }
00137 
00138   if(has_lights_data_ && !lights_controller_halt_)
00139   {
00140         lights_stat->level = diagnostic_msgs::DiagnosticStatus::OK;
00141   }else{
00142         lights_stat->level = diagnostic_msgs::DiagnosticStatus::ERROR;
00143   }
00144 
00145   if(has_battery_data_ && !batt_low_ && !batt_high_)
00146   {
00147         battery_stat->level = diagnostic_msgs::DiagnosticStatus::OK;
00148   }else if(batt_low_ || batt_high_){
00149         battery_stat->level = diagnostic_msgs::DiagnosticStatus::ERROR;
00150   }
00151 
00152 
00153   vector<boost::shared_ptr<diagnostic_msgs::DiagnosticStatus> > output;
00154   output.push_back(motors_stat);
00155   output.push_back(motor_l_stat);
00156   output.push_back(motor_r_stat);
00157   output.push_back(battery_stat);
00158   output.push_back(lights_stat);
00159 
00160   return output;
00161 }


mrp2_analyzer
Author(s): Bolkar Altuntas
autogenerated on Sat Jun 8 2019 20:52:15