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"
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 return true;
42}
43
45 const std::shared_ptr<PointCloud>& point_cloud) {
46 const auto start_time = Time::Now();
47 std::shared_ptr<PointCloud> point_cloud_compensated =
48 writer_->AcquireMessage();
49 if (point_cloud_compensated == nullptr) {
50 AWARN << "compensator fail to getobject, will be new";
51 point_cloud_compensated = std::make_shared<PointCloud>();
52 point_cloud_compensated->mutable_point()->Reserve(140000);
53 }
54 if (point_cloud_compensated == nullptr) {
55 AWARN << "compensator point_cloud is nullptr";
56 return false;
57 }
58 point_cloud_compensated->Clear();
59 if (compensator_->MotionCompensation(point_cloud, point_cloud_compensated)) {
60 const auto end_time = Time::Now();
61 const auto diff = end_time - start_time;
62 const auto meta_diff =
63 end_time - Time(point_cloud_compensated->header().lidar_timestamp());
64 AINFO << "compenstator diff (ms):" << (diff.ToNanosecond() / 1e6)
65 << ";meta (ns):"
66 << point_cloud_compensated->header().lidar_timestamp()
67 << ";meta diff (ms): " << (meta_diff.ToNanosecond() / 1e6);
68 static common::LatencyRecorder latency_recorder(FLAGS_pointcloud_topic);
69 latency_recorder.AppendLatencyRecord(
70 point_cloud_compensated->header().lidar_timestamp(), start_time,
71 end_time);
72
73 point_cloud_compensated->mutable_header()->set_sequence_num(seq_);
74 writer_->Write(point_cloud_compensated);
75 seq_++;
76 }
77
78 return true;
79}
80
81} // namespace compensator
82} // namespace drivers
83} // 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 AINFO
Definition log.h:42
#define AWARN
Definition log.h:43
class register implement
Definition arena_queue.h:37