ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Insert elements to a map listing the nodes

asked 2017-12-04 14:17:14 -0500

robo_ninja gravatar image

updated 2017-12-04 14:21:03 -0500

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)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-12-05 01:13:51 -0500

mgruhler gravatar image

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:

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2017-12-04 14:17:14 -0500

Seen: 152 times

Last updated: Dec 05 '17