mirror of
https://github.com/orbbec/OrbbecSDK_ROS2.git
synced 2026-10-04 20:17:47 +08:00
Update publishScanToPoint
This commit is contained in:
@@ -59,7 +59,7 @@ def generate_launch_description():
|
|||||||
DeclareLaunchArgument('publish_tf', default_value='true'),
|
DeclareLaunchArgument('publish_tf', default_value='true'),
|
||||||
DeclareLaunchArgument('tf_publish_rate', default_value='0.0'),
|
DeclareLaunchArgument('tf_publish_rate', default_value='0.0'),
|
||||||
DeclareLaunchArgument('lidar_format', default_value='ANY'),#LIDAR_POINT, LIDAR_SPHERE_POINT, LIDAR_SCAN
|
DeclareLaunchArgument('lidar_format', default_value='ANY'),#LIDAR_POINT, LIDAR_SPHERE_POINT, LIDAR_SCAN
|
||||||
DeclareLaunchArgument('lidar_rate', default_value='20'),
|
DeclareLaunchArgument('lidar_rate', default_value='30'),
|
||||||
DeclareLaunchArgument('enable_scan_to_point', default_value='false'),
|
DeclareLaunchArgument('enable_scan_to_point', default_value='false'),
|
||||||
DeclareLaunchArgument('repetitive_scan_mode', default_value='-1'),
|
DeclareLaunchArgument('repetitive_scan_mode', default_value='-1'),
|
||||||
DeclareLaunchArgument('filter_level', default_value='-1'),
|
DeclareLaunchArgument('filter_level', default_value='-1'),
|
||||||
|
|||||||
@@ -460,7 +460,7 @@ void OBLidarNode::publishScan(std::shared_ptr<ob::FrameSet> frame_set) {
|
|||||||
scan_msg->range_max = max_range_;
|
scan_msg->range_max = max_range_;
|
||||||
scan_msg->ranges.resize(scan_count);
|
scan_msg->ranges.resize(scan_count);
|
||||||
scan_msg->intensities.resize(scan_count);
|
scan_msg->intensities.resize(scan_count);
|
||||||
for (size_t i = 0; i < scan_count; i++) {
|
for (size_t i = 0; i < scan_count; ++i) {
|
||||||
if (scans_data->distance < min_range_ && scans_data->distance > max_range_) {
|
if (scans_data->distance < min_range_ && scans_data->distance > max_range_) {
|
||||||
scans_data++;
|
scans_data++;
|
||||||
continue;
|
continue;
|
||||||
@@ -477,6 +477,43 @@ void OBLidarNode::publishScanToPoint(std::shared_ptr<ob::FrameSet> frame_set) {
|
|||||||
if (frame_set == nullptr) {
|
if (frame_set == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
auto lidar_frame = frame_set->getFrame(OB_FRAME_LIDAR_POINTS);
|
||||||
|
auto *scans_data = reinterpret_cast<OBLiDARScanPoint *>(lidar_frame->getData());
|
||||||
|
auto scan_count = lidar_frame->getDataSize() / sizeof(OBLiDARScanPoint);
|
||||||
|
auto point_cloud_msg = std::make_unique<sensor_msgs::msg::PointCloud2>();
|
||||||
|
sensor_msgs::PointCloud2Modifier modifier(*point_cloud_msg);
|
||||||
|
modifier.setPointCloud2Fields(4, "x", 1, sensor_msgs::msg::PointField::FLOAT32, "y", 1,
|
||||||
|
sensor_msgs::msg::PointField::FLOAT32, "z", 1,
|
||||||
|
sensor_msgs::msg::PointField::FLOAT32, "reflectivity", 1,
|
||||||
|
sensor_msgs::msg::PointField::UINT8);
|
||||||
|
modifier.resize(scan_count);
|
||||||
|
auto frame_timestamp = getFrameTimestampUs(lidar_frame);
|
||||||
|
auto timestamp = fromUsToROSTime(frame_timestamp);
|
||||||
|
point_cloud_msg->header.stamp = timestamp;
|
||||||
|
point_cloud_msg->header.frame_id = frame_id_[LIDAR];
|
||||||
|
point_cloud_msg->height = 1;
|
||||||
|
point_cloud_msg->width = scan_count;
|
||||||
|
point_cloud_msg->is_dense = true;
|
||||||
|
point_cloud_msg->is_bigendian = false;
|
||||||
|
point_cloud_msg->row_step = point_cloud_msg->width * point_cloud_msg->point_step;
|
||||||
|
point_cloud_msg->data.resize(point_cloud_msg->height * point_cloud_msg->row_step);
|
||||||
|
sensor_msgs::PointCloud2Iterator<float> iter_x(*point_cloud_msg, "x");
|
||||||
|
sensor_msgs::PointCloud2Iterator<float> iter_y(*point_cloud_msg, "y");
|
||||||
|
sensor_msgs::PointCloud2Iterator<float> iter_z(*point_cloud_msg, "z");
|
||||||
|
sensor_msgs::PointCloud2Iterator<uint8_t> iter_reflectivity(*point_cloud_msg, "reflectivity");
|
||||||
|
for (size_t i = 0; i < scan_count; ++i, ++iter_x, ++iter_y, ++iter_z, ++iter_reflectivity) {
|
||||||
|
double rad = 0.7853981852531433 + 0.0026179938577115536 * i;
|
||||||
|
*iter_x = static_cast<float>(scans_data[i].distance * cos(rad) / 1000.0);
|
||||||
|
*iter_y = static_cast<float>(scans_data[i].distance * sin(rad) / -1000.0);
|
||||||
|
*iter_z = static_cast<float>(0.0);
|
||||||
|
*iter_reflectivity = static_cast<uint8_t>(scans_data[i].intensity);
|
||||||
|
// RCLCPP_INFO_STREAM(logger_, "*iter_x:"<<*iter_x);
|
||||||
|
}
|
||||||
|
RCLCPP_INFO(logger_, "point_step: %u", point_cloud_msg->point_step);
|
||||||
|
RCLCPP_INFO(logger_, "row_step: %u", point_cloud_msg->row_step);
|
||||||
|
RCLCPP_INFO(logger_, "data size: %zu", point_cloud_msg->data.size());
|
||||||
|
*point_cloud_msg = filterPointCloud(*point_cloud_msg);
|
||||||
|
point_cloud_pub_->publish(std::move(point_cloud_msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
void OBLidarNode::publishPointCloud(std::shared_ptr<ob::FrameSet> frame_set) {
|
void OBLidarNode::publishPointCloud(std::shared_ptr<ob::FrameSet> frame_set) {
|
||||||
|
|||||||
Reference in New Issue
Block a user