hek_teleop_main.cpp
Go to the documentation of this file.
00001 
00002 //
00003 // Package:   RoadNarrows Robotics Hekateros Robotic Manipulator ROS Package
00004 //
00005 // Link:      https://github.com/roadnarrows-robotics/hekateros
00006 //
00007 // ROS Node:  hek_teleop
00008 //
00009 // File:      hek_teleop_main.cpp
00010 //
00026 /*
00027  * @EulaBegin@
00028  * 
00029  * Permission is hereby granted, without written agreement and without
00030  * license or royalty fees, to use, copy, modify, and distribute this
00031  * software and its documentation for any purpose, provided that
00032  * (1) The above copyright notice and the following two paragraphs
00033  * appear in all copies of the source code and (2) redistributions
00034  * including binaries reproduces these notices in the supporting
00035  * documentation.   Substantial modifications to this software may be
00036  * copyrighted by their authors and need not follow the licensing terms
00037  * described here, provided that the new terms are clearly indicated in
00038  * all files where they apply.
00039  * 
00040  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY MEMBERS/EMPLOYEES
00041  * OF ROADNARROW LLC OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY
00042  * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
00043  * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
00044  * EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF
00045  * THE POSSIBILITY OF SUCH DAMAGE.
00046  * 
00047  * THE AUTHOR AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
00048  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
00049  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
00050  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
00051  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
00052  * 
00053  * @EulaEnd@
00054  */
00056 
00057 
00058 //
00059 // System
00060 // 
00061 #include <unistd.h>
00062 #include <signal.h>
00063 #include <string>
00064 
00065 //
00066 // ROS 
00067 //
00068 #include "ros/ros.h"
00069 
00070 //
00071 // RoadNarrows
00072 //
00073 #include "rnr/rnrconfig.h"
00074 #include "rnr/log.h"
00075 #include "rnr/opts.h"
00076 
00077 //
00078 // Node headers.
00079 //
00080 #include "hek_teleop.h"
00081 
00082 using namespace ::std;
00083 using namespace hekateros;
00084 using namespace hekateros_control;
00085 
00086 
00087 //. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 
00088 // Node Specific Defines and Data
00089 //. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 
00090 
00091 //
00092 // Application exit codes
00093 //
00094 #define APP_EC_OK   0   ///< success
00095 #define APP_EC_INIT 2   ///< initialization fatal error
00096 #define APP_EC_EXEC 4   ///< execution fatal error
00097 
00098 #define NO_SIGNAL   0   ///< no signal receieved value
00099 
00100 //
00101 // Data
00102 //
00103 const char *NodeName  = "hek_teleop";  
00104 static int  RcvSignal = NO_SIGNAL;      
00105 
00106 
00107 
00108 //. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 
00109 // RoadNarrows Specific Defines and Data
00110 //. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 
00111 
00112 //
00113 // Options
00114 //
00115 
00122 static const PkgInfo_T PkgInfo =
00123 {
00124   NodeName,                       
00125   "1.1.0",                        
00126   "2014.03.18",                   
00127   "2014",                         
00128   NodeName,                       
00129   "Robin Knight, Daniel Packard", 
00130   "RoadNarrows LLC",              
00131   "(C) 2013-2014 RoadNarrows LLC" 
00132 };
00133 
00137 static OptsPgmInfo_T AppPgmInfo =
00138 {
00139   // usage_args
00140   "[ROSOPTIONS]",
00141 
00142   // synopsis
00143   "The %P ROS node provides ROS interfaces to the embedded Hekateros "
00144   "robotic manipulator.",
00145   
00146   // long_desc 
00147   "",
00148  
00149   // diagnostics
00150   NULL
00151 };
00152 
00156 static OptsInfo_T AppOptsInfo[] =
00157 {
00158 
00159   {NULL, }
00160 };
00161 
00169 static void sigHandler(int sig)
00170 {
00171   RcvSignal = sig;
00172 
00173   // All the default sigint handler does is call shutdown()
00174   //ros::shutdown();
00175 }
00176 
00185 int main(int argc, char *argv[])
00186 {
00187   string  strNodeName;  // ROS-given node name
00188   double  hz = 30;
00189   int     rc;
00190 
00191   // 
00192   // Initialize the node. Parse the command line arguments and environment to
00193   // determine ROS options such as node name, namespace and remappings.
00194   // This call does not contact the master. This lets you use
00195   // ros::master::check() and other ROS functions after calling ros::init()
00196   // to check on the status of the master.
00197   //
00198   ros::init(argc, argv, NodeName);
00199 
00200   //
00201   // Parse node-specific options and arguments (from librnr).
00202   //
00203   OptsGet(NodeName, &PkgInfo, &AppPgmInfo, AppOptsInfo, true, &argc, argv);
00204  
00205   //
00206   //
00207   // A ctrl-c interrupt will stop attempts to connect to the ROS core.
00208   //
00209   ros::NodeHandle nh(NodeName);
00210 
00211   // actual ROS-given node name
00212   strNodeName = ros::this_node::getName();
00213 
00214   //
00215   // Failed to connect.
00216   //
00217   if( !ros::master::check() )
00218   {
00219     // add optional non-ROS unit tests here, then simply exit.
00220     return APP_EC_OK;
00221   }
00222 
00223   //
00224   // Signals
00225   //
00226 
00227   // Override the default ros sigint handler. This must be set after the first
00228   // NodeHandle is created.
00229   signal(SIGINT, sigHandler);
00230 
00231   // try to end safely with this signal
00232   signal(SIGTERM, sigHandler);
00233 
00234   ROS_INFO("%s: Node started.", strNodeName.c_str());
00235   
00236   //
00237   // Create a Hekateros teleoperation node object.
00238   //
00239   HekTeleop  teleop(nh, hz);
00240 
00241   //
00242   // Advertise server services.
00243   //
00244   teleop.advertiseServices();
00245 
00246   ROS_INFO("%s: Server services registered.", strNodeName.c_str());
00247 
00248   //
00249   // Initializedd client services.
00250   //
00251   teleop.clientServices();
00252 
00253   ROS_INFO("%s: Client services initialized.", strNodeName.c_str());
00254 
00255   //
00256   // Advertise publishers.
00257   //
00258   teleop.advertisePublishers();
00259   
00260   ROS_INFO("%s: Publishers registered.", strNodeName.c_str());
00261   
00262   //
00263   // Subscribed to topics.
00264   //
00265   teleop.subscribeToTopics();
00266   
00267   ROS_INFO("%s: Subscribed topics registered.", strNodeName.c_str());
00268 
00269   // set loop rate in Hertz
00270   ros::Rate loop_rate(hz);
00271 
00272   ROS_INFO("%s: Ready.", strNodeName.c_str());
00273 
00274   //
00275   // Main loop.
00276   //
00277   while( (RcvSignal == NO_SIGNAL) && ros::ok() )
00278   {
00279     // make any callbacks on pending ROS events
00280     ros::spinOnce(); 
00281 
00282     // check integrity of communications
00283     teleop.commCheck();
00284 
00285     // sleep to keep at loop rate
00286     loop_rate.sleep();
00287   }
00288 
00289   if( ros::ok() )
00290   {
00291     teleop.putRobotInSafeMode(true);
00292     usleep(1000000);
00293   }
00294 
00295   return APP_EC_OK;
00296 }


hekateros_control
Author(s): Robin Knight , Daniel Packard
autogenerated on Mon Oct 6 2014 00:36:42