transform.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009, 2010 Austin Robot Technology, Jack O'Quin
3  * Copyright (C) 2011 Jesse Vera
4  * Copyright (C) 2012 Austin Robot Technology, Jack O'Quin
5  * License: Modified BSD Software License Agreement
6  *
7  * $Id$
8  */
9 
22 
25 
26 namespace velodyne_pointcloud
27 {
29  Transform::Transform(ros::NodeHandle node, ros::NodeHandle private_nh, std::string const & node_name):
30  tf_prefix_(tf::getPrefixParam(private_nh)),
31  data_(new velodyne_rawdata::RawData),
32  first_rcfg_call(true),
33  diagnostics_(node, private_nh, node_name)
34  {
35  boost::optional<velodyne_pointcloud::Calibration> calibration = data_->setup(private_nh);
36  if(calibration)
37  {
38  ROS_DEBUG_STREAM("Calibration file loaded.");
39  config_.num_lasers = static_cast<uint16_t>(calibration.get().num_lasers);
40  }
41  else
42  {
43  ROS_ERROR_STREAM("Could not load calibration file!");
44  }
45 
46  config_.target_frame = config_.fixed_frame = "velodyne";
47  tf_ptr_ = boost::make_shared<tf::TransformListener>();
48 
50  {
53  config_.num_lasers, data_->scansPerPacket(), tf_ptr_));
54  }
55  else
56  {
60  data_->scansPerPacket(), tf_ptr_));
61  }
62 
63  // advertise output point cloud (before subscribing to input data)
64  output_ =
65  node.advertise<sensor_msgs::PointCloud2>("velodyne_points", 10);
66 
67  srv_ = boost::make_shared<dynamic_reconfigure::Server<TransformNodeCfg>> (private_nh);
68  dynamic_reconfigure::Server<TransformNodeCfg>::CallbackType f;
69  f = boost::bind (&Transform::reconfigure_callback, this, _1, _2);
70  srv_->setCallback (f);
71 
72  // subscribe to VelodyneScan packets using transform filter
73  velodyne_scan_.subscribe(node, "velodyne_packets", 10);
76  tf_filter_ptr_->registerCallback(boost::bind(&Transform::processScan, this, _1));
77  private_nh.param<std::string>("fixed_frame", config_.fixed_frame, "odom");
78 
79  // Diagnostics
80  diagnostics_.setHardwareID("Velodyne Transform");
81  // Arbitrary frequencies since we don't know which RPM is used, and are only
82  // concerned about monitoring the frequency.
83  diag_min_freq_ = 2.0;
84  diag_max_freq_ = 20.0;
85  using namespace diagnostic_updater;
86  diag_topic_.reset(new TopicDiagnostic("velodyne_points", diagnostics_,
89  0.1, 10),
91 
92  }
93 
95  velodyne_pointcloud::TransformNodeConfig &config, uint32_t level)
96  {
97  ROS_INFO_STREAM("Reconfigure request.");
98  data_->setParameters(config.min_range, config.max_range,
99  config.view_direction, config.view_width);
100  config_.target_frame = tf::resolve(tf_prefix_, config.frame_id);
101  ROS_INFO_STREAM("Target frame ID now: " << config_.target_frame);
102  config_.min_range = config.min_range;
103  config_.max_range = config.max_range;
104 
105  boost::lock_guard<boost::mutex> guard(reconfigure_mtx_);
106 
107  if(first_rcfg_call || config.organize_cloud != config_.organize_cloud){
108  first_rcfg_call = false;
109  config_.organize_cloud = config.organize_cloud;
111  {
112  ROS_INFO_STREAM("Using the organized cloud format...");
116  config_.num_lasers, data_->scansPerPacket()));
117  }
118  else
119  {
123  data_->scansPerPacket()));
124  }
125  }
127  }
128 
134  void
135  Transform::processScan(const velodyne_msgs::VelodyneScan::ConstPtr &scanMsg)
136  {
137  if (output_.getNumSubscribers() == 0) // no one listening?
138  return; // avoid much work
139 
140  boost::lock_guard<boost::mutex> guard(reconfigure_mtx_);
141 
142  // allocate a point cloud with same time and frame ID as raw data
143  container_ptr->setup(scanMsg);
144 
145  // process each packet provided by the driver
146  for (size_t i = 0; i < scanMsg->packets.size(); ++i)
147  {
148  container_ptr->computeTransformation(scanMsg->packets[i].stamp);
149  data_->unpack(scanMsg->packets[i], *container_ptr, scanMsg->header.stamp);
150  }
151  // publish the accumulated cloud message
152  output_.publish(container_ptr->finishCloud());
153 
154  diag_topic_->tick(scanMsg->header.stamp);
156  }
157 
158 } // namespace velodyne_pointcloud
double min_range
minimum range to publish
Definition: transform.h:93
boost::shared_ptr< tf::TransformListener > tf_ptr_
Definition: transform.h:84
Transform(ros::NodeHandle node, ros::NodeHandle private_nh, std::string const &node_name=ros::this_node::getName())
Constructor.
Definition: transform.cc:29
boost::shared_ptr< dynamic_reconfigure::Server< velodyne_pointcloud::TransformNodeConfig > > srv_
Definition: transform.h:76
boost::shared_ptr< tf::MessageFilter< velodyne_msgs::VelodyneScan > > tf_filter_ptr_
Definition: transform.h:83
message_filters::Subscriber< velodyne_msgs::VelodyneScan > velodyne_scan_
Definition: transform.h:81
void publish(const boost::shared_ptr< M > &message) const
std::string getPrefixParam(ros::NodeHandle &nh)
void setHardwareID(const std::string &hwid)
std::string fixed_frame
fixed frame
Definition: transform.h:90
diagnostic_updater::Updater diagnostics_
Definition: transform.h:104
bool organize_cloud
enable/disable organized cloud structure
Definition: transform.h:91
std::string resolve(const std::string &prefix, const std::string &frame_name)
boost::shared_ptr< velodyne_rawdata::RawData > data_
Definition: transform.h:80
bool param(const std::string &param_name, T &param_val, const T &default_val) const
std::string target_frame
target frame
Definition: transform.h:89
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void reconfigure_callback(velodyne_pointcloud::TransformNodeConfig &config, uint32_t level)
Definition: transform.cc:94
#define ROS_DEBUG_STREAM(args)
const std::string tf_prefix_
Definition: transform.h:79
uint32_t getNumSubscribers() const
#define ROS_INFO_STREAM(args)
void subscribe(ros::NodeHandle &nh, const std::string &topic, uint32_t queue_size, const ros::TransportHints &transport_hints=ros::TransportHints(), ros::CallbackQueueInterface *callback_queue=0)
boost::shared_ptr< diagnostic_updater::TopicDiagnostic > diag_topic_
Definition: transform.h:107
double max_range
maximum range to publish
Definition: transform.h:92
void processScan(const velodyne_msgs::VelodyneScan::ConstPtr &scanMsg)
Callback for raw scan messages.
Definition: transform.cc:135
dictionary calibration
#define ROS_ERROR_STREAM(args)
uint16_t num_lasers
number of lasers
Definition: transform.h:94
boost::shared_ptr< velodyne_rawdata::DataContainerBase > container_ptr
Definition: transform.h:101


velodyne_pointcloud
Author(s): Jack O'Quin, Piyush Khandelwal, Jesse Vera, Sebastian Pütz
autogenerated on Sun Sep 6 2020 03:25:30