diff --git a/CMakeLists.txt b/CMakeLists.txt index d7feef5..df143eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,8 @@ find_package(catkin REQUIRED COMPONENTS data_convert geometry_msgs nav_msgs + pcl_conversions + pcl_ros robot_depth_image_proc robot_costmap_2d robot_cpp @@ -20,6 +22,11 @@ find_package(catkin REQUIRED COMPONENTS tf2_ros ) +find_package(PCL REQUIRED COMPONENTS + common + filters +) + find_library(TF3_LIBRARY NAMES tf3 PATHS /usr/lib /usr/local/lib /usr/lib/x86_64-linux-gnu @@ -38,11 +45,13 @@ add_executable(depth_local_costmap_noetic_test_node target_include_directories(depth_local_costmap_noetic_test_node PRIVATE ${catkin_INCLUDE_DIRS} + ${PCL_INCLUDE_DIRS} ) target_link_libraries(depth_local_costmap_noetic_test_node PRIVATE ${catkin_LIBRARIES} + ${PCL_LIBRARIES} ${TF3_LIBRARY} ) diff --git a/README.md b/README.md index 0fba676..261cd27 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,20 @@ roslaunch depth_local_costmap_noetic_test depth_local_costmap_test.launch publis Không bật `publish_odom_tf` nếu đã có node khác publish TF này. +Point cloud marking `/camera/depth/points_proc` được downsample bằng PCL +`VoxelGrid` trước khi feed vào `robot_costmap_2d`, giống hướng trong +`amr_control/src/sensor_converter.cpp`. Mặc định leaf size là `0.10 m`: + +```bash +roslaunch depth_local_costmap_noetic_test depth_local_costmap_test.launch depth_cloud_voxel_leaf_size:=0.10 +``` + +Nếu muốn so sánh full cloud: + +```bash +roslaunch depth_local_costmap_noetic_test depth_local_costmap_test.launch enable_depth_cloud_voxel_filter:=false +``` + ## Kiểm tra runtime ```bash diff --git a/launch/depth_local_costmap_test.launch b/launch/depth_local_costmap_test.launch index 5f56132..49c0928 100644 --- a/launch/depth_local_costmap_test.launch +++ b/launch/depth_local_costmap_test.launch @@ -2,6 +2,8 @@ + + @@ -20,6 +22,8 @@ + + diff --git a/package.xml b/package.xml index 034c0f7..4f2a5a8 100644 --- a/package.xml +++ b/package.xml @@ -12,6 +12,8 @@ data_convert geometry_msgs nav_msgs + pcl_conversions + pcl_ros robot_depth_image_proc robot_costmap_2d robot_cpp diff --git a/src/depth_local_costmap_noetic_test_node.cpp b/src/depth_local_costmap_noetic_test_node.cpp index feb12bf..0a40bde 100644 --- a/src/depth_local_costmap_noetic_test_node.cpp +++ b/src/depth_local_costmap_noetic_test_node.cpp @@ -26,6 +26,11 @@ #include #include +#include +#include +#include +#include + #include #include #include @@ -265,6 +270,10 @@ public: : local_costmap_(local_costmap) { private_nh.param("depth_cloud_topic", depth_cloud_topic_, std::string("/camera/depth/points_proc")); + private_nh.param("enable_depth_cloud_voxel_filter", enable_voxel_filter_, true); + private_nh.param("depth_cloud_voxel_leaf_size", voxel_leaf_size_, 0.10); + voxel_leaf_size_ = std::max(0.0, voxel_leaf_size_); + depth_cloud_sub_ = private_nh.subscribe(depth_cloud_topic_, 1, &DepthCloudFeeder::depthCloudCallback, this); } @@ -276,16 +285,48 @@ private: return; const robot_sensor_msgs::PointCloud2 robot_cloud = toRobotPointCloud2(*msg); - feedVoxelLayers(local_costmap_, robot_cloud, depth_cloud_topic_); + const robot_sensor_msgs::PointCloud2 marking_cloud = filterMarkingCloud(robot_cloud); + feedVoxelLayers(local_costmap_, marking_cloud, depth_cloud_topic_); - ROS_INFO_THROTTLE(5.0, "Fed depth cloud to robot_costmap_2d: %ux%u frame=%s", + ROS_INFO_THROTTLE(5.0, + "Fed depth cloud to robot_costmap_2d: in=%ux%u out=%ux%u leaf=%.3f frame=%s", msg->width, msg->height, + marking_cloud.width, + marking_cloud.height, + enable_voxel_filter_ ? voxel_leaf_size_ : 0.0, msg->header.frame_id.c_str()); } + robot_sensor_msgs::PointCloud2 filterMarkingCloud(const robot_sensor_msgs::PointCloud2& cloud) const + { + if (!enable_voxel_filter_ || voxel_leaf_size_ <= 0.0 || cloud.width == 0 || cloud.height == 0) + return cloud; + + pcl::PointCloud pcl_cloud; + pcl::fromROBOTMsg(cloud, pcl_cloud); + if (pcl_cloud.empty()) + return cloud; + + pcl::VoxelGrid voxel; + voxel.setInputCloud(pcl_cloud.makeShared()); + voxel.setLeafSize(static_cast(voxel_leaf_size_), + static_cast(voxel_leaf_size_), + static_cast(voxel_leaf_size_)); + + pcl::PointCloud filtered; + voxel.filter(filtered); + + robot_sensor_msgs::PointCloud2 output; + pcl::toROBOTMsg(filtered, output); + output.header = cloud.header; + return output; + } + robot_costmap_2d::Costmap2DROBOT& local_costmap_; std::string depth_cloud_topic_; + bool enable_voxel_filter_{true}; + double voxel_leaf_size_{0.10}; ros::Subscriber depth_cloud_sub_; };