$search
00001 /* 00002 * Copyright (c) 2011, Robert Bosch LLC 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * * Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Neither the name of Robert Bosch LLC nor the names of its 00014 * contributors may be used to endorse or promote products derived from 00015 * this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00021 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00022 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00023 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00024 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00025 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00026 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00027 * POSSIBILITY OF SUCH DAMAGE. 00028 */ 00029 00034 #include "ros/ros.h" 00035 #include "pr2_interactive_segmentation/computeICP.h" 00036 #include <eigen_conversions/eigen_msg.h> 00037 #include <pcl/io/pcd_io.h> 00038 #include <pcl/point_types.h> 00039 #include <pcl/registration/icp_nl.h> 00040 #include <pcl/console/time.h> 00041 typedef pcl::PointXYZ PointT; 00042 00043 bool computeICP(pr2_interactive_segmentation::computeICP::Request &req, 00044 pr2_interactive_segmentation::computeICP::Response &res ) 00045 { 00046 pcl::PointCloud<PointT> input, target; 00047 pcl::IterativeClosestPointNonLinear<PointT, PointT> icp; 00048 icp.setMaximumIterations(2000); 00049 icp.setTransformationEpsilon (1e-8); 00050 std::cerr << "[compute_icp_server:] icp.getTransformationEpsilon () " << icp.getTransformationEpsilon () << std::endl; 00051 std::cerr << "[compute_icp_server:] icp.getMaximumIterations() " << icp.getMaximumIterations () << std::endl; 00052 std::cerr << "[compute_icp_server:] icp.getMaxCorrespondenceDistance () " << icp.getMaxCorrespondenceDistance () << std::endl; 00053 00054 pcl::fromROSMsg (req.input, input); 00055 pcl::fromROSMsg (req.target, target); 00056 icp.setInputCloud(input.makeShared()); 00057 icp.setInputTarget(target.makeShared()); 00058 pcl::PointCloud<PointT> Final; 00059 pcl::console::TicToc tictoc; 00060 tictoc.tic(); 00061 icp.align(Final); 00062 std::cerr << "[compute_icp_server:] has converged: " << icp.hasConverged() << " in " << tictoc.toc() << " seconds." << 00063 std:: endl << "score: " << icp.getFitnessScore() << std::endl; 00064 std::cerr << icp.getFinalTransformation() << std::endl; 00065 geometry_msgs::Pose transform; 00066 Eigen::Affine3d e2; 00067 e2.matrix() = icp.getFinalTransformation().cast<double>(); 00068 tf::poseEigenToMsg (e2, transform); 00069 res.transform = transform; 00070 return true; 00071 } 00072 00073 int main(int argc, char **argv) 00074 { 00075 ros::init(argc, argv, "compute_icp_server"); 00076 ros::NodeHandle n; 00077 ros::ServiceServer service = n.advertiseService("compute_icp_server", computeICP); 00078 ros::spin(); 00079 return 0; 00080 }