0
$\begingroup$

Rosanswers logo

Hi-

I'm trying to create a script that takes in 2 bag files (fixed_frame and camera_frame), converts the ROS sensor_msgs/PointCloud2 data to pcl/PointCloud data, performs ICP between the pointcloud in fixed_frame and all the pointclouds in camera_frame, and publishes the results. Here is my code so far:

// Includes listed here

ros::Publisher _pub;
pcl::PointCloud<pcl::PointXYZ> cloud_in; 

void fixed_frame_cb (const sensor_msgs::PointCloud2ConstPtr& pc2_msg) {

  // Convert the sensor_msgs/PointCloud2 data to pcl/PointCloud
  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_in(
                           new pcl::PointCloud<pcl::PointXYZ>
                           );
  pcl::fromROSMsg ( *pc2_msg, *cloud_in );


}

void camera_frame_cb (const sensor_msgs::PointCloud2ConstPtr& next_pc2_msg) {
 
  // Convert the sensor_msgs/PointCloud2 data to pcl/PointCloud
  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud2_in(
                           new pcl::PointCloud<pcl::PointXYZ>
                           );
  pcl::fromROSMsg ( *next_pc2_msg, *cloud2_in );

  // Perform ICP
  pcl::IterativeClosestPoint<pcl::PointXYZ, pcl::PointXYZ> icp;
  icp.setInputCloud(cloud2_in);
  icp.setInputTarget(cloud_in);
  pcl::PointCloud<pcl::PointXYZ> Final;
  icp.align(Final);

  // Convert the pcl/PointCloud to sensor_msgs/PointCloud2
  sensor_msgs::PointCloud2 output;
  pcl::toROSMsg( *cloud2_in, output );
  // Publish the results
  _pub.publish( output );

}

int main (int argc, char** argv) {

  // Initialize ROS
  ros::init (argc, argv, "my_script");
  ros::NodeHandle n( "~" );

  // Create ROS subscriber for fixed_frame topic
  ros::Subscriber sub = n.subscribe(
                    "/sr/pointcloud2/raw",
                    1,
                    fixed_frame_cb
                    );

  // Create ROS subscriber for camera_frame topic
  ros::Subscriber sub2 = n.subscribe(
                     "/sr/pointcloud2/raw",
                     1,
                     camera_frame_cb
                     );

  // Create ROS publisher for transformed pointcloud
  _pub = n.advertise<sensor_msgs::PointCloud2>(
                           "/iml_transform_point_cloud/transformed_point_cloud",
                           1
                           );

  // Spin
  ros::spin ();
}

I'm getting a lot of errors when I run 'make'. New to ros and c++, so I think these might just be syntax problems. Can anyone point me in the right direction? Thanks in advance.

Make errors:

mdegges@ubuntu:~/ros_workspace/iml_ros/my_script$ make mkdir -p bin cd build && cmake -Wdev -DCMAKE_TOOLCHAIN_FILE=/opt/ros/groovy/share/ros/core/rosbuild/rostoolchain.cmake .. [rosbuild] Building package my_script -- Using CATKIN_DEVEL_PREFIX: /home/mdegges/ros_workspace/iml_ros/my_script/build/devel -- Using CMAKE_PREFIX_PATH: /opt/ros/groovy -- This workspace overlays: /opt/ros/groovy -- Found gtest sources under '/usr/src/gtest': gtests will be built -- catkin 0.5.63 [rosbuild] Including /opt/ros/groovy/share/roscpp/rosbuild/roscpp.cmake [rosbuild] Including /opt/ros/groovy/share/rospy/rosbuild/rospy.cmake -- Configuring done -- Generating done CMake Warning: Manually-specified variables were not used by the project:

CMAKE_TOOLCHAIN_FILE

-- Build files have been written to: /home/mdegges/ros_workspace/iml_ros/my_script/build cd build && make make[1]: Entering directory /home/mdegges/ros_workspace/iml_ros/my_script/build' make[2]: Entering directory /home/mdegges/ros_workspace/iml_ros/my_script/build' make[3]: Entering directory /home/mdegges/ros_workspace/iml_ros/my_script/build' make[3]: Leaving directory /home/mdegges/ros_workspace/iml_ros/my_script/build' [ 0%] Built target rospack_genmsg_libexe make[3]: Entering directory /home/mdegges/ros_workspace/iml_ros/my_script/build' make[3]: Leaving directory /home/mdegges/ros_workspace/iml_ros/my_script/build' [ 0%] Built target rosbuild_precompile make[3]: Entering directory /home/mdegges/ros_workspace/iml_ros/my_script/build' make[3]: Leaving directory /home/mdegges/ros_workspace/iml_ros/my_script/build' make[3]: Entering directory `/home/mdegges/ros_workspace/iml_ros/my_script/build' [100%] Building CXX object CMakeFiles/my_script.dir/src/example.cpp.o /home/mdegges/ros_workspace/iml_ros/my_script/src/example.cpp: In function ‘void camera_frame_cb(const PointCloud2ConstPtr&)’: /home/mdegges/ros_workspace/iml_ros/my_script/src/example.cpp:37:30: error: no matching function for call to ‘pcl::IterativeClosestPoint<pcl::PointXYZ, pcl::PointXYZ>::setInputTarget(pcl::PointCloudpcl::PointXYZ&)’ /home/mdegges/ros_workspace/iml_ros/my_script/src/example.cpp:37:30: note: candidate is: /opt/ros/groovy/include/pcl-1.6/pcl/registration/impl/registration.hpp:42:1: note: void pcl::Registration<PointSource, PointTarget>::setInputTarget(const PointCloudTargetConstPtr&) [with PointSource = pcl::PointXYZ, PointTarget = pcl::PointXYZ, pcl::Registration<PointSource, PointTarget>::PointCloudTargetConstPtr = boost::shared_ptr<const pcl::PointCloudpcl::PointXYZ >] /opt/ros/groovy/include/pcl-1.6/pcl/registration/impl/registration.hpp:42:1: note: no known conversion for argument 1 from ‘pcl::PointCloudpcl::PointXYZ’ to ‘const PointCloudTargetConstPtr& {aka const boost::shared_ptr<const pcl::PointCloudpcl::PointXYZ >&}’ In file included from /opt/ros/groovy/include/ros/node_handle.h:32:0, from /opt/ros/groovy/include/ros/ros.h:45, from /home/mdegges/ros_workspace/iml_ros/my_script/src/example.cpp:1: /opt/ros/groovy/include/ros/publisher.h: In member function ‘void ros::Publisher::publish(const M&) const [with M = sensor_msgs::PointCloud2_std::allocator<void

]’: /home/mdegges/ros_workspace/iml_ros/my_script/src/example.cpp:45:24: instantiated from here /opt/ros/groovy/include/ros/publisher.h:112:7: warning: comparison with string literal results in unspecified behaviour [-Waddress] make[3]: *** [CMakeFiles/my_script.dir/src/example.cpp.o] Error 1 make[3]: Leaving directory /home/mdegges/ros_workspace/iml_ros/my_script/build' make[2]: *** [CMakeFiles/my_script.dir/all] Error 2 make[2]: Leaving directory /home/mdegges/ros_workspace/iml_ros/my_script/build' make[1]: *** [all] Error 2 make[1]: Leaving directory `/home/mdegges/ros_workspace/iml_ros/my_script/build' make: *** [all] Error 2


Originally posted by mdegges on ROS Answers with karma: 57 on 2013-04-09

Post score: 0


Original comments

Comment by Dan Lazewatsky on 2013-04-09:
Please edit your question with the errors you're seeing. It is very hard to help you without seeing what the problem is.

Comment by mdegges on 2013-04-09:
Ok- I posted the make errors on pastie: http://pastie.org/7397787

Comment by yangyangcv on 2013-04-09:
cannot open the page on pastie. why don't you just paste the error here? and you should also provide you CMakeLists.txt file

Comment by mdegges on 2013-04-09:
Sorry- edited the question with the errors included. The CMakeLists.txt file is the default, except I added a line at the bottom to make the script executable.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Figured it out. I just had some syntax errors- for ex, when I defined the global variable 'cloud_in', I forgot to make it a pointer.


Originally posted by mdegges with karma: 57 on 2013-04-11

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by jrgen on 2017-09-29:
How did you get the two .bag files into your program? I tried rosbag play -l 2017-06-07-13-49-48.bag 2017-06-07-14-05-40.bag /camera/depth/points:=icp/input/raw But that doesn't work.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.