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/or 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);
65  onInitPostProcess();
66  }
67 
69  // message_filters::Synchronizer needs to be called reset
70  // before message_filters::Subscriber is freed.
71  // Calling reset fixes the following error on shutdown of the nodelet:
72  // terminate called after throwing an instance of
73  // 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::lock_error> >'
74  // what(): boost: mutex lock failed in pthread_mutex_lock: Invalid argument
75  // Also see https://github.com/ros/ros_comm/issues/720 .
76  sync_.reset();
77  }
78 
80  const geometry_msgs::Pose& new_pose)
81  {
82  Eigen::Affine3d new_affine;
83  tf::poseMsgToEigen(new_pose, new_affine);
84  for (size_t i = 0; i < poses_.size(); i++) {
85  // convert pose into eigen
86  Eigen::Affine3d affine;
87  tf::poseMsgToEigen(poses_[i], affine);
88  // compute difference
89  Eigen::Affine3d diff = affine.inverse() * new_affine;
90  double positional_difference = diff.translation().norm();
91  if (positional_difference < positional_bin_size_) {
92  Eigen::AngleAxisd rotational_difference(diff.rotation());
93  if (rotational_difference.angle() < rotational_bin_size_) {
94  return true;
95  }
96  }
97  }
98  return false;
99  }
100 
102  {
103  sub_pose_.subscribe(*pnh_, "input/pose", 1);
104  sub_mask_.subscribe(*pnh_, "input/mask", 1);
105  sub_mask_indices_.subscribe(*pnh_, "input/mask_indices", 1);
106  sub_left_image_.subscribe(*pnh_, "input/left_image", 1);
107  sub_left_cam_info_.subscribe(*pnh_, "input/left_camera_info", 1);
108  sub_right_cam_info_.subscribe(*pnh_, "input/right_camera_info", 1);
109  sub_disparity_.subscribe(*pnh_, "input/disparity", 1);
110  sync_ = boost::make_shared<message_filters::Synchronizer<SyncPolicy> >(100);
111  sync_->connectInput(sub_pose_,
112  sub_mask_,
118  sync_->registerCallback(boost::bind(&CaptureStereoSynchronizer::republish,
119  this,
120  _1,
121  _2,
122  _3,
123  _4,
124  _5,
125  _6,
126  _7));
127  }
128 
130  {
138  }
139 
141  const geometry_msgs::PoseStamped::ConstPtr& pose,
142  const sensor_msgs::Image::ConstPtr& mask,
143  const PCLIndicesMsg::ConstPtr& mask_indices,
144  const sensor_msgs::Image::ConstPtr& left_image,
145  const sensor_msgs::CameraInfo::ConstPtr& left_cam_info,
146  const sensor_msgs::CameraInfo::ConstPtr& right_cam_info,
147  const stereo_msgs::DisparityImage::ConstPtr& disparity)
148  {
149  if (checkNearPose(pose->pose)) {
150  ROS_DEBUG("too near");
151  }
152  else {
153  ROS_INFO("%d sample", counter_++);
154  poses_.push_back(pose->pose);
156  pub_mask_.publish(mask);
157  pub_mask_indices_.publish(mask_indices);
158  pub_left_image_.publish(left_image);
159  pub_left_cam_info_.publish(left_cam_info);
160  pub_right_cam_info_.publish(right_cam_info);
161  pub_disparity_.publish(disparity);
162  }
163  std_msgs::Int32 count;
164  count.data = counter_;
166  }
167 }
168 
jsk_pcl_ros::CaptureStereoSynchronizer::pub_disparity_
ros::Publisher pub_disparity_
Definition: capture_stereo_synchronizer.h:169
jsk_pcl_ros::CaptureStereoSynchronizer::pub_right_cam_info_
ros::Publisher pub_right_cam_info_
Definition: capture_stereo_synchronizer.h:168
tf::poseMsgToEigen
void poseMsgToEigen(const geometry_msgs::Pose &m, Eigen::Affine3d &e)
jsk_pcl_ros::CaptureStereoSynchronizer::pub_pose_
ros::Publisher pub_pose_
Definition: capture_stereo_synchronizer.h:163
_2
boost::arg< 2 > _2
jsk_pcl_ros::CaptureStereoSynchronizer::sub_mask_
message_filters::Subscriber< sensor_msgs::Image > sub_mask_
Definition: capture_stereo_synchronizer.h:171
_3
boost::arg< 3 > _3
i
int i
jsk_pcl_ros::CaptureStereoSynchronizer::sub_mask_indices_
message_filters::Subscriber< PCLIndicesMsg > sub_mask_indices_
Definition: capture_stereo_synchronizer.h:172
jsk_pcl_ros::CaptureStereoSynchronizer::pub_left_cam_info_
ros::Publisher pub_left_cam_info_
Definition: capture_stereo_synchronizer.h:167
jsk_pcl_ros::CaptureStereoSynchronizer::counter_
int counter_
Definition: capture_stereo_synchronizer.h:161
ROS_DEBUG
#define ROS_DEBUG(...)
jsk_pcl_ros::CaptureStereoSynchronizer::subscribe
virtual void subscribe()
Definition: capture_stereo_synchronizer_nodelet.cpp:101
_7
boost::arg< 7 > _7
jsk_pcl_ros::CaptureStereoSynchronizer::pub_count_
ros::Publisher pub_count_
Definition: capture_stereo_synchronizer.h:162
ros::Publisher::publish
void publish(const boost::shared_ptr< M > &message) const
message_filters::Subscriber::unsubscribe
void unsubscribe()
jsk_pcl_ros::CaptureStereoSynchronizer::positional_bin_size_
double positional_bin_size_
Definition: capture_stereo_synchronizer.h:183
pose
pose
class_list_macros.h
jsk_pcl_ros::CaptureStereoSynchronizer::sub_disparity_
message_filters::Subscriber< stereo_msgs::DisparityImage > sub_disparity_
Definition: capture_stereo_synchronizer.h:176
jsk_pcl_ros::CaptureStereoSynchronizer::sub_right_cam_info_
message_filters::Subscriber< sensor_msgs::CameraInfo > sub_right_cam_info_
Definition: capture_stereo_synchronizer.h:175
jsk_pcl_ros
Definition: add_color_from_image.h:51
_5
boost::arg< 5 > _5
jsk_pcl_ros::CaptureStereoSynchronizer::sync_
boost::shared_ptr< message_filters::Synchronizer< SyncPolicy > > sync_
Definition: capture_stereo_synchronizer.h:177
eigen_msg.h
jsk_pcl_ros::CaptureStereoSynchronizer::checkNearPose
virtual bool checkNearPose(const geometry_msgs::Pose &new_pose)
Definition: capture_stereo_synchronizer_nodelet.cpp:79
_1
boost::arg< 1 > _1
jsk_pcl_ros::count
double count(const OneDataStat &d)
wrapper function for count method for boost::function
Definition: one_data_stat.h:144
jsk_pcl_ros::CaptureStereoSynchronizer::unsubscribe
virtual void unsubscribe()
Definition: capture_stereo_synchronizer_nodelet.cpp:129
jsk_pcl_ros::CaptureStereoSynchronizer::pub_mask_
ros::Publisher pub_mask_
Definition: capture_stereo_synchronizer.h:164
jsk_pcl_ros::CaptureStereoSynchronizer::sub_left_cam_info_
message_filters::Subscriber< sensor_msgs::CameraInfo > sub_left_cam_info_
Definition: capture_stereo_synchronizer.h:174
message_filters::Subscriber::subscribe
void subscribe()
jsk_pcl_ros::CaptureStereoSynchronizer::republish
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)
Definition: capture_stereo_synchronizer_nodelet.cpp:140
nodelet::Nodelet
jsk_pcl_ros::CaptureStereoSynchronizer::poses_
std::vector< geometry_msgs::Pose > poses_
Definition: capture_stereo_synchronizer.h:178
jsk_pcl_ros::CaptureStereoSynchronizer::~CaptureStereoSynchronizer
virtual ~CaptureStereoSynchronizer()
Definition: capture_stereo_synchronizer_nodelet.cpp:68
capture_stereo_synchronizer.h
_6
boost::arg< 6 > _6
PLUGINLIB_EXPORT_CLASS
PLUGINLIB_EXPORT_CLASS(jsk_pcl_ros::CaptureStereoSynchronizer, nodelet::Nodelet)
_4
boost::arg< 4 > _4
jsk_pcl_ros::CaptureStereoSynchronizer::rotational_bin_size_
double rotational_bin_size_
Definition: capture_stereo_synchronizer.h:182
jsk_pcl_ros::CaptureStereoSynchronizer
Definition: capture_stereo_synchronizer.h:89
ROS_INFO
#define ROS_INFO(...)
jsk_pcl_ros::CaptureStereoSynchronizer::sub_left_image_
message_filters::Subscriber< sensor_msgs::Image > sub_left_image_
Definition: capture_stereo_synchronizer.h:173
jsk_pcl_ros::CaptureStereoSynchronizer::pub_left_image_
ros::Publisher pub_left_image_
Definition: capture_stereo_synchronizer.h:166
jsk_pcl_ros::CaptureStereoSynchronizer::onInit
virtual void onInit()
Definition: capture_stereo_synchronizer_nodelet.cpp:44
jsk_pcl_ros::CaptureStereoSynchronizer::sub_pose_
message_filters::Subscriber< geometry_msgs::PoseStamped > sub_pose_
Definition: capture_stereo_synchronizer.h:170
jsk_pcl_ros::CaptureStereoSynchronizer::pub_mask_indices_
ros::Publisher pub_mask_indices_
Definition: capture_stereo_synchronizer.h:165


jsk_pcl_ros
Author(s): Yohei Kakiuchi
autogenerated on Tue Jan 7 2025 04:05:44