pointcloud_moveit_filter.cpp
Go to the documentation of this file.
1 // -*- mode: c++ -*-
2 /*********************************************************************
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2014, JSK Lab
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/o2r other materials provided
17  * with the distribution.
18  * * Neither the name of the JSK Lab nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *********************************************************************/
37 
38 namespace jsk_pcl_ros
39 {
41  OccupancyMapUpdater("PointCloudMoveitFilter"),
42  private_nh_("~"),
43  scale_(1.0),
44  padding_(0.0),
45  max_range_(std::numeric_limits<double>::infinity()),
46  point_subsample_(1),
47  point_cloud_subscriber_(NULL),
48  point_cloud_filter_(NULL),
49  use_color_(false),
50  keep_organized_(false)
51  {
52  }
53 
55  {
56  }
57 
59  {
60  try
61  {
62  if (!params.hasMember("point_cloud_topic"))
63  return false;
64  point_cloud_topic_ = static_cast<const std::string&>(params["point_cloud_topic"]);
65 
66  readXmlParam(params, "max_range", &max_range_);
67  readXmlParam(params, "padding_offset", &padding_);
68  readXmlParam(params, "padding_scale", &scale_);
69  readXmlParam(params, "point_subsample", &point_subsample_);
70  if (!params.hasMember("filtered_cloud_topic")) {
71  ROS_ERROR("filtered_cloud_topic is required");
72  return false;
73  }
74  else {
75  filtered_cloud_topic_ = static_cast<const std::string&>(params["filtered_cloud_topic"]);
76  }
77  if (params.hasMember("filtered_cloud_use_color")) {
78  use_color_ = (bool)params["filtered_cloud_use_color"];
79  }
80  if (params.hasMember("filtered_cloud_keep_organized")) {
81  keep_organized_ = (bool)params["filtered_cloud_keep_organized"];
82  }
83  }
85  {
86  ROS_ERROR("XmlRpc Exception: %s", ex.getMessage().c_str());
87  return false;
88  }
89 
90  return true;
91  }
92 
93 
94 
96  {
99  shape_mask_->setTransformCallback(
100  boost::bind(&PointCloudMoveitFilter::getShapeTransform, this, _1, _2));
101  filtered_cloud_publisher_ = private_nh_.advertise<sensor_msgs::PointCloud2>(
102  filtered_cloud_topic_, 10, false);
103  return true;
104  }
105 
106 #if (ROS_VERSION_MINIMUM(1,14,0) || MOVEIT_VERSION_MAJOR >= 1) // melodic or MoveIt 1.0
107  bool PointCloudMoveitFilter::getShapeTransform(ShapeHandle h, Eigen::Isometry3d &transform) const
108 #else
109  bool PointCloudMoveitFilter::getShapeTransform(ShapeHandle h, Eigen::Affine3d &transform) const
110 #endif
111  {
112  ShapeTransformCache::const_iterator it = transform_cache_.find(h);
113  if (it == transform_cache_.end())
114  {
115  ROS_ERROR("Internal error. Shape filter handle %u not found", h);
116  return false;
117  }
118  transform = it->second;
119  return true;
120  }
121 
123  {
124  ShapeHandle h = 0;
125  if (shape_mask_)
126  h = shape_mask_->addShape(shape, scale_, padding_);
127  else
128  ROS_ERROR("Shape filter not yet initialized!");
129  return h;
130  }
131 
132 
134  {
135  if (shape_mask_)
136  shape_mask_->removeShape(handle);
137  }
138 
139 
141  {
143  return;
144  /* subscribe to point cloud topic using tf filter*/
148  if (tf_ && !monitor_->getMapFrame().empty())
149  {
151 #if (ROS_VERSION_MINIMUM(1,14,0) || MOVEIT_VERSION_MAJOR >= 1) // melodic or MoveIt 1.0
153  *point_cloud_subscriber_, *tf_, monitor_->getMapFrame(), 5, nullptr);
154 #else
157 #endif
158  if (use_color_) {
160  boost::bind(
161  &PointCloudMoveitFilter::cloudMsgCallback<pcl::PointXYZRGB>,
162  this, _1));
163  }
164  else {
166  boost::bind(
167  &PointCloudMoveitFilter::cloudMsgCallback<pcl::PointXYZ>,
168  this, _1));
169  }
170  ROS_INFO("Listening to '%s' using message filter with target frame '%s'",
171  point_cloud_topic_.c_str(),
173  }
174  else
175  {
176  if (use_color_) {
178  boost::bind(
179  &PointCloudMoveitFilter::cloudMsgCallback<pcl::PointXYZRGB>,
180  this, _1));
181  }
182  else {
184  boost::bind(&PointCloudMoveitFilter::cloudMsgCallback<pcl::PointXYZ>,
185  this, _1));
186  }
187  ROS_INFO("Listening to '%s'", point_cloud_topic_.c_str());
188  }
189  }
190 
192  {
193  delete point_cloud_filter_;
195  }
196 
198  {
199  stopHelper();
202  }
203 
204 }
205 
const std::string & getMessage() const
boost::scoped_ptr< point_containment_filter::ShapeMask > shape_mask_
virtual ShapeHandle excludeShape(const shapes::ShapeConstPtr &shape)
virtual void forgetShape(ShapeHandle handle)
occupancy_map_monitor::ShapeHandle ShapeHandle
virtual bool setParams(XmlRpc::XmlRpcValue &params)
tf::MessageFilter< sensor_msgs::PointCloud2 > * point_cloud_filter_
const std::string & getMapFrame() const
const boost::shared_ptr< tf::Transformer > & getTFClient() const
#define ROS_INFO(...)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
bool hasMember(const std::string &name) const
boost::shared_ptr< tf::Transformer > tf_
static void readXmlParam(XmlRpc::XmlRpcValue &params, const std::string &param_name, double *value)
#define NULL
message_filters::Subscriber< sensor_msgs::PointCloud2 > * point_cloud_subscriber_
virtual bool getShapeTransform(ShapeHandle h, Eigen::Affine3d &transform) const
std::string getTargetFramesString()
#define ROS_ERROR(...)
CLASS_LOADER_REGISTER_CLASS(Dog, Base)
Connection registerCallback(const C &callback)
std::shared_ptr< const Shape > ShapeConstPtr


jsk_pcl_ros
Author(s): Yohei Kakiuchi
autogenerated on Mon May 3 2021 03:03:47