[关闭]
@Pigmon 2018-11-29T11:53:09.000000Z 字数 3165 阅读 95

Velodyne Grabber 例子

慧拓


说明

链接激光雷达;新建一个catkin工程,cpp,cmake和package文件都在这个文档里。

  1. catkin_make
  2. source devel/setup.sh
  3. rosrun grabber_test test_node

main.cpp

  1. #include <iostream>
  2. #include <sstream>
  3. #include <ros/ros.h>
  4. #include <sensor_msgs/PointCloud2.h>
  5. #include <pcl/point_cloud.h>
  6. #include <pcl/point_types.h>
  7. #include <pcl/io/hdl_grabber.h>
  8. #include <pcl/conversions.h>
  9. #include <pcl_conversions/pcl_conversions.h>
  10. typedef pcl::PointXYZI PointType;
  11. int main(int argc, char *argv[])
  12. {
  13. ros::init(argc, argv, "memc_cloud");
  14. ros::Time::init();
  15. std::string ipaddress("192.168.1.201");
  16. std::string port("2368");
  17. pcl::PointCloud<PointType>::ConstPtr cloud_;
  18. boost::mutex mutex;
  19. boost::function<void(const pcl::PointCloud<PointType>::ConstPtr &)> function =
  20. [&cloud_, &mutex](const pcl::PointCloud<PointType>::ConstPtr &ptr) {
  21. boost::mutex::scoped_lock lock(mutex);
  22. // 这里实际得到了一帧数据
  23. cloud_ = ptr;
  24. ROS_INFO("<pcl::PointCloud> Point Count: %ld", cloud_->points.size());
  25. // 转换成 pcl::PointCloud2
  26. double start_time = ros::Time::now().toSec();
  27. pcl::PCLPointCloud2 pcl_pc2;
  28. toPCLPointCloud2(*cloud_, pcl_pc2);
  29. ROS_INFO("<pcl::PointCloud2> Data in Bytes: %ld", pcl_pc2.data.size());
  30. // 转换成 ROS Message
  31. //sensor_msgs::PointCloud2 msg;
  32. //pcl_conversions::fromPCL(pcl_pc2, msg);
  33. //ROS_INFO("<sensor_msgs::PointCloud2> Data in Bytes: %ld", msg.data.size());
  34. };
  35. // HDL Grabber
  36. boost::shared_ptr<pcl::HDLGrabber> grabber;
  37. std::cout << "Capture from Sensor..." << std::endl;
  38. grabber = boost::shared_ptr<pcl::HDLGrabber>(
  39. new pcl::HDLGrabber(
  40. boost::asio::ip::address::from_string(ipaddress),
  41. boost::lexical_cast<unsigned short>(port)));
  42. // Register Callback Function
  43. boost::signals2::connection connection = grabber->registerCallback(function);
  44. // Start Grabber
  45. grabber->start();
  46. // Just loop...
  47. while (ros::ok())
  48. {
  49. }
  50. // Stop Grabber
  51. grabber->stop();
  52. // Disconnect Callback Function
  53. if (connection.connected())
  54. {
  55. connection.disconnect();
  56. }
  57. return 0;
  58. }

CMake

  1. cmake_minimum_required(VERSION 2.8.3)
  2. project(grabber_test)
  3. add_compile_options(-std=c++11)
  4. find_package(catkin REQUIRED COMPONENTS
  5. roscpp
  6. pcl_ros
  7. )
  8. catkin_package(
  9. )
  10. ###########
  11. ## Build ##
  12. ###########
  13. include_directories(
  14. include
  15. ${catkin_INCLUDE_DIRS}
  16. )
  17. find_package(PCL 1.7 REQUIRED)
  18. include_directories(${PCL_INCLUDE_DIRS})
  19. link_directories(${PCL_LIBRARY_DIRS})
  20. add_definitions(${PCL_DEFINITIONS})
  21. message(STATUS "PCL_INCLUDE_DIRS:" ${PCL_INCLUDE_DIRS})
  22. message(STATUS "PCL_LIBRARY_DIRS:" ${PCL_LIBRARY_DIRS})
  23. message(STATUS "PCL_DEFINITIONS:" ${PCL_DEFINITIONS})
  24. find_package(OpenMP)
  25. if (OPENMP_FOUND)
  26. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
  27. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
  28. endif()
  29. #############
  30. ## Install ##
  31. #############
  32. #############
  33. ## Testing ##
  34. #############
  35. add_executable(test_node src/main.cpp)
  36. target_link_libraries(test_node ${catkin_LIBRARIES})

Package.xml

  1. <?xml version="1.0"?>
  2. <package format="2">
  3. <name>grabber_test</name>
  4. <version>0.0.0</version>
  5. <description>Fetch Point Cloud and Cache them into Memcached</description>
  6. <maintainer email="pigmon@todo.todo">pigmon</maintainer>
  7. <license>TODO</license>
  8. <buildtool_depend>catkin</buildtool_depend>
  9. <build_depend>roscpp</build_depend>
  10. <build_depend>pcl_ros</build_depend>
  11. <build_export_depend>roscpp</build_export_depend>
  12. <build_export_depend>pcl_ros</build_export_depend>
  13. <exec_depend>roscpp</exec_depend>
  14. <exec_depend>pcl_ros</exec_depend>
  15. <export>
  16. </export>
  17. </package>
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注