Apollo 11.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"
23// #include "modules/drivers/lidar/proto/velodyne.pb.h"
24#include "modules/drivers/lidar/compensator/proto/compensator_config.pb.h"
25
27
28namespace apollo {
29namespace drivers {
30namespace compensator {
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(
70 point_cloud, point_cloud_compensated)) {
71 const auto end_time = Time::Now();
72 const auto diff = end_time - start_time;
73 const auto meta_diff = end_time
74 - Time(point_cloud_compensated->header().lidar_timestamp());
75 AINFO << "compenstator diff (ms):" << (diff.ToNanosecond() / 1e6)
76 << ";meta (ns):"
77 << point_cloud_compensated->header().lidar_timestamp()
78 << ";meta diff (ms): " << (meta_diff.ToNanosecond() / 1e6);
79 static common::LatencyRecorder latency_recorder(FLAGS_pointcloud_topic);
80 latency_recorder.AppendLatencyRecord(
81 point_cloud_compensated->header().lidar_timestamp(),
82 start_time,
83 end_time);
84
85 point_cloud_compensated->mutable_header()->set_sequence_num(seq_);
86 writer_->Write(point_cloud_compensated);
87 seq_++;
88 }
89
90 return true;
91}
92
93} // namespace compensator
94} // namespace drivers
95} // 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