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
motion_capture.hpp
Go to the documentation of this file.
1// Copyright 2024 João Vitor Silva Mendes
2
3#ifndef MOTION_CAPTURE_HPP_
4#define MOTION_CAPTURE_HPP_
5
6#include <pcl/point_cloud.h>
7#include <pcl/point_types.h>
8#include <pcl/common/centroid.h>
9#include <pcl_conversions/pcl_conversions.h>
10
11#include <Eigen/Core>
12#include <queue>
13#include <string>
14
15#include <rclcpp/rclcpp.hpp>
16#include <sensor_msgs/msg/point_cloud2.hpp>
17#include <geometry_msgs/msg/point.hpp>
18#include <geometry_msgs/msg/vector3.hpp>
19
21{
22class MotionCapture : public rclcpp::Node
23{
24public:
38
47 {
50 kVectorZ = 2
51 };
52
60 std::string kDefaultPointCloudTopicFiltered {"/point_cloud/filtered"};
61
68 std::string kDefaultPositionPublishTopic {"/object_position"};
69
76 std::string kDefaultVelocityPublishTopic {"/object_velocity"};
77
84 std::string kDefaultAccelerationPublishTopic {"/object_acceleration"};
85
94
103
111
120
129
138
139private:
150 void pointCloudCallback(const sensor_msgs::msg::PointCloud2::SharedPtr msg);
151
161 void updatePositionSamples(const Eigen::Vector4f & centroid);
162
172 Eigen::Vector4f getFilteredPosition();
173
183 void updateVelocitySamples(const Eigen::Vector3f & velocity);
184
194 Eigen::Vector3f getFilteredVelocity();
195
203 void publishData();
204
213 void publishPosition(const Eigen::Vector4f & centroid);
214
225 Eigen::Vector3f publishVelocity(const Eigen::Vector4f & current_position);
226
236 void publishAcceleration(const Eigen::Vector3f & current_velocity);
237
246 void loadParameters();
247
255 rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr subscription_;
256
264 rclcpp::Publisher<geometry_msgs::msg::Point>::SharedPtr position_publisher_;
265
273 rclcpp::Publisher<geometry_msgs::msg::Vector3>::SharedPtr velocity_publisher_;
274
282 rclcpp::Publisher<geometry_msgs::msg::Vector3>::SharedPtr acceleration_publisher_;
283
292 std::queue<Eigen::Vector4f> position_queue_;
293
301 std::queue<Eigen::Vector3f> velocity_queue_;
302
309 Eigen::Vector4f previous_position_;
310
317 Eigen::Vector3f previous_velocity_;
318
326 rclcpp::Time previous_time_;
327
336
344
352
360
369
377 rclcpp::TimerBase::SharedPtr timer_;
378
387
395
403
411};
412
413} // namespace pointcloud_motion_capture
414
415#endif // MOTION_CAPTURE_HPP_
rclcpp::Publisher< geometry_msgs::msg::Vector3 >::SharedPtr acceleration_publisher_
ROS2 publisher to send the calculated object acceleration.
CentroidIndex
Enumeration representing indices for the centroid coordinates.
@ kCentroidY
Index for the Y-coordinate of the centroid.
@ kCentroidX
Index for the X-coordinate of the centroid.
@ kCentroidZ
Index for the Z-coordinate of the centroid.
void publishData()
Publishes the calculated position, velocity, and acceleration.
double kDefaultPublishRate
Default publish rate in Hz for publishing position, velocity, and acceleration.
int kDefaultQueueSize
Default queue size for ROS publishers and subscriptions.
Eigen::Vector4f getFilteredPosition()
Retrieves the filtered position of the object.
VectorIndex
Enumeration representing indices for the velocity vector.
@ kVectorZ
Index for the Z-component of the velocity vector.
@ kVectorY
Index for the Y-component of the velocity vector.
@ kVectorX
Index for the X-component of the velocity vector.
std::string kDefaultPointCloudTopicFiltered
Default topic name for subscribing to the filtered point cloud data.
Eigen::Vector4f previous_position_
The previous position of the object in 3D space.
void updatePositionSamples(const Eigen::Vector4f &centroid)
Updates the position samples queue with a new centroid value.
std::string acceleration_publish_topic_
Topic name for publishing the calculated acceleration of an object.
void loadParameters()
Loads parameters from the ROS2 parameter server.
rclcpp::Time previous_time_
The timestamp of the previous position sample.
std::queue< Eigen::Vector4f > position_queue_
Queue to store recent position samples for calculating position.
int kDefaultPositionSamples
Default number of position samples used for calculations.
Eigen::Vector3f publishVelocity(const Eigen::Vector4f &current_position)
Publishes the object's velocity to a ROS topic.
std::string kDefaultAccelerationPublishTopic
Default topic name for publishing the calculated object acceleration.
std::queue< Eigen::Vector3f > velocity_queue_
Queue to store recent velocity samples for calculating velocity.
int kDefaultVelocitySamples
Default number of velocity samples used for calculations.
Eigen::Vector3f getFilteredVelocity()
Retrieves the filtered velocity of the object.
int velocity_samples_
Number of velocity samples used for calculations.
std::string kDefaultPositionPublishTopic
Default topic name for publishing the calculated object position.
int position_samples_
Number of position samples used for calculations.
rclcpp::Publisher< geometry_msgs::msg::Vector3 >::SharedPtr velocity_publisher_
ROS2 publisher to send the calculated object velocity.
std::string point_cloud_topic_filtered_
Topic name for subscribing to filtered point cloud data.
double kMillisecondsPerSecond
Conversion factor from seconds to milliseconds.
std::string kDefaultVelocityPublishTopic
Default topic name for publishing the calculated object velocity.
MotionCapture()
Constructor for the MotionCapture class.
int queue_size_
Queue size for message publishers and subscriptions.
rclcpp::TimerBase::SharedPtr timer_
Timer used for scheduling the publication of data.
Eigen::Vector3f previous_velocity_
The previous velocity of the object in 3D space.
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 PointCloud2 messages.
void publishPosition(const Eigen::Vector4f &centroid)
Publishes the object's position to a ROS topic.
void updateVelocitySamples(const Eigen::Vector3f &velocity)
Updates the velocity samples queue with a new velocity value.
void publishAcceleration(const Eigen::Vector3f &current_velocity)
Publishes the object's acceleration to a ROS topic.
std::string velocity_publish_topic_
Topic name for publishing the calculated velocity of an object.
rclcpp::Publisher< geometry_msgs::msg::Point >::SharedPtr position_publisher_
ROS2 publisher to send the calculated object position.
rclcpp::Time previous_velocity_time_
The timestamp of the previous velocity sample.
std::string position_publish_topic_
Topic name for publishing the calculated position of an object.
double publish_rate_
Publish rate for sending position, velocity, and acceleration data.