0
$\begingroup$

Rosanswers logo

I am subscribing to /diagnostics topic, to which all my nodes are publishing their outputs. In my source file, I have created a map of all the node names as follows -

std::map<string, int> TextCode;
TextCode = {{"Camera_node1", 1}, {"LIDAR_node2", 2}};

I have prepopulated the map with few nodes (as above). I have a callback function, in which I publish the node name whenever the level of operation is ERROR -

void diagnosticCallback(const diagnostic_msgs::DiagnosticArrayPtr &diags_msg)
{
  int Maincode;
  if (diags_msg->status[0].level == diagnostic_msgs::DiagnosticStatus::ERROR)
  {
    Maincode = TextCode[diags_msg->status[0].name];
    ROS_INFO_STREAM("Error occured : " << Maincode);
  }
  else if (diags_msg->status[0].level == diagnostic_msgs::DiagnosticStatus::OK)
  {
    Maincode = TextCode[diags_msg->status[0].name];
    ROS_INFO_STREAM("No error");
  }
}

I want to check the node names every time we receive ERROR and then check all the elements of my map TextCode, if the name is present. If not then add the name as the next element in the map. How should I proceed with that?

Note - Diagnostics_msgs - http://docs.ros.org/api/diagnostic_msgs/html/msg/DiagnosticStatus.html


Originally posted by robo_ninja on ROS Answers with karma: 55 on 2017-12-04

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

This is not really a ROS related question... This is about regular programming...

So, if you receive ERROR you want to check if there is already an error stored in the map, and if not, add it? You can use the Standard std::map functions:


Originally posted by mgruhler with karma: 12390 on 2017-12-05

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.