lslidar_c16_driver_nodelet.cc
Go to the documentation of this file.
1 /*
2  * This file is part of lslidar_c16 driver.
3  *
4  * The driver is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * The driver is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with the driver. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <string>
19 #include <boost/thread.hpp>
20 
21 #include <ros/ros.h>
23 #include <nodelet/nodelet.h>
24 
26 
27 
28 namespace lslidar_c16_driver
29 {
30 
32  running(false) {
33  return;
34 }
35 
37  if (running) {
38  NODELET_INFO("shutting down driver thread");
39  running = false;
40  device_thread->join();
41  NODELET_INFO("driver thread stopped");
42  }
43  return;
44 }
45 
47 {
48  // start the driver
49  lslidar_c16_driver.reset(
51  if (!lslidar_c16_driver->initialize()) {
52  ROS_ERROR("Cannot initialize lslidar driver...");
53  return;
54  }
55 
56  // spawn device poll thread
57  running = true;
59  (new boost::thread(boost::bind(&LslidarC16DriverNodelet::devicePoll, this)));
60 }
61 
64 {
65  while(ros::ok()) {
66  // poll device until end of file
67  running = lslidar_c16_driver->polling();
68  // ROS_INFO_THROTTLE(30, "polling data successfully");
69  if (!running)
70  break;
71  }
72  running = false;
73 }
74 
75 } // namespace lslidar_driver
76 
77 // Register this plugin with pluginlib. Names must match nodelet_lslidar.xml.
78 // parameters are: class type, base class type
virtual void devicePoll(void)
Device poll thread main loop.
volatile bool running
device thread is running
ros::NodeHandle & getPrivateNodeHandle() const
ROSCPP_DECL bool ok()
ros::NodeHandle & getNodeHandle() const
#define NODELET_INFO(...)
boost::shared_ptr< boost::thread > device_thread
#define ROS_ERROR(...)
PLUGINLIB_EXPORT_CLASS(lslidar_c16_driver::LslidarC16DriverNodelet, nodelet::Nodelet)


lslidar_c16_driver
Author(s): Yutong
autogenerated on Thu Aug 22 2019 03:51:43