capture_stereo_synchronizer_nodelet.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  *********************************************************************/
35 
36 #define BOOST_PARAMETER_MAX_ARITY 7
38 #include <pcl/common/angles.h>
40 #include <std_msgs/Int32.h>
41 
42 namespace jsk_pcl_ros
43 {
45  {
46  DiagnosticNodelet::onInit();
47  counter_ = 0;
48  pnh_->param("rotational_bin_size", rotational_bin_size_, pcl::deg2rad(10.0));
49  pnh_->param("positional_bin_size", positional_bin_size_, 0.1);
50  pub_pose_ = advertise<geometry_msgs::PoseStamped>(*pnh_, "output/pose", 1);
51  pub_mask_ = advertise<sensor_msgs::Image>(*pnh_, "output/mask", 1);
52  poses_.resize(0);
53  pub_mask_indices_ = advertise<PCLIndicesMsg>(
54  *pnh_, "output/mask_indices", 1);
55  pub_left_image_ = advertise<sensor_msgs::Image>(
56  *pnh_, "output/left_image", 1);
57  pub_left_cam_info_ = advertise<sensor_msgs::CameraInfo>(
58  *pnh_, "output/left_camera_info", 1);
59  pub_right_cam_info_ = advertise<sensor_msgs::CameraInfo>(
60  *pnh_, "output/right_camera_info", 1);
61  pub_disparity_ = advertise<stereo_msgs::DisparityImage>(
62  *pnh_, "output/disparity", 1);
63  pub_count_ = advertise<std_msgs::Int32>(
64  *pnh_, "output/count", 1);
66  }
67 
69  const geometry_msgs::Pose& new_pose)
70  {
71  Eigen::Affine3d new_affine;
72  tf::poseMsgToEigen(new_pose, new_affine);
73  for (size_t i = 0; i < poses_.size(); i++) {
74  // convert pose into eigen
75  Eigen::Affine3d affine;
76  tf::poseMsgToEigen(poses_[i], affine);
77  // compute difference
78  Eigen::Affine3d diff = affine.inverse() * new_affine;
79  double positional_difference = diff.translation().norm();
80  if (positional_difference < positional_bin_size_) {
81  Eigen::AngleAxisd rotational_difference(diff.rotation());
82  if (rotational_difference.angle() < rotational_bin_size_) {
83  return true;
84  }
85  }
86  }
87  return false;
88  }
89 
91  {
92  sub_pose_.subscribe(*pnh_, "input/pose", 1);
93  sub_mask_.subscribe(*pnh_, "input/mask", 1);
94  sub_mask_indices_.subscribe(*pnh_, "input/mask_indices", 1);
95  sub_left_image_.subscribe(*pnh_, "input/left_image", 1);
96  sub_left_cam_info_.subscribe(*pnh_, "input/left_camera_info", 1);
97  sub_right_cam_info_.subscribe(*pnh_, "input/right_camera_info", 1);
98  sub_disparity_.subscribe(*pnh_, "input/disparity", 1);
99  sync_ = boost::make_shared<message_filters::Synchronizer<SyncPolicy> >(100);
100  sync_->connectInput(sub_pose_,
101  sub_mask_,
107  sync_->registerCallback(boost::bind(&CaptureStereoSynchronizer::republish,
108  this,
109  _1,
110  _2,
111  _3,
112  _4,
113  _5,
114  _6,
115  _7));
116  }
117 
119  {
127  }
128 
130  const geometry_msgs::PoseStamped::ConstPtr& pose,
131  const sensor_msgs::Image::ConstPtr& mask,
132  const PCLIndicesMsg::ConstPtr& mask_indices,
133  const sensor_msgs::Image::ConstPtr& left_image,
134  const sensor_msgs::CameraInfo::ConstPtr& left_cam_info,
135  const sensor_msgs::CameraInfo::ConstPtr& right_cam_info,
136  const stereo_msgs::DisparityImage::ConstPtr& disparity)
137  {
138  if (checkNearPose(pose->pose)) {
139  ROS_DEBUG("too near");
140  }
141  else {
142  ROS_INFO("%d sample", counter_++);
143  poses_.push_back(pose->pose);
144  pub_pose_.publish(pose);
145  pub_mask_.publish(mask);
146  pub_mask_indices_.publish(mask_indices);
147  pub_left_image_.publish(left_image);
148  pub_left_cam_info_.publish(left_cam_info);
149  pub_right_cam_info_.publish(right_cam_info);
150  pub_disparity_.publish(disparity);
151  }
152  std_msgs::Int32 count;
153  count.data = counter_;
154  pub_count_.publish(count);
155  }
156 }
157 
void publish(const boost::shared_ptr< M > &message) const
std::vector< geometry_msgs::Pose > poses_
message_filters::Subscriber< sensor_msgs::CameraInfo > sub_right_cam_info_
void poseMsgToEigen(const geometry_msgs::Pose &m, Eigen::Affine3d &e)
IMETHOD Vector diff(const Vector &p_w_a, const Vector &p_w_b, double dt=1)
boost::shared_ptr< message_filters::Synchronizer< SyncPolicy > > sync_
message_filters::Subscriber< PCLIndicesMsg > sub_mask_indices_
#define ROS_INFO(...)
virtual bool checkNearPose(const geometry_msgs::Pose &new_pose)
boost::shared_ptr< ros::NodeHandle > pnh_
message_filters::Subscriber< sensor_msgs::Image > sub_mask_
message_filters::Subscriber< geometry_msgs::PoseStamped > sub_pose_
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)
message_filters::Subscriber< sensor_msgs::Image > sub_left_image_
message_filters::Subscriber< sensor_msgs::CameraInfo > sub_left_cam_info_
double count(const OneDataStat &d)
wrapper function for count method for boost::function
PLUGINLIB_EXPORT_CLASS(jsk_pcl_ros::CaptureStereoSynchronizer, nodelet::Nodelet)
virtual void republish(const geometry_msgs::PoseStamped::ConstPtr &pose, const sensor_msgs::Image::ConstPtr &mask, const PCLIndicesMsg::ConstPtr &mask_indices, const sensor_msgs::Image::ConstPtr &left_image, const sensor_msgs::CameraInfo::ConstPtr &left_cam_info, const sensor_msgs::CameraInfo::ConstPtr &right_cam_info, const stereo_msgs::DisparityImage::ConstPtr &disparity)
message_filters::Subscriber< stereo_msgs::DisparityImage > sub_disparity_
#define ROS_DEBUG(...)


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