Apollo 11.0
自动驾驶开放平台
predictor_submodule.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2019 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 *****************************************************************************/
16
18
19#include "cyber/time/time.h"
20
21#include "cyber/time/clock.h"
23#include "modules/common/adapters/proto/adapter_config.pb.h"
26
27namespace apollo {
28namespace prediction {
29
32
33std::string PredictorSubmodule::Name() const {
34 return FLAGS_evaluator_submodule_name;
35}
36
38 predictor_manager_.reset(new PredictorManager());
39
40 PredictionConf prediction_conf;
41 if (!ComponentBase::GetProtoConfig(&prediction_conf)) {
42 AERROR << "Unable to load prediction conf file: "
43 << ComponentBase::ConfigFilePath();
44 return false;
45 }
46 ADEBUG << "Prediction config file is loaded into: "
47 << prediction_conf.ShortDebugString();
48 if (!MessageProcess::InitPredictors(predictor_manager_.get(),
49 prediction_conf)) {
50 return false;
51 }
52 predictor_writer_ = node_->CreateWriter<PredictionObstacles>(
53 prediction_conf.topic_conf().prediction_topic());
54 return true;
55}
56
58 const std::shared_ptr<PerceptionObstacles>& perception_obstacles,
59 const std::shared_ptr<ADCTrajectoryContainer>& adc_trajectory_container,
60 const std::shared_ptr<SubmoduleOutput>& submodule_output) {
61 const apollo::common::Header& perception_header =
62 perception_obstacles->header();
63 const apollo::common::ErrorCode& perception_error_code =
64 perception_obstacles->error_code();
65 const apollo::cyber::Time& frame_start_time =
66 submodule_output->frame_start_time();
67 ObstaclesContainer obstacles_container(*submodule_output);
68 predictor_manager_->Run(*perception_obstacles, adc_trajectory_container.get(),
69 &obstacles_container);
70 PredictionObstacles prediction_obstacles =
71 predictor_manager_->prediction_obstacles();
72
73 prediction_obstacles.set_end_timestamp(Clock::NowInSeconds());
74 prediction_obstacles.mutable_header()->set_lidar_timestamp(
75 perception_header.lidar_timestamp());
76 prediction_obstacles.mutable_header()->set_camera_timestamp(
77 perception_header.camera_timestamp());
78 prediction_obstacles.mutable_header()->set_radar_timestamp(
79 perception_header.radar_timestamp());
80 prediction_obstacles.set_perception_error_code(perception_error_code);
81
82 common::util::FillHeader(node_->Name(), &prediction_obstacles);
83 predictor_writer_->Write(prediction_obstacles);
84
85 const apollo::cyber::Time& end_time = Clock::Now();
86 ADEBUG << "End to end time = "
87 << (end_time - frame_start_time).ToSecond() * 1000 << " ms";
88
89 return true;
90}
91
92} // namespace prediction
93} // namespace apollo
a singleton clock that can be used to get the current timestamp.
Definition clock.h:39
static double NowInSeconds()
gets the current time in second.
Definition clock.cc:56
static Time Now()
PRECISION >= 1000000 means the precision is at least 1us.
Definition clock.cc:40
std::shared_ptr< Node > node_
Cyber has builtin time type Time.
Definition time.h:31
static bool InitPredictors(PredictorManager *predictor_manager, const PredictionConf &prediction_conf)
bool Init() override
Initialize the node
bool Proc(const std::shared_ptr< apollo::perception::PerceptionObstacles > &, const std::shared_ptr< ADCTrajectoryContainer > &, const std::shared_ptr< SubmoduleOutput > &) override
Data callback upon receiving a prediction evaluator output.
std::string Name() const
Get name of the node
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
Some string util functions.
class register implement
Definition arena_queue.h:37
Use predictor submodule to manage all predictors
optional uint64 camera_timestamp
Definition header.proto:22
optional uint64 lidar_timestamp
Definition header.proto:19
optional uint64 radar_timestamp
Definition header.proto:25