xbot_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>
42 #include "xbot_node/xbot_ros.hpp"
43 
44 
45 namespace xbot
46 {
47 
49 {
50 public:
53  {
54  NODELET_DEBUG_STREAM("Xbot : waiting for update thread to finish.");
55  shutdown_requested_ = true;
56  update_thread_.join();
57  }
58  virtual void onInit()
59  {
60  NODELET_DEBUG_STREAM("Xbot : initialising nodelet...");
61  std::string nodelet_name = this->getName();
62  xbot_.reset(new XbotRos(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 (xbot_->init(this->getPrivateNodeHandle()))
65  {
66  update_thread_.start(&XbotNodelet::update, *this);
67  NODELET_INFO_STREAM("Xbot : initialised.");
68  }
69  else
70  {
71  NODELET_ERROR_STREAM("Xbot : could not initialise! Please restart.");
72  }
73  }
74 private:
75  void update()
76  {
77  ros::Rate spin_rate(10);//check the state every 0.1sec
78  while (!shutdown_requested_ && ros::ok() && xbot_->update())
79  {
80  spin_rate.sleep();
81  }
82  }
83 
85  ecl::Thread update_thread_;
87 };
88 
89 } // namespace xbot
90 
#define NODELET_INFO_STREAM(...)
Wraps the xbot driver in a ROS-specific library.
virtual void onInit()
const std::string & getName() const
boost::shared_ptr< XbotRos > xbot_
#define NODELET_ERROR_STREAM(...)
ecl::Thread update_thread_
ROSCPP_DECL bool ok()
#define NODELET_DEBUG_STREAM(...)
bool sleep()
PLUGINLIB_EXPORT_CLASS(xbot::XbotNodelet, nodelet::Nodelet)


xbot_node
Author(s): Roc, wangpeng@droid.ac.cn
autogenerated on Sat Oct 10 2020 03:28:13