16#ifndef APOLLO_LIDAR_COMPONENT_BASE_IMPL_H
17#define APOLLO_LIDAR_COMPONENT_BASE_IMPL_H
22#include "modules/common_msgs/sensor_msgs/pointcloud.pb.h"
23#include "modules/drivers/lidar/common/proto/lidar_config_base.pb.h"
32template <
typename ScanType,
typename ComponentType = apollo::cyber::NullType>
49 virtual bool WriteScan(
const std::shared_ptr<ScanType>& scan_message);
54 const std::shared_ptr<PointCloud>& point_cloud);
60 std::shared_ptr<PointCloud>& unused_pcd_frame);
65 std::shared_ptr<cyber::Writer<ScanType>> scan_writer_ =
nullptr;
66 std::shared_ptr<cyber::Reader<ScanType>> scan_reader_ =
nullptr;
67 std::shared_ptr<cyber::Writer<PointCloud>> pcd_writer_ =
nullptr;
68 std::shared_ptr<SyncBuffering<PointCloud>> pcd_buffer_ =
nullptr;
70 std::atomic<int> pcd_sequence_num_{0};
73template <
typename ScanType,
typename ComponentType>
76 pcd_writer_ = this->node_->template CreateWriter<PointCloud>(
81 == LidarConfigBase_SourceType_RAW_PACKET) {
82 scan_reader_ = this->node_->template CreateReader<ScanType>(
87 std::placeholders::_1));
91 frame_id_ = lidar_config_base.
frame_id();
93 pcd_buffer_ = std::make_shared<SyncBuffering<PointCloud>>(
99 pcd_buffer_->SetBufferSize(lidar_config_base.
buffer_size());
104template <
typename ScanType,
typename ComponentType>
108 == LidarConfigBase_SourceType_ONLINE_LIDAR) {
109 scan_writer_ = this->node_->template CreateWriter<ScanType>(
116template <
typename ScanType,
typename ComponentType>
118 ScanType, ComponentType>::AcquireScanMessage() {
119 if (scan_writer_ ==
nullptr) {
120 return std::make_shared<ScanType>();
122 return scan_writer_->AcquireMessage();
125template <
typename ScanType,
typename ComponentType>
127 const std::shared_ptr<ScanType>& scan_message) {
128 return scan_writer_->Write(scan_message);
131template <
typename ScanType,
typename ComponentType>
132std::shared_ptr<PointCloud>
134 return pcd_buffer_->AllocateElement();
137template <
typename ScanType,
typename ComponentType>
139 const std::shared_ptr<PointCloud>& point_cloud) {
140 point_cloud->mutable_header()->set_frame_id(frame_id_);
141 point_cloud->mutable_header()->set_sequence_num(
142 pcd_sequence_num_.fetch_add(1));
143 point_cloud->mutable_header()->set_timestamp_sec(
149template <
typename ScanType,
typename ComponentType>
150std::shared_ptr<PointCloud>
153 constexpr int default_point_cloud_reserve = 170000;
154 std::shared_ptr<PointCloud> new_pcd_object = pcd_writer->AcquireMessage();
155 new_pcd_object->mutable_point()->Reserve(default_point_cloud_reserve);
156 AINFO <<
"new pcd frame memory allocated, reserve point size = "
157 << default_point_cloud_reserve;
158 return new_pcd_object;
161template <
typename ScanType,
typename ComponentType>
163 std::shared_ptr<PointCloud>& unused_pcd_frame) {
164 unused_pcd_frame->clear_point();
Cyber has builtin time type Time.
virtual bool WritePointCloud(const std::shared_ptr< PointCloud > &point_cloud)
bool InitConverter(const LidarConfigBase &lidar_config_base)
virtual ~LidarComponentBaseImpl()=default
bool InitPacket(const LidarConfigBase &lidar_config_base)
virtual bool WriteScan(const std::shared_ptr< ScanType > &scan_message)
std::shared_ptr< ScanType > AcquireScanMessage()
static void PcdDefaultCleaner(std::shared_ptr< PointCloud > &unused_pcd_frame)
static std::shared_ptr< PointCloud > PcdDefaultAllocator(std::shared_ptr< cyber::Writer< PointCloud > > &pcd_writer)
virtual std::shared_ptr< PointCloud > AllocatePointCloud()
virtual bool InitBase(const LidarConfigBase &lidar_config_base)=0
virtual void ReadScanCallback(const std::shared_ptr< ScanType > &scan_message)=0
#define RETURN_VAL_IF(condition, val)
optional int32 buffer_size
required string scan_channel
required string point_cloud_channel
required SourceType source_type