nodelet.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2012, Yujin Robot.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of Yujin Robot nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00039 /*****************************************************************************
00040  ** Includes
00041  *****************************************************************************/
00042 
00043 #include <ecl/threads/thread.hpp>
00044 #include "roch_safety_controller/safety_controller.hpp"
00045 #include <boost/concept_check.hpp>
00046 
00047 
00048 namespace sawyer
00049 {
00050 
00051 class SafetyControllerNodelet 
00052 {
00053 public:
00054   SafetyControllerNodelet() : shutdown_requested_(false) { onInit();};
00055   ~SafetyControllerNodelet()
00056   {
00057     ROS_DEBUG("Waiting for update thread to finish.");
00058     shutdown_requested_ = true;
00059     update_thread_.join();
00060   }
00061   void onInit()
00062   {
00063  
00064     // resolve node(let) name
00065     std::string name = nh.getUnresolvedNamespace();
00066     int pos = name.find_last_of('/');
00067     name = name.substr(pos + 1);
00068     ROS_DEBUG("Initialising nodelet... [  %s  ]",name.c_str());
00069     controller_.reset(new SafetyController(nh, name));
00070     if (controller_->init())
00071     {
00072       ROS_DEBUG("roch initialised. Spinning up update thread ... [ %s ]",name.c_str());
00073       update_thread_.start(&SafetyControllerNodelet::update, *this);
00074       ROS_DEBUG("Nodelet initialised. [ %s ]",name.c_str());
00075     }
00076     else
00077     {
00078       ROS_DEBUG("Couldn't initialise nodelet! Please restart. [ %s ]",name.c_str());
00079     }
00080    
00081   }
00082 private:
00083   void update()
00084   {
00085     ros::Rate spin_rate(10);
00086     controller_->enable(); // enable the controller when loading the nodelet
00087     while (! shutdown_requested_ && ros::ok())
00088     {
00089       controller_->spin();
00090       spin_rate.sleep();
00091     }
00092   }
00093 
00094   boost::shared_ptr<SafetyController> controller_;
00095   ecl::Thread update_thread_;
00096   bool shutdown_requested_;
00097   ros::NodeHandle nh;
00098 };
00099 
00100 } // namespace roch
00101 
00102 int main(int argc, char** argv){
00103   
00104   ros::init(argc,argv,"roch_safety_controller_nodelet");
00105   
00106   sawyer::SafetyControllerNodelet saftycon;
00107   
00108   ros::spin();
00109   
00110   return 0;
00111 }


roch_safety_controller
Author(s): Marcus Liebhardt , Carl
autogenerated on Sat Jun 8 2019 20:32:46