nodelet.cpp
Go to the documentation of this file.
1 
6 #include <ecl/threads/thread.hpp>
7 #include <nodelet/nodelet.h>
10 
11 
12 namespace yocs_safety_controller
13 {
14 
16 {
17 public:
20  {
21  NODELET_DEBUG_STREAM("Waiting for update thread to finish.");
22  shutdown_requested_ = true;
23  update_thread_.join();
24  }
25  virtual void onInit()
26  {
28  // resolve node(let) name
29  std::string name = nh.getUnresolvedNamespace();
30  int pos = name.find_last_of('/');
31  name = name.substr(pos + 1);
32  NODELET_INFO_STREAM("Initialising nodelet... [" << name << "]");
33  controller_.reset(new SafetyController(nh, name));
34  if (controller_->init())
35  {
36  NODELET_INFO_STREAM("Safety controller initialised. Spinning up update thread ... [" << name << "]");
38  NODELET_INFO_STREAM("Nodelet initialised. [" << name << "]");
39  }
40  else
41  {
42  NODELET_ERROR_STREAM("Couldn't initialise nodelet! Please restart. [" << name << "]");
43  }
44  }
45 private:
46  void update()
47  {
48  ros::Rate spin_rate(10);
49  controller_->enable(); // enable the controller when loading the nodelet
50  while (! shutdown_requested_ && ros::ok())
51  {
52  controller_->spinOnce();
53  spin_rate.sleep();
54  }
55  }
56 
58  ecl::Thread update_thread_;
60 };
61 
62 } // namespace yocs_safety_controller
63 
#define NODELET_INFO_STREAM(...)
const std::string & getUnresolvedNamespace() const
PLUGINLIB_EXPORT_CLASS(yocs_safety_controller::SafetyControllerNodelet, nodelet::Nodelet)
boost::shared_ptr< SafetyController > controller_
Definition: nodelet.cpp:57
ros::NodeHandle & getPrivateNodeHandle() const
#define NODELET_ERROR_STREAM(...)
ROSCPP_DECL bool ok()
#define NODELET_DEBUG_STREAM(...)
bool sleep()


yocs_safety_controller
Author(s): Marcus Liebhardt
autogenerated on Mon Jun 10 2019 15:54:01