Publishing diagnostics from C++?
Are there any examples of how to publish diagnostics messages from C++? I can only find examples using Python.
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
Are there any examples of how to publish diagnostics messages from C++? I can only find examples using Python.
Its like publishing anything else.
Setup a Publisher, fill in the Message and publish it.
Here is a completely senseless example but gives you perhaps an idea:
#include "ros/ros.h"
#include <diagnostic_msgs/DiagnosticArray.h>
#include <diagnostic_msgs/DiagnosticStatus.h>
#include <diagnostic_msgs/KeyValue.h>
int main(int argc, char **argv)
{
ros::init(argc, argv, "diagnostics");
ros::NodeHandle nh;
ros::Publisher diagnostic_pub = nh.advertise<diagnostic_msgs::DiagnosticArray>("/diagnostics", 1);
ros::Rate loop_rate(10);
while (ros::ok())
{
diagnostic_msgs::DiagnosticArray dia_array;
diagnostic_msgs::DiagnosticStatus robot_status;
robot_status.name = "Robot";
robot_status.level = diagnostic_msgs::DiagnosticStatus::OK;
robot_status.message = "Everything seem to be ok.";
diagnostic_msgs::KeyValue emergency;
emergency.key = "Emgergencystop hit";
emergency.value = "false";
diagnostic_msgs::KeyValue exited_normally;
emergency.key = "Exited normally";
emergency.value = "true";
robot_status.values.push_back(emergency);
robot_status.values.push_back(exited_normally);
diagnostic_msgs::DiagnosticStatus eth_status;
eth_status.name = "EtherCAT Master";
eth_status.level = diagnostic_msgs::DiagnosticStatus::OK;
eth_status.message = "Running";
dia_array.status.push_back(robot_status);
dia_array.status.push_back(eth_status);
diagnostic_pub.publish(dia_array);
ros::spinOnce();
loop_rate.sleep();
}
return 0;
}
If you running a full ROS (and not rosserial on an Arduino) you can use the diagnostic_updater package to automatically fill in the diagnostics message and publish it.
The diagnostics_updater package also includes diagnosed publishers that you can use to make sure that you're publishing at your desired rate.
The diagnostics_updater package ships with some fairly good examples: http://docs.ros.org/api/diagnostic_up...
Asked: 2017-05-21 20:33:00 -0600
Seen: 2,472 times
Last updated: May 22 '17
Error in tutorial creating a diagnostic analyzer (in python) [closed]
Diagnostics not seen on local but seen on Robot (running ROS MASTER).
Removing a prefix from a Diagnostics Aggregator Group
Alternative to diagnostic_aggregator and robot_monitor?
Robot_localization diagnostics topic question
Is there a robot monitor node?
rqt_robot_monitor (RuntimeError: deque mutated during iteration)
log level in diagnostics package.