33 buffer_ptr_ = apollo::transform::Buffer::Instance();
39 readers_.emplace_back(reader);
45 const std::shared_ptr<PointCloud>& point_cloud) {
46 auto target = std::make_shared<PointCloud>(*point_cloud);
47 auto fusion_readers = readers_;
50 fusion_readers.size() > 0) {
51 for (
auto itr = fusion_readers.begin(); itr != fusion_readers.end();) {
53 if (!(*itr)->Empty()) {
54 auto source = (*itr)->GetLatestObserved();
58 Fusion(target, source);
59 itr = fusion_readers.erase(itr);
65 std::this_thread::sleep_for(std::chrono::milliseconds(5));
68 AINFO <<
"Pointcloud fusion diff: " << diff / 1000000 <<
"ms";
69 fusion_writer_->Write(target);
74bool PriSecFusionComponent::IsExpired(
75 const std::shared_ptr<PointCloud>& target,
76 const std::shared_ptr<PointCloud>& source) {
77 auto diff = target->measurement_time() - source->measurement_time();
81bool PriSecFusionComponent::QueryPoseAffine(
const std::string& target_frame_id,
82 const std::string& source_frame_id,
83 Eigen::Affine3d* pose) {
84 std::string err_string;
85 if (!buffer_ptr_->
canTransform(target_frame_id, source_frame_id,
87 AERROR <<
"Can not find transform. "
88 <<
"target_id:" << target_frame_id <<
" frame_id:" << source_frame_id
89 <<
" Error info: " << err_string;
96 }
catch (tf2::TransformException& ex) {
111void PriSecFusionComponent::AppendPointCloud(
112 std::shared_ptr<PointCloud> point_cloud,
113 std::shared_ptr<PointCloud> point_cloud_add,
const Eigen::Affine3d& pose) {
114 if (std::isnan(pose(0, 0))) {
115 for (
auto& point : point_cloud_add->point()) {
116 PointXYZIT* point_new = point_cloud->add_point();
117 point_new->set_intensity(point.intensity());
118 point_new->set_timestamp(point.timestamp());
119 point_new->set_x(point.x());
120 point_new->set_y(point.y());
121 point_new->set_z(point.z());
124 for (
auto& point : point_cloud_add->point()) {
125 if (std::isnan(point.x())) {
126 PointXYZIT* point_new = point_cloud->add_point();
127 point_new->set_intensity(point.intensity());
128 point_new->set_timestamp(point.timestamp());
129 point_new->set_x(point.x());
130 point_new->set_y(point.y());
131 point_new->set_z(point.z());
133 PointXYZIT* point_new = point_cloud->add_point();
134 point_new->set_intensity(point.intensity());
135 point_new->set_timestamp(point.timestamp());
136 Eigen::Matrix<float, 3, 1> pt(point.x(), point.y(), point.z());
137 point_new->set_x(
static_cast<float>(
138 pose(0, 0) * pt.coeffRef(0) + pose(0, 1) * pt.coeffRef(1) +
139 pose(0, 2) * pt.coeffRef(2) + pose(0, 3)));
140 point_new->set_y(
static_cast<float>(
141 pose(1, 0) * pt.coeffRef(0) + pose(1, 1) * pt.coeffRef(1) +
142 pose(1, 2) * pt.coeffRef(2) + pose(1, 3)));
143 point_new->set_z(
static_cast<float>(
144 pose(2, 0) * pt.coeffRef(0) + pose(2, 1) * pt.coeffRef(1) +
145 pose(2, 2) * pt.coeffRef(2) + pose(2, 3)));
150 int new_width = point_cloud->point_size() / point_cloud->height();
151 point_cloud->set_width(new_width);
154bool PriSecFusionComponent::Fusion(std::shared_ptr<PointCloud> target,
155 std::shared_ptr<PointCloud> source) {
156 Eigen::Affine3d pose;
157 if (QueryPoseAffine(target->header().frame_id(), source->header().frame_id(),
159 AppendPointCloud(target, source, pose);
bool GetProtoConfig(T *config) const
const std::string & ConfigFilePath() const
std::shared_ptr< Node > node_
Cyber has builtin time type Time.
uint64_t ToNanosecond() const
convert time to nanosecond.
static Time Now()
get the current time.
double ToSecond() const
convert time to second.
bool Proc(const std::shared_ptr< PointCloud > &point_cloud) override
optional bool drop_expired_data
repeated string input_channel
optional uint32 max_interval_ms
optional string fusion_channel
optional float wait_time_s