kobuki_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  */
35 /*****************************************************************************
36  ** Includes
37  *****************************************************************************/
38 
39 #include <nodelet/nodelet.h>
41 #include <ecl/threads/thread.hpp>
43 
44 
45 namespace kobuki
46 {
47 
49 {
50 public:
53  {
54  NODELET_DEBUG_STREAM("Kobuki : waiting for update thread to finish.");
55  shutdown_requested_ = true;
56  update_thread_.join();
57  }
58  virtual void onInit()
59  {
60  NODELET_DEBUG_STREAM("Kobuki : initialising nodelet...");
61  std::string nodelet_name = this->getName();
62  kobuki_.reset(new KobukiRos(nodelet_name));
63  // if there are latency issues with callbacks, we might want to move to process callbacks in multiple threads (use MTPrivateNodeHandle)
64  if (kobuki_->init(this->getPrivateNodeHandle(), this->getNodeHandle()))
65  {
67  NODELET_INFO_STREAM("Kobuki : initialised.");
68  }
69  else
70  {
71  NODELET_ERROR_STREAM("Kobuki : could not initialise! Please restart.");
72  }
73  }
74 private:
75  void update()
76  {
77  ros::Rate spin_rate(10);
78  while (!shutdown_requested_ && ros::ok() && kobuki_->update())
79  {
80  spin_rate.sleep();
81  }
82  }
83 
85  ecl::Thread update_thread_;
87 };
88 
89 } // namespace kobuki
90 
#define NODELET_INFO_STREAM(...)
boost::shared_ptr< KobukiRos > kobuki_
const std::string & getName() const
#define NODELET_ERROR_STREAM(...)
PLUGINLIB_EXPORT_CLASS(kobuki::KobukiNodelet, nodelet::Nodelet)
Wraps the kobuki driver in a ROS-specific library.
ROSCPP_DECL bool ok()
ros::NodeHandle & getNodeHandle() const
#define NODELET_DEBUG_STREAM(...)
bool sleep()


kobuki_node
Author(s): Daniel Stonier, Younghun Ju, Jorge Santos Simon
autogenerated on Mon Jun 10 2019 13:45:13