# Revision history [back]

### Insert elements to a map listing the nodes

I am subscribing to [/diagnostics](http://docs.ros.org/api/diagnostic_msgs/html/msg/DiagnosticStatus.html) 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;
Text Code = {{"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 everytime there is ERROR and then check all the elements of my map, if the name is present. If not then add the name as the next element in the map. How should I proceed with that?

### Insert elements to a map listing the nodes

I am subscribing to [/diagnostics](http://docs.ros.org/api/diagnostic_msgs/html/msg/DiagnosticStatus.html)/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;
Text Code = {{"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 everytime there is ERROR and then check all the elements of my map, 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

### Insert elements to a map listing the nodes

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;
Text Code = {{"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 everytime there is ERROR and then check all the elements of my map, 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

### Insert elements to a map listing the nodes

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;
Text Code 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 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 everytime there is ERROR every time we receive ERROR and then check all the elements of my map, 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

### Insert elements to a map listing the nodes

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', 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