42 #include <boost/thread.hpp> 45 #include "diagnostic_msgs/DiagnosticStatus.h" 46 #include "diagnostic_msgs/SelfTest.h" 92 private_node_handle_(ph)
96 ops.
init<diagnostic_msgs::SelfTest::Request, diagnostic_msgs::SelfTest::Response>(
"self_test", boost::bind(&
TestRunner::doTest,
this, _1, _2));
130 bool doTest(diagnostic_msgs::SelfTest::Request &req,
131 diagnostic_msgs::SelfTest::Response &res)
134 bool ignore_set_id_warn =
false;
136 if (node_handle_.
ok())
142 std::vector<diagnostic_msgs::DiagnosticStatus> status_vec;
144 const std::vector<DiagnosticTaskInternal> &tasks = getTasks();
145 for (std::vector<DiagnosticTaskInternal>::const_iterator iter = tasks.begin();
146 iter != tasks.end(); iter++)
150 ROS_ERROR(
"ROS has shut down. Exiting.");
157 status.message =
"No message was set";
160 ROS_INFO(
"Starting test: %s", iter->getName().c_str());
163 }
catch (std::exception& e)
166 status.message =
std::string(
"Uncaught exception: ") + e.what();
167 ignore_set_id_warn =
true;
170 if (status.level >= 1)
172 ROS_WARN(
"Non-zero self-test test status. Name: '%s', status %i: '%s'", status.name.c_str(), status.level, status.message.c_str());
174 status_vec.push_back(status);
177 if (!ignore_set_id_warn && id_.empty())
178 ROS_WARN(
"setID was not called by any self-test. The node author should be notified. If there is no suitable ID for this node, an ID of 'none' should be used.");
184 for (std::vector<diagnostic_msgs::DiagnosticStatus>::iterator status_iter = status_vec.begin();
185 status_iter != status_vec.end();
188 if (status_iter->level >= 2)
192 if (res.passed && id_ == unspecified_id)
193 ROS_WARN(
"Self-test passed, but setID was not called. This is a bug in the driver. Please report it.");
195 res.status = status_vec;
CallbackQueueInterface * callback_queue
void init(const std::string &_service, const boost::function< bool(MReq &, MRes &)> &_callback)
bool doTest(diagnostic_msgs::SelfTest::Request &req, diagnostic_msgs::SelfTest::Response &res)
ros::NodeHandle private_node_handle_
void add(const std::string &name, TaskFunction f)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
ros::ServiceServer service_server_
ROSCPP_DECL bool isShuttingDown()
void checkTest()
Check if a self-test is pending. If so, start it and wait for it to complete.
Class to facilitate the creation of component self-tests.
ros::NodeHandle node_handle_
void setID(std::string id)
Sets the ID of the part being tested.
ros::CallbackQueue self_test_queue_
TestRunner(ros::NodeHandle h=ros::NodeHandle(), ros::NodeHandle ph=ros::NodeHandle("~"))
Constructs a dispatcher.