node.cpp
Go to the documentation of this file.
00001 
00006 #include <signal.h>
00007 #include <ros/ros.h>
00008 #include <ros/xmlrpc_manager.h>
00009 #include "slam/base.h"
00010 
00011 // Signal-safe flag for whether shutdown is requested
00012 sig_atomic_t volatile g_request_shutdown = 0;
00013 
00014 // Replacement SIGINT handler
00015 void sigIntHandler(int sig)
00016 {
00017   g_request_shutdown = 1;
00018 }
00019 
00020 // Replacement "shutdown" XMLRPC callback
00021 void shutdownCallback(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result)
00022 {
00023   int num_params = 0;
00024   if (params.getType() == XmlRpc::XmlRpcValue::TypeArray)
00025     num_params = params.size();
00026   if (num_params > 1)
00027   {
00028     std::string reason = params[1];
00029     ROS_WARN("Shutdown request received. Reason: [%s]", reason.c_str());
00030     g_request_shutdown = 1; // Set flag
00031   }
00032 
00033   result = ros::xmlrpc::responseInt(1, "", 0);
00034 }
00035 
00036 int main(int argc, char **argv)
00037 {
00038   // Override SIGINT handler
00039   ros::init(argc, argv, "stereo_slam", ros::init_options::NoSigintHandler);
00040   signal(SIGINT, sigIntHandler);
00041 
00042   // Override XMLRPC shutdown
00043   ros::XMLRPCManager::instance()->unbind("shutdown");
00044   ros::XMLRPCManager::instance()->bind("shutdown", shutdownCallback);
00045 
00046   // Stereo slam class
00047   ros::NodeHandle nh;
00048   ros::NodeHandle nh_private("~");
00049   slam::SlamBase slam_node(nh,nh_private);
00050 
00051   // Do our own spin loop
00052   while (!g_request_shutdown)
00053   {
00054     // Do non-callback stuff
00055     ros::spinOnce();
00056     usleep(100000);
00057   }
00058 
00059   // Finalize stereo slam
00060   slam_node.finalize();
00061 
00062   // Exit
00063   ros::shutdown();
00064 }


stereo_slam
Author(s): Pep Lluis Negre
autogenerated on Thu Aug 27 2015 15:24:22