nodelet.cpp
Go to the documentation of this file.
1 
10 /*****************************************************************************
11 ** Includes
12 *****************************************************************************/
13 #include <string>
14 #include <ecl/threads/thread.hpp>
15 #include <nodelet/nodelet.h>
18 
19 
20 namespace kobuki
21 {
22 
27 {
28 public:
31  {
32  shutdown_requested_ = true;
33  NODELET_DEBUG_STREAM("Waiting for update thread to finish. [" << name_ << "]");
34  update_thread_.join();
35  NODELET_INFO_STREAM("Controller is shutting down. [" << name_ << "]");
36  }
37 
43  virtual void onInit()
44  {
45  ros::NodeHandle nh_priv = this->getPrivateNodeHandle();
46 
47  // resolve node(let) name
48  std::string name = nh_priv.getUnresolvedNamespace();
49  int pos = name.find_last_of('/');
50  name_ = name.substr(pos + 1);
51 
52  NODELET_INFO_STREAM("Initialising nodelet ... [" << name_ << "]");
53  controller_.reset(new RandomWalkerController(nh_priv, name_));
54 
55  nh_priv.param("update_rate", update_rate_, 10.0);
56  NODELET_INFO_STREAM("Controller will spin at " << update_rate_ << " hz. [" << name_ << "]");
57 
58  // Initialises the controller
59  if (controller_->init())
60  {
61  NODELET_INFO_STREAM("Nodelet initialised. Spinning up update thread. [" << name_ << "]");
63  }
64  else
65  {
66  NODELET_ERROR_STREAM("Couldn't initialise nodelet! Please restart. [" << name_ << "]");
67  }
68  }
69 
70 private:
74  double update_rate_;
76  std::string name_;
78  ecl::Thread update_thread_;
81 
83  void update()
84  {
85  ros::Rate spin_rate(update_rate_);
86  while (ros::ok() && !shutdown_requested_)
87  {
88  controller_->spin();
89  spin_rate.sleep();
90  }
91  }
92 };
93 
94 } // namespace kobuki
95 
boost::shared_ptr< RandomWalkerController > controller_
Pointer to the random walker controller.
Definition: nodelet.cpp:72
virtual void onInit()
Initialise the nodelet.
Definition: nodelet.cpp:43
#define NODELET_INFO_STREAM(...)
const std::string & getUnresolvedNamespace() const
bool shutdown_requested_
Flag for stopping the update thread.
Definition: nodelet.cpp:80
PLUGINLIB_EXPORT_CLASS(kobuki::RandomWalkerControllerNodelet, nodelet::Nodelet)
double update_rate_
Spin rate for the update thread.
Definition: nodelet.cpp:74
void update()
Method for update thread.
Definition: nodelet.cpp:83
ros::NodeHandle & getPrivateNodeHandle() const
std::string name_
Node(let) name.
Definition: nodelet.cpp:76
#define NODELET_ERROR_STREAM(...)
bool param(const std::string &param_name, T &param_val, const T &default_val) const
ROSCPP_DECL bool ok()
ecl::Thread update_thread_
Update thread for publishing velocity and LED commands.
Definition: nodelet.cpp:78
Nodelet-wrapper of the RandomWalkerController class.
Definition: nodelet.cpp:26
#define NODELET_DEBUG_STREAM(...)
bool sleep()


kobuki_random_walker
Author(s): Marcus Liebhardt
autogenerated on Mon Jun 10 2019 13:45:06