Friday, December 20, 2013

How to add GICP source code into CMakeLists.txt and use it in ROS

The source code for GICP can be found at

http://www.robots.ox.ac.uk/~avsegal/generalized_icp.html


Part of CMakeLists.txt

The gicp folder downloaded from the website is at /home/sai/workspace/

Add these lines in CMakeLists.txt

include_directories(/home/sai/workspace/gicp/ann_1.1.1/include/ANN/)
include_directories(/home/sai/workspace/gicp/)
link_directories(/home/sai/workspace/gicp/)

include_directories(/home/sai/workspace/gicp/ann_1.1.1/lib/)
link_directories(/home/sai/workspace/gicp/ann_1.1.1/lib/)


rosbuild_add_executable(gicp_testing src/gicp_testing.cpp)
target_link_libraries(gicp_testing ${PCL_LIBRARIES} libgicp.a libANN.a -lgsl -lgslcblas)


Add this line in your test file which in my case is gicp_testing.cpp

The original source code is at

http://www.pcl-users.org/file/n4019799/Main.cpp


gicp_testing.cpp file is as follows.


#include "pcl17/io/pcd_io.h"
#include "pcl17/filters/voxel_grid.h"
#include "pcl17/registration/gicp.h"
#include "pcl17/visualization/cloud_viewer.h"
#include "/home/sai/workspace/gicp/gicp.h"


pcl17::PointCloud::Ptr modelCloud(new pcl17::PointCloud);
pcl17::PointCloud::Ptr modelCloudDownsampled(new pcl17::PointCloud);
pcl17::PointCloud::Ptr dataCloud(new pcl17::PointCloud);
pcl17::PointCloud::Ptr dataCloudDownsampled(new pcl17::PointCloud);

pcl17::PointCloud::Ptr transformed(new pcl17::PointCloud);

void viewerOneOff(pcl17::visualization::PCLVisualizer& viewer)
{
    viewer.addPointCloud(modelCloudDownsampled, "model");
    //viewer.setPointCloudRenderingProperties(pcl17::visualization::PCL_VISUALIZER_COLOR, 255, 0, 0, "model");
    viewer.addPointCloud(transformed, "transformed");
    //viewer.setPointCloudRenderingProperties(pcl17::visualization::PCL_VISUALIZER_COLOR, 0, 0, 255, "transformed");
}


int main(int argv, char **args)
{
    // load files and convert to point type pcl17::PointXYZ
    sensor_msgs::PointCloud2 cloudBlob;

    pcl17::io::loadPCDFile("temp1.pcd", cloudBlob);
    pcl17::fromROSMsg(cloudBlob, *modelCloud);
    pcl17::io::loadPCDFile("temp2.pcd", cloudBlob);
    pcl17::fromROSMsg(cloudBlob, *dataCloud);

    // make dense
    std::vector indices;
    pcl17::removeNaNFromPointCloud(*modelCloud, *modelCloud, indices);
    pcl17::removeNaNFromPointCloud(*dataCloud,  *dataCloud,  indices);

    // downsample clouds
    pcl17::VoxelGrid vg;
    vg.setInputCloud(modelCloud);
    vg.setLeafSize (0.01f, 0.01f, 0.01f);
    vg.filter(*modelCloudDownsampled);

    vg.setInputCloud(dataCloud);
    vg.setLeafSize (0.01f, 0.01f, 0.01f);
    vg.filter(*dataCloudDownsampled);


    /* Segal-GICP */
    dgc::gicp::GICPPointSet ps_in, ps_out;
 
    for(int i=0; ipoints.size(); ++i)
    {
        dgc::gicp::GICPPoint p;
        p.x = dataCloudDownsampled->points[i].x;
        p.y = dataCloudDownsampled->points[i].y;
        p.z = dataCloudDownsampled->points[i].z;
     
        ps_in.AppendPoint(p);
    }
 
    for(int i=0; ipoints.size(); ++i)
    {
        dgc::gicp::GICPPoint p;
        p.x = modelCloudDownsampled->points[i].x;
        p.y = modelCloudDownsampled->points[i].y;
        p.z = modelCloudDownsampled->points[i].z;
     
        ps_out.AppendPoint(p);
    }  
 
    dgc_transform_t T_guess, T_delta, T_est;
    dgc_transform_identity(T_delta);
    dgc_transform_identity(T_guess);

    ps_in.BuildKDTree();
    ps_out.BuildKDTree();
    ps_in.ComputeMatrices();
    ps_out.ComputeMatrices();
    ps_out.SetDebug(0);
    //ps_out.SetMaxIterationInner(8);
 
    ps_out.AlignScan(&ps_in, T_guess, T_delta, 5);
    dgc_transform_copy(T_est, T_guess);
    dgc_transform_left_multiply(T_est, T_delta);        
 
    Eigen::Matrix4f em;
 
    for(int i=0; i<4 i="" p="">        for(int j=0; j<4 j="" p="">            em(i,j) = (float) T_est[i][j];
         
    std::cout << em << std::endl << std::endl;

    return 0;
}

Friday, December 13, 2013

Boost linking error and its solution in ROS

Error


/usr/bin/ld: note: 'boost::signals::connection::~connection()' is defined in DSO /usr/lib/libboost_signals.so.1.46.1 so try adding it to the linker command line
  /usr/lib/libboost_signals.so.1.46.1: could not read symbols: Invalid operation
  collect2: ld returned 1 exit status



Solution

# Put this line before the executable or library in your CMakeLists.txt
   rosbuild_add_boost_directories()
   # assuming that my_target is your executable
   rosbuild_add_executable(my_target my_srcs/my_target.cpp)
   # Put this line after the executable or library:
   rosbuild_link_boost(my_target signals)

If the above steps does not solve the issue then add
target_link_libraries(my_target libboost_system.so)

Thursday, December 12, 2013

OMP Error: /usr/include/eigen3/Eigen/src/Core/products/GeneralMatrixMatrix.h:93: undefined reference to `omp_get_num_threads' ---> Solution to this error

Error:


  /usr/include/eigen3/Eigen/src/Core/products/GeneralMatrixMatrix.h:93: undefined reference to `omp_get_num_threads'
  CMakeFiles/ndt_feature_eval.dir/src/ndt_feature_eval.o: In function `void Eigen::internal::parallelize_gemm, Eigen::Transpose const>, Eigen::Matrix, Eigen::Matrix, Eigen::internal::gemm_blocking_space<0 -1="" double="" false=""> >, int>(Eigen::internal::gemm_functor, Eigen::Transpose const>, Eigen::Matrix, Eigen::Matrix, Eigen::internal::gemm_blocking_space<0 -1="" double="" false=""> > const&, int, int, bool)':
  /usr/include/eigen3/Eigen/src/Core/products/Parallelizer.h:105: undefined reference to `omp_get_num_threads'
  /usr/include/eigen3/Eigen/src/Core/products/Parallelizer.h:145: undefined reference to `GOMP_parallel_start'
  /usr/include/eigen3/Eigen/src/Core/products/Parallelizer.h:145: undefined reference to `GOMP_parallel_end'
  CMakeFiles/ndt_feature_eval.dir/src/ndt_feature_eval.o: In function `nbThreads':
  /usr/include/eigen3/Eigen/src/Core/products/Parallelizer.h:47: undefined reference to `omp_get_max_threads'
  collect2: ld returned 1 exit status
  make[3]: *** [../bin/ndt_feature_eval] Error 1
  make[3]: Leaving directory `/home/sai/fuerte_workspace/oru-ros-pkg-read-only/perception_oru/ndt_feature_reg/build'
  make[2]: *** [CMakeFiles/ndt_feature_eval.dir/all] Error 2
  make[2]: *** Waiting for unfinished jobs....
  Linking CXX executable ../bin/ndt_feature_reg_node
  CMakeFiles/ndt_feature_reg_node.dir/src/ndt_feature_reg_node.o: In function `lslgeneric::NDTMatcherD2D::derivativesNDT(std::vector*, std::allocator*> > const&, lslgeneric::NDTMap const&, Eigen::Matrix&, Eigen::Matrix&, bool) [clone ._omp_fn.0]':
  /home/sai/fuerte_workspace/oru-ros-pkg-read-only/perception_oru/ndt_registration/include/impl/ndt_matcher_d2d.hpp:1476: undefined reference to `omp_get_num_threads'
  /home/sai/fuerte_workspace/oru-ros-pkg-read-only/perception_oru/ndt_registration/include/impl/ndt_matcher_d2d.hpp:1476: undefined reference to `omp_get_thread_num'
  /home/sai/fuerte_workspace/oru-ros-pkg-read-only/perception_oru/ndt_registration/include/impl/ndt_matcher_d2d.hpp:1476: undefined reference to `GOMP_barrier'
  CMakeFiles/ndt_feature_reg_node.dir/src/ndt_feature_reg_node.o: In function `void Eigen::internal::parallelize_gemm, Eigen::Transpose const>, Eigen::Matrix, Eigen::Matrix, Eigen::internal::gemm_blocking_space<0 -1="" double="" false=""> >, int>(Eigen::internal::gemm_functor, Eigen::Transpose const>, Eigen::Matrix, Eigen::Matrix, Eigen::internal::gemm_blocking_space<0 -1="" double="" false=""> > const&, int, int, bool) [clone ._omp_fn.1]':
  /usr/include/eigen3/Eigen/src/Core/products/Parallelizer.h:131: undefined reference to `omp_get_num_threads'
  /usr/include/eigen3/Eigen/src/Core/products/Parallelizer.h:131: undefined reference to `omp_get_thread_num'
  CMakeFiles/ndt_feature_reg_node.dir/src/ndt_feature_reg_node.o: In function `lslgeneric::NDTMatcherD2D::derivativesNDT(std::vector*, std::allocator*> > const&, lslgeneric::NDTMap const&, Eigen::Matrix&, Eigen::Matrix&, bool)':
  /home/sai/fuerte_workspace/oru-ros-pkg-read-only/perception_oru/ndt_registration/include/impl/ndt_matcher_d2d.hpp:1550: undefined reference to `GOMP_parallel_start'
  /home/sai/fuerte_workspace/oru-ros-pkg-read-only/perception_oru/ndt_registration/include/impl/ndt_matcher_d2d.hpp:1550: undefined reference to `GOMP_parallel_end'
  CMakeFiles/ndt_feature_reg_node.dir/src/ndt_feature_reg_node.o: In function `Eigen::internal::general_matrix_matrix_product::run(int, int, int, double const*, int, double const*, int, double*, int, double, Eigen::internal::level3_blocking&, Eigen::internal::GemmParallelInfo*)':
  /usr/include/eigen3/Eigen/src/Core/products/GeneralMatrixMatrix.h:92: undefined reference to `omp_get_thread_num'
  /usr/include/eigen3/Eigen/src/Core/products/GeneralMatrixMatrix.h:93: undefined reference to `omp_get_num_threads'
  CMakeFiles/ndt_feature_reg_node.dir/src/ndt_feature_reg_node.o: In function `void Eigen::internal::parallelize_gemm, Eigen::Transpose const>, Eigen::Matrix, Eigen::Matrix, Eigen::internal::gemm_blocking_space<0 -1="" double="" false=""> >, int>(Eigen::internal::gemm_functor, Eigen::Transpose const>, Eigen::Matrix, Eigen::Matrix, Eigen::internal::gemm_blocking_space<0 -1="" double="" false=""> > const&, int, int, bool)':
  /usr/include/eigen3/Eigen/src/Core/products/Parallelizer.h:105: undefined reference to `omp_get_num_threads'
  /usr/include/eigen3/Eigen/src/Core/products/Parallelizer.h:145: undefined reference to `GOMP_parallel_start'
  /usr/include/eigen3/Eigen/src/Core/products/Parallelizer.h:145: undefined reference to `GOMP_parallel_end'
  CMakeFiles/ndt_feature_reg_node.dir/src/ndt_feature_reg_node.o: In function `nbThreads':
  /usr/include/eigen3/Eigen/src/Core/products/Parallelizer.h:47: undefined reference to `omp_get_max_threads'
  collect2: ld returned 1 exit status



Solution:


Add these lines in your CMakeLists.txt

#check for OpenMP
find_package(OpenMP)
if(OPENMP_FOUND)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
  if(MSVC90 OR MSVC10)
    if(MSVC90)
      set(OPENMP_DLL VCOMP90)
    elseif(MSVC10)
      set(OPENMP_DLL VCOMP100)
    endif(MSVC90)
    set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /DELAYLOAD:${OPENMP_DLL}D.dll")
    set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DELAYLOAD:${OPENMP_DLL}.dll")
  endif(MSVC)
else(OPENMP_FOUND)
  message (STATUS "OpenMP not found")
endif()

if (MSVC)
  Set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /O2 ${SSE_FLAGS}")
else (MSVC)
  set(CMAKE_CXX_FLAGS "-O3 ${CMAKE_CXX_FLAGS} ${SSE_FLAGS}")
  set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -O0 -g ${SSE_FLAGS}")
  set(CMAKE_CXX_FLAGS_RELEASE " ${CMAKE_CXX_FLAGS} -O3 ${SSE_FLAGS}")
endif (MSVC)

Thursday, December 5, 2013

pcl17 in ROS . Error " undefined referenced to "

Error 

Built target ROSBUILD_gensrv_lisp
  Built target ROSBUILD_gensrv_cpp
  make[3]: Entering directory `/home/sai/fuerte_workspace/depth_odometry_tools/depth_odometry/build'
  make[3]: Leaving directory `/home/sai/fuerte_workspace/depth_odometry_tools/depth_odometry/build'
  [ 88%] Built target rospack_gensrv
  make[3]: Entering directory `/home/sai/fuerte_workspace/depth_odometry_tools/depth_odometry/build'
  make[3]: Entering directory `/home/sai/fuerte_workspace/depth_odometry_tools/depth_odometry/build'
  make[3]: Leaving directory `/home/sai/fuerte_workspace/depth_odometry_tools/depth_odometry/build'
  make[3]: Leaving directory `/home/sai/fuerte_workspace/depth_odometry_tools/depth_odometry/build'
  [ 88%] [ 88%] Built target rosbuild_precompile
  Built target rospack_gensrv_all
  make[3]: Entering directory `/home/sai/fuerte_workspace/depth_odometry_tools/depth_odometry/build'
  make[3]: Leaving directory `/home/sai/fuerte_workspace/depth_odometry_tools/depth_odometry/build'
  make[3]: Entering directory `/home/sai/fuerte_workspace/depth_odometry_tools/depth_odometry/build'
  Linking CXX executable ../bin/depth_odometry_node
  /usr/bin/ld: skipping incompatible /usr/lib/Lib/libOpenNI.so when searching for -lOpenNI
  /usr/bin/ld: skipping incompatible /usr/lib/Lib/libOpenNI.so when searching for -lOpenNI
  /home/sai/fuerte_workspace/depth_odometry_tools/lib_depthtools/lib/librgbdtools.so: undefined reference to `pcl17::PCDWriter::resetLockingPermissions(std::basic_string, std::allocator > const&, boost::interprocess::file_lock&)'
  /home/sai/fuerte_workspace/depth_odometry_tools/lib_depthtools/lib/librgbdtools.so: undefined reference to `pcl17::KdTreeFLANN >::nearestKSearch(pcl17::PointXYZ const&, int, std::vector >&, std::vector >&) const'
  /home/sai/fuerte_workspace/depth_odometry_tools/lib_depthtools/lib/librgbdtools.so: undefined reference to `pcl17::PassThrough::applyFilterIndices(std::vector >&)'
  /home/sai/fuerte_workspace/depth_odometry_tools/lib_depthtools/lib/librgbdtools.so: undefined reference to `pcl17::KdTreeFLANN >::radiusSearch(pcl17::PointXYZ const&, double, std::vector >&, std::vector >&, unsigned int) const'
  /home/sai/fuerte_workspace/depth_odometry_tools/lib_depthtools/lib/librgbdtools.so: undefined reference to `pcl17::KdTreeFLANN >::setInputCloud(boost::shared_ptr const> const&, boost::shared_ptr > const> const&)'
  /home/sai/fuerte_workspace/depth_odometry_tools/lib_depthtools/lib/librgbdtools.so: undefined reference to `pcl17::KdTreeFLANN >::KdTreeFLANN(bool)'
  /home/sai/fuerte_workspace/depth_odometry_tools/lib_depthtools/lib/librgbdtools.so: undefined reference to `pcl17::search::KdTree::KdTree(bool)'
  /home/sai/fuerte_workspace/depth_odometry_tools/lib_depthtools/lib/librgbdtools.so: undefined reference to `pcl17::PCDWriter::writeASCII(std::basic_string, std::allocator > const&, sensor_msgs::PointCloud2_ > const&, Eigen::Matrix const&, Eigen::Quaternion const&, int)'
  /home/sai/fuerte_workspace/depth_odometry_tools/lib_depthtools/lib/librgbdtools.so: undefined reference to `pcl17::PCDWriter::writeBinary(std::basic_string, std::allocator > const&, sensor_msgs::PointCloud2_ > const&, Eigen::Matrix const&, Eigen::Quaternion const&)'
  /home/sai/fuerte_workspace/depth_odometry_tools/lib_depthtools/lib/librgbdtools.so: undefined reference to `pcl17::search::KdTree::setPointRepresentation(boost::shared_ptr const> const&)'
  /home/sai/fuerte_workspace/depth_odometry_tools/lib_depthtools/lib/librgbdtools.so: undefined reference to `pcl17::VoxelGrid::applyFilter(pcl17::PointCloud&)'
  /home/sai/fuerte_workspace/depth_odometry_tools/lib_depthtools/lib/librgbdtools.so: undefined reference to `pcl17::PassThrough::applyFilter(pcl17::PointCloud&)'
  /home/sai/fuerte_workspace/depth_odometry_tools/lib_depthtools/lib/librgbdtools.so: undefined reference to `pcl17::PCDWriter::setLockingPermissions(std::basic_string, std::allocator > const&, boost::interprocess::file_lock&)'
  /home/sai/fuerte_workspace/depth_odometry_tools/lib_depthtools/lib/librgbdtools.so: undefined reference to `pcl17::KdTreeFLANN >::cleanup()'
  /home/sai/fuerte_workspace/depth_odometry_tools/lib_depthtools/lib/librgbdtools.so: undefined reference to `pcl17::KdTreeFLANN >::setEpsilon(float)'
  collect2: ld returned 1 exit status
  make[3]: *** [../bin/depth_odometry_node] Error 1
  make[3]: Leaving directory `/home/sai/fuerte_workspace/depth_odometry_tools/depth_odometry/build'
  make[2]: *** [CMakeFiles/depth_odometry_node.dir/all] Error 2
  make[2]: Leaving directory `/home/sai/fuerte_workspace/depth_odometry_tools/depth_odometry/build'
  make[1]: *** [all] Error 2
  make[1]: Leaving directory `/home/sai/fuerte_workspace/depth_odometry_tools/depth_odometry/build'
-------------------------------------------------------------------------------}
[ rosmake ] Output from build of package depth_odometry written to:
[ rosmake ]    /home/sai/.ros/rosmake/rosmake_output-20131205-164150/depth_odometry/build_output.log
[rosmake-2] Finished <<< depth_odometry [FAIL] [ 3.10 seconds ]                                                                                      
[ rosmake ] Halting due to failure in package depth_odometry.
[ rosmake ] Waiting for other threads to complete.                                    
[ rosmake ] Results:                                                                                                                                
[ rosmake ] Built 36 packages with 1 failures.                                                                                                      
[ rosmake ] Summary output to directory                                                                                                              
[ rosmake ] /home/sai/.ros/rosmake/rosmake_output-20131205-164150                                                                                    
sai@sai-HP-EliteBook-8460w:~/fuerte_workspace$ rosmake depth_odometry


Solution

Add the lines given below in the CMakeLists.txt

include_directories(/home/sai/fuerte_workspace/pcl17/include/pcl-1.7/)
include_directories(/home/sai/fuerte_workspace/pcl17/lib/)
link_libraries(pcl17_2d ; pcl17_surface ; pcl_io_ply  ;   pcl_people  ; pcl_stereo ;pcl17_common ; pcl17_tracking.so ; pcl_io ;        pcl_people  ;  pcl_stereo; pcl17_features;pcl17_visualization.so  ;pcl_io;pcl_recognition   ;        pcl_stereo ;pcl17_filters    ;       pcl_2d    ;           pcl_io   ;      pcl_recognition;        pcl_surface;pcl17_io_ply    ;       pcl_2d      ;     pcl_kdtree;     pcl_recognition   ;    pcl_surface ;pcl17_io    ;            pcl_2d    ;     pcl_kdtree ;     pcl_registration ;           pcl_surface ;pcl17_kdtree  ;         pcl_common   ;       pcl_kdtree  ;   pcl_registration ;      pcl_tracking ;pcl17_keypoints ;       pcl_common   ;   pcl_keypoints  ;     pcl_registration   ;  pcl_tracking;pcl17_ml    ;    pcl_common;     pcl_keypoints ;   pcl_sample_consensus  ;     pcl_tracking; pcl17_octree  ;         pcl_features ;     pcl_keypoints ; pcl_sample_consensus ;  pcl_visualization; pcl17_people   ;         pcl_features;  pcl_ml  ;           pcl_sample_consensus ; pcl_visualization ;pcl17_recognition   ;   pcl_features  ; pcl_ml   ;     pcl_search  ;               pcl_visualization ;pcl17_registration  ;   pcl_filters   ;     pcl_ml;       pcl_search   ;    pcl17_sample_consensus;  pcl_filters;     pcl_octree   ;        pcl_search; pcl17_search      ;   pcl_filters ;   pcl_octree ;     pcl_segmentation ;pcl17_segmentation;     pcl_io_ply ;        pcl_octree ;    pcl_segmentation; pcl17_stereo;          pcl_io_ply;      pcl_people ;         pcl_segmentation ) 

Tuesday, December 3, 2013

How to use PCL 1.7 in ROS

copied from an answer at

source :  http://answers.ros.org/question/44821/updating-to-pcl-17-in-ros-fuerte/


Ok, I believe I figured out the update for using pcl17.
change directories to your ROS_PACAKGE_PATH

Download the packages from the link below
once you have these checked out change folders,

do

rosdep install
and
rosmake

on each pcl17 and pcl17_ros. Side note, it took a while to run rosmake on pcl17 so make sure you give it enough time.
If you are planning to use these in your package for say a pcl tutorial you have to change your 'manifest.xml'

depend package  = pcl17

and

depend package = pcl17_ros
Once you've done this make sure to update all your references from pcl::  to pcl17::  in your code