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 <boost/thread.hpp>
42 
44 
45 
46 namespace kobuki
47 {
48 
50 {
51  public:
54  {
55  NODELET_DEBUG_STREAM("Kobuki : waiting for update thread to finish.");
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 FakeKobukiRos(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()))
65  {
66  update_thread_ = boost::thread(&SoftKobukiNodelet::update,this);
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(30);
78  while (ros::ok() && kobuki_->update())
79  {
80  spin_rate.sleep();
81  }
82  }
83 
85  boost::thread update_thread_;
86 };
87 
88 } // namespace kobuki
89 
#define NODELET_INFO_STREAM(...)
const std::string & getName() const
PLUGINLIB_EXPORT_CLASS(kobuki::SoftKobukiNodelet, nodelet::Nodelet)
#define NODELET_ERROR_STREAM(...)
ROSCPP_DECL bool ok()
#define NODELET_DEBUG_STREAM(...)
bool sleep()
boost::shared_ptr< FakeKobukiRos > kobuki_


kobuki_softnode
Author(s): Jihoon Lee
autogenerated on Mon Jun 10 2019 13:52:14