driver.cc
Go to the documentation of this file.
1 /*
2  * License: Modified BSD Software License Agreement
3  *
4  * $Id$
5  */
6 
12 #include <string>
13 #include <cmath>
14 
15 #include <ros/ros.h>
16 #include <tf/transform_listener.h>
17 #include <sensor_msgs/PointCloud2.h>
18 
19 #include "driver.h"
20 
21 namespace o3m151_driver
22 {
23 
25  ros::NodeHandle private_nh)
26 {
27  // use private node handle to get parameters
28  private_nh.param("frame_id", frame_id_, std::string("o3m151"));
29  std::string tf_prefix = tf::getPrefixParam(private_nh);
30  ROS_DEBUG_STREAM("tf_prefix: " << tf_prefix);
31  frame_id_ = tf::resolve(tf_prefix, frame_id_);
32 
33  std::string dump_file;
34  private_nh.param("pcap", dump_file, std::string(""));
35 
36  // initialize diagnostics
37  diagnostics_.setHardwareID(std::string("O3M151"));
38  const double diag_freq = 25;
39  diag_max_freq_ = diag_freq;
40  diag_min_freq_ = diag_freq;
41  ROS_INFO("expected frequency: %.3f (Hz)", diag_freq);
42 
43  using namespace diagnostic_updater;
44  diag_topic_.reset(new TopicDiagnostic("o3m151_packets", diagnostics_,
47  0.1, 10),
49 
50  // open O3M151 input device or file
51  if (dump_file != "")
52  input_.reset(new o3m151_driver::InputPCAP(private_nh,
53  diag_freq*19, // Needs 19 packets to obtain a scan (cf wireshark)
54  dump_file));
55  else
56  input_.reset(new o3m151_driver::InputSocket(private_nh));
57 
58  // raw data output topic
59  output_ = node.advertise<sensor_msgs::PointCloud2>("o3m151_points", 10);
60 }
61 
67 {
68  // Allocate a new shared pointer for zero-copy sharing with other nodelets.
69  //sensor_msgs::PointCloud2Ptr pc(new sensor_msgs::PointCloud2);
70  pcl::PointCloud<pcl::PointXYZI>::Ptr pc(new pcl::PointCloud<pcl::PointXYZI>());
71 
72  // Since the o3m151 delivers data at a very high rate, keep
73  // reading and publishing scans as fast as possible.
74  pc->points.clear();
75  while (true)
76  {
77  // keep reading until full packet received
78  int rc = input_->getPacket(*pc);
79  if (rc == 0) break; // got a full packet?
80  if (rc < 0) return false; // end of file reached?
81  }
82 
83  // publish message using time of last packet read
84  ROS_DEBUG("Publishing a full O3M151 scan with %d points", pc->points.size());
85  ros::Time now = ros::Time::now();
87  pc->header.stamp = now.toNSec() / 1e3;
88  pc->header.frame_id = frame_id_;
89  pc->height = 1;
90  pc->width = pc->points.size();
91  output_.publish(pc);
92 
93  // notify diagnostics that a message has been published, updating
94  // its status
95  diag_topic_->tick(now);
97 
98  return true;
99 }
100 
101 } // namespace o3m151_driver
boost::shared_ptr< diagnostic_updater::TopicDiagnostic > diag_topic_
Definition: driver.h:50
O3M151Driver(ros::NodeHandle node, ros::NodeHandle private_nh)
Definition: driver.cc:24
void publish(const boost::shared_ptr< M > &message) const
std::string getPrefixParam(ros::NodeHandle &nh)
std::string frame_id_
tf frame ID
Definition: driver.h:41
void setHardwareID(const std::string &hwid)
std::string resolve(const std::string &prefix, const std::string &frame_name)
#define ROS_INFO(...)
boost::shared_ptr< Input > input_
Definition: driver.h:43
bool param(const std::string &param_name, T &param_val, const T &default_val) const
ros::Publisher output_
Definition: driver.h:44
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
#define ROS_DEBUG_STREAM(args)
diagnostic_updater::Updater diagnostics_
Definition: driver.h:47
static Time now()
Live O3M151 input from socket.
Definition: input.h:85
O3M151 input from PCAP dump file.
Definition: input.h:104
#define ROS_DEBUG(...)


o3m151_driver
Author(s): Vincent Rousseau
autogenerated on Mon Jun 10 2019 14:07:55