5 #include <pcl_conversions/pcl_conversions.h>
15 log_warning(
"[Realsense::init] Configuration File ignored. (not implemented)");
17 log(
"Enable depth stream...");
18 m_cfg.enable_stream(RS2_STREAM_DEPTH, RS2_FORMAT_Z16);
21 auto callback = [&](
const rs2::frame& frame) {
22 log_debug(
"[Realsense::Callback] New Frame");
23 auto now = this->m_nodePtr->get_clock()->now();
26 if(!frame.is<rs2::frameset>()) {
32 auto frameset = frame.as<rs2::frameset>();
34 auto it = frameset.begin();
35 if (it == frameset.end()) {
40 if((*it).get_profile().stream_type() != RS2_STREAM_DEPTH) {
41 log_warning(
"[Realsense::Callback] No Depth Frame");
46 rs2::depth_frame depthFrame = frameset.get_depth_frame();
47 rs2::pointcloud pointcloud;
48 rs2::points pc = pointcloud.calculate(depthFrame);
50 auto pointCloudPairSPtr = std::make_shared<std::pair<rclcpp::Time, pcl::PointCloud<pcl::PointXYZ>::Ptr>>();
51 std::get<0>(*pointCloudPairSPtr) = now;
52 std::get<1>(*pointCloudPairSPtr) = points_to_pcl(pc);
55 this->m_currentPointCloudPairSPtr = pointCloudPairSPtr;
56 this->m_currentPointCloudPairNewData =
true;
57 m_newPCLConditionVar.notify_all();
74 log(
"Pipeline started...");
76 m_profile = m_pipe.start(callback);
138 std::unique_lock<std::mutex> lock(m_mtx);
139 std::shared_ptr<std::pair<rclcpp::Time, pcl::PointCloud<pcl::PointXYZ>::Ptr>> ret =
nullptr;
141 if(m_currentPointCloudPairNewData) {
142 ret = m_currentPointCloudPairSPtr;
143 m_currentPointCloudPairNewData =
false;
147 if(ret ==
nullptr && blocking) {
148 m_newPCLConditionVar.wait(lock);
149 ret = m_currentPointCloudPairSPtr;
150 m_currentPointCloudPairNewData =
false;
157 std::unique_lock<std::mutex> lock(m_mtx);
158 std::shared_ptr<std::pair<rclcpp::Time, pcl::PointCloud<pcl::PointXYZ>::Ptr>> ret = m_currentPointCloudPairSPtr;
164 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(
new pcl::PointCloud<pcl::PointXYZ>);
166 auto sp = points.get_profile().as<rs2::video_stream_profile>();
169 cloud->width = points.size();
171 cloud->is_dense =
true;
172 cloud->points.reserve(points.size());
174 auto ptr = points.get_vertices();
176 size_t pointsAppended = 0;
178 float m_minY = -0.08;
179 float m_maxY = 0.08f;
182 for (
size_t i = 0; i < points.size(); ++i) {
183 if(ptr->z <= m_maxZ && ptr->y >= m_minY && ptr->y <= m_maxY) {
184 cloud->push_back(pcl::PointXYZ(ptr->x, ptr->y, ptr->z));
192 cloud->points.resize(pointsAppended);
193 cloud->width = pointsAppended;