delay_pointcloud_nodelet.cpp
Go to the documentation of this file.
00001 // -*- mode: C++ -*-
00002 /*********************************************************************
00003  * Software License Agreement (BSD License)
00004  *
00005  *  Copyright (c) 2014, JSK Lab
00006  *  All rights reserved.
00007  *
00008  *  Redistribution and use in source and binary forms, with or without
00009  *  modification, are permitted provided that the following conditions
00010  *  are met:
00011  *
00012  *   * Redistributions of source code must retain the above copyright
00013  *     notice, this list of conditions and the following disclaimer.
00014  *   * Redistributions in binary form must reproduce the above
00015  *     copyright notice, this list of conditions and the following
00016  *     disclaimer in the documentation and/o2r other materials provided
00017  *     with the distribution.
00018  *   * Neither the name of the JSK Lab nor the names of its
00019  *     contributors may be used to endorse or promote products derived
00020  *     from this software without specific prior written permission.
00021  *
00022  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033  *  POSSIBILITY OF SUCH DAMAGE.
00034  *********************************************************************/
00035 
00036 #include "jsk_pcl_ros_utils/delay_pointcloud.h"
00037 #include <pluginlib/class_list_macros.h>
00038 
00039 namespace jsk_pcl_ros_utils
00040 {
00041   void DelayPointCloud::onInit()
00042   {
00043     ConnectionBasedNodelet::onInit();
00044 
00045     srv_ = boost::make_shared <dynamic_reconfigure::Server<Config> > (*pnh_);
00046     dynamic_reconfigure::Server<Config>::CallbackType f =
00047         boost::bind (&DelayPointCloud::configCallback, this, _1, _2);
00048     srv_->setCallback (f);
00049 
00050     pnh_->param("delay_time", delay_time_, 0.1);
00051     pnh_->param("queue_size", queue_size_, 1000);
00052     pub_ = advertise<sensor_msgs::PointCloud2>(*pnh_, "output", queue_size_);
00053   }
00054 
00055   void DelayPointCloud::configCallback(Config &config, uint32_t level)
00056   {
00057     boost::mutex::scoped_lock lock(mutex_);
00058 
00059     delay_time_ = config.delay_time;
00060     DelayPointCloud::subscribe();
00061   }
00062 
00063   void DelayPointCloud::delay(const sensor_msgs::PointCloud2::ConstPtr& msg)
00064   {
00065     sensor_msgs::PointCloud2 out_cloud_msg = *msg;
00066     out_cloud_msg.header.stamp = ros::Time::now();
00067     pub_.publish(out_cloud_msg);
00068   }
00069 
00070   void DelayPointCloud::subscribe()
00071   {
00072     sub_.subscribe(*pnh_, "input", 1);
00073     time_sequencer_ = boost::make_shared<message_filters::TimeSequencer<sensor_msgs::PointCloud2> >(ros::Duration(delay_time_), ros::Duration(0.01), queue_size_);
00074     time_sequencer_->connectInput(sub_);
00075     time_sequencer_->registerCallback(boost::bind(&DelayPointCloud::delay, this, _1));
00076   }
00077   void DelayPointCloud::unsubscribe()
00078   {
00079     sub_.unsubscribe();
00080   }
00081 }
00082 
00083 PLUGINLIB_EXPORT_CLASS (jsk_pcl_ros_utils::DelayPointCloud, nodelet::Nodelet);


jsk_pcl_ros_utils
Author(s): Yohei Kakiuchi
autogenerated on Sun Oct 8 2017 02:43:04