PointCloud Motion Capture
Pointcloud Motion Capture is a ROS 2 package designed to process point clouds for capturing object movements. It detects objects using color filters and infers data about their position, velocity, and acceleration. This package has been tested under [ROS] Humble and Ubuntu 22.04
Loading...
Searching...
No Matches
point_cloud_reader.cpp
Go to the documentation of this file.
1// Copyright 2024 João Vitor Silva Mendes
2
4
6{
8: Node("point_cloud_processor")
9{
11
12 subscription_ = this->create_subscription<sensor_msgs::msg::PointCloud2>(
14 std::bind(&PointCloudProcessor::pointCloudCallback, this, std::placeholders::_1));
15
16 publisher_ = this->create_publisher<sensor_msgs::msg::PointCloud2>(
18
19 RCLCPP_INFO(this->get_logger(), "PointCloudProcessor node initialized.");
20}
21
23{
24 this->declare_parameter<int>("red_threshold", kRedThresholdDefault);
25 this->declare_parameter<int>("green_threshold", kGreenThresholdDefault);
26 this->declare_parameter<int>("blue_threshold", kBlueThresholdDefault);
27 this->declare_parameter<std::string>("point_cloud_topic_raw", kPointCloudTopicRaw);
28 this->declare_parameter<std::string>("point_cloud_topic_filtered", kPointCloudTopicFiltered);
29 this->declare_parameter<float>("update_rate", kUpdateRate);
30
31 this->get_parameter("red_threshold", red_threshold_);
32 this->get_parameter("green_threshold", green_threshold_);
33 this->get_parameter("blue_threshold", blue_threshold_);
34 this->get_parameter("point_cloud_topic_raw", point_cloud_topic_raw_);
35 this->get_parameter("point_cloud_topic_filtered", point_cloud_topic_filtered_);
36 this->get_parameter("update_rate", update_rate_);
37
38 RCLCPP_INFO(this->get_logger(), "Loading Parameters...");
39 RCLCPP_INFO(this->get_logger(), "Filter parameters:");
40 RCLCPP_INFO(this->get_logger(), " Red threshold: %d", red_threshold_);
41 RCLCPP_INFO(this->get_logger(), " Green threshold: %d", green_threshold_);
42 RCLCPP_INFO(this->get_logger(), " Blue threshold: %d", blue_threshold_);
43 RCLCPP_INFO(this->get_logger(), "Reading point cloud from: %s", point_cloud_topic_raw_.c_str());
44 RCLCPP_INFO(
45 this->get_logger(), "Publishing filtered point cloud on: %s",
47 RCLCPP_INFO(this->get_logger(), "Update Rate: %f Hz", update_rate_);
48}
49
50
51void PointCloudProcessor::pointCloudCallback(const sensor_msgs::msg::PointCloud2::SharedPtr msg)
52{
53 pcl::PointCloud<pcl::PointXYZRGB>::Ptr pcl_cloud(new pcl::PointCloud<pcl::PointXYZRGB>());
54 pcl::fromROSMsg(*msg, *pcl_cloud);
55
56 pcl::PointCloud<pcl::PointXYZRGB>::Ptr filtered_cloud(new pcl::PointCloud<pcl::PointXYZRGB>());
57 for (const auto & point : *pcl_cloud) {
58 if (point.r > red_threshold_ && point.g < green_threshold_ && point.b < blue_threshold_) {
59 filtered_cloud->push_back(point);
60 }
61 }
62
63 pcl::toROSMsg(*filtered_cloud, filtered_msg_);
64 filtered_msg_.header.frame_id = frame_id_;
65 filtered_msg_.header.stamp = this->get_clock()->now();
66
67 publisher_->publish(filtered_msg_);
68}
69
70} // namespace pointcloud_motion_capture
71
72int main(int argc, char ** argv)
73{
74 rclcpp::init(argc, argv);
75 rclcpp::spin(std::make_shared<pointcloud_motion_capture::PointCloudProcessor>());
76 rclcpp::shutdown();
77 return 0;
78}
const std::string kPointCloudTopicFiltered
ROS topic that publishes the filtered point cloud.
std::string point_cloud_topic_raw_
ROS topic for receiving the raw point cloud data.
std::string point_cloud_topic_filtered_
ROS topic for publishing the filtered point cloud data.
const int kBlueThresholdDefault
Default value for the blue color threshold.
const int kGreenThresholdDefault
Default value for the green color threshold.
void load_parameters()
Loads parameters from the ROS2 parameter server.
float update_rate_
Update rate for processing the point cloud data.
const float kUpdateRate
Default update rate (in Hz).
rclcpp::Publisher< sensor_msgs::msg::PointCloud2 >::SharedPtr publisher_
ROS2 publisher to publish filtered PointCloud2 messages.
int red_threshold_
Threshold value for red color filtering.
int green_threshold_
Threshold value for green color filtering.
rclcpp::Subscription< sensor_msgs::msg::PointCloud2 >::SharedPtr subscription_
ROS2 subscription to receive PointCloud2 messages.
void pointCloudCallback(const sensor_msgs::msg::PointCloud2::SharedPtr msg)
Callback function for processing incoming point cloud data.
std::string frame_id_
Frame ID used for the point cloud data.
int blue_threshold_
Threshold value for blue color filtering.
const int kRedThresholdDefault
Default value for the red color threshold.
sensor_msgs::msg::PointCloud2 filtered_msg_
Holds the filtered PointCloud2 message.
const std::string kPointCloudTopicRaw
ROS topic that receives the raw (unfiltered) point cloud.
int main(int argc, char **argv)