nodelet.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, Yujin Robot.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of Yujin Robot nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
39 /*****************************************************************************
40  ** Includes
41  *****************************************************************************/
42 
43 #include <nodelet/nodelet.h>
45 #include <ecl/threads/thread.hpp>
47 
48 
49 namespace kobuki
50 {
51 
53 {
54 public:
57  {
58  NODELET_DEBUG_STREAM("Waiting for update thread to finish.");
59  shutdown_requested_ = true;
60  update_thread_.join();
61  }
62  virtual void onInit()
63  {
65  // resolve node(let) name
66  std::string name = nh.getUnresolvedNamespace();
67  int pos = name.find_last_of('/');
68  name = name.substr(pos + 1);
69  NODELET_INFO_STREAM("Initialising nodelet... [" << name << "]");
70  controller_.reset(new SafetyController(nh, name));
71  if (controller_->init())
72  {
73  NODELET_INFO_STREAM("Kobuki initialised. Spinning up update thread ... [" << name << "]");
75  NODELET_INFO_STREAM("Nodelet initialised. [" << name << "]");
76  }
77  else
78  {
79  NODELET_ERROR_STREAM("Couldn't initialise nodelet! Please restart. [" << name << "]");
80  }
81  }
82 private:
83  void update()
84  {
85  ros::Rate spin_rate(10);
86  controller_->enable(); // enable the controller when loading the nodelet
87  while (! shutdown_requested_ && ros::ok())
88  {
89  controller_->spin();
90  spin_rate.sleep();
91  }
92  }
93 
95  ecl::Thread update_thread_;
97 };
98 
99 } // namespace kobuki
100 
#define NODELET_INFO_STREAM(...)
const std::string & getUnresolvedNamespace() const
Kobuki-specific safety controller.
PLUGINLIB_EXPORT_CLASS(kobuki::SafetyControllerNodelet, nodelet::Nodelet)
boost::shared_ptr< SafetyController > controller_
Definition: nodelet.cpp:94
ros::NodeHandle & getPrivateNodeHandle() const
#define NODELET_ERROR_STREAM(...)
ROSCPP_DECL bool ok()
#define NODELET_DEBUG_STREAM(...)
bool sleep()


kobuki_safety_controller
Author(s): Marcus Liebhardt
autogenerated on Mon Jun 10 2019 13:45:09