Apollo 10.0
自动驾驶开放平台
compensator_component.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
17
18#include <memory>
19
20#include "cyber/time/time.h"
21
24#include "modules/drivers/lidar/proto/velodyne.pb.h"
25
27
28namespace apollo {
29namespace drivers {
30namespace velodyne {
31
33 CompensatorConfig config;
34 if (!GetProtoConfig(&config)) {
35 AWARN << "Load config failed, config file" << ConfigFilePath();
36 return false;
37 }
38
39 writer_ = node_->CreateWriter<PointCloud>(config.output_channel());
40 compensator_.reset(new Compensator(config));
41 compensator_pool_.reset(new CCObjectPool<PointCloud>(pool_size_));
42 compensator_pool_->ConstructAll();
43 for (int i = 0; i < pool_size_; ++i) {
44 auto point_cloud = compensator_pool_->GetObject();
45 if (point_cloud == nullptr) {
46 AERROR << "fail to getobject:" << i;
47 return false;
48 }
49 point_cloud->mutable_point()->Reserve(140000);
50 }
51 return true;
52}
53
55 const std::shared_ptr<PointCloud>& point_cloud) {
56 const auto start_time = Time::Now();
57 std::shared_ptr<PointCloud> point_cloud_compensated =
58 compensator_pool_->GetObject();
59 if (point_cloud_compensated == nullptr) {
60 AWARN << "compensator fail to getobject, will be new";
61 point_cloud_compensated = std::make_shared<PointCloud>();
62 point_cloud_compensated->mutable_point()->Reserve(140000);
63 }
64 if (point_cloud_compensated == nullptr) {
65 AWARN << "compensator point_cloud is nullptr";
66 return false;
67 }
68 point_cloud_compensated->Clear();
69 if (compensator_->MotionCompensation(point_cloud, point_cloud_compensated)) {
70 const auto end_time = Time::Now();
71 const auto diff = end_time - start_time;
72 const auto meta_diff =
73 end_time - Time(point_cloud_compensated->header().lidar_timestamp());
74 AINFO << "compenstator diff (ms):" << (diff.ToNanosecond() / 1e6)
75 << ";meta (ns):"
76 << point_cloud_compensated->header().lidar_timestamp()
77 << ";meta diff (ms): " << (meta_diff.ToNanosecond() / 1e6);
78 static common::LatencyRecorder latency_recorder(FLAGS_pointcloud_topic);
79 latency_recorder.AppendLatencyRecord(
80 point_cloud_compensated->header().lidar_timestamp(), start_time,
81 end_time);
82
83 point_cloud_compensated->mutable_header()->set_sequence_num(seq_);
84 writer_->Write(point_cloud_compensated);
85 seq_++;
86 }
87
88 return true;
89}
90
91} // namespace velodyne
92} // namespace drivers
93} // namespace apollo
void AppendLatencyRecord(const uint64_t message_id, const apollo::cyber::Time &begin_time, const apollo::cyber::Time &end_time)
bool GetProtoConfig(T *config) const
const std::string & ConfigFilePath() const
std::shared_ptr< Node > node_
Cyber has builtin time type Time.
Definition time.h:31
static Time Now()
get the current time.
Definition time.cc:57
bool Proc(const std::shared_ptr< PointCloud > &point_cloud) override
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
#define AWARN
Definition log.h:43
class register implement
Definition arena_queue.h:37