Apollo 11.0
自动驾驶开放平台
evaluator.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2020 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 <limits>
20#include <vector>
21
22#include "cyber/common/file.h"
26
27DEFINE_double(trajectory_delta_t, 0.2,
28 "delta time(sec) between trajectory points");
29
30namespace apollo {
31namespace planning {
32
34 start_time_ = std::chrono::system_clock::now();
35 std::time_t now = std::time(nullptr);
37 << "UTC date and time: " << std::asctime(std::gmtime(&now))
38 << "Local date and time: " << std::asctime(std::localtime(&now));
39}
40
42 auto end_time = std::chrono::system_clock::now();
43 std::chrono::duration<double> elapsed_seconds = end_time - start_time_;
45 << "Time elapsed(sec): " << elapsed_seconds.count() << std::endl
46 << std::endl;
47}
48
49void Evaluator::Evaluate(const std::string& source_file) {
50 EvaluatorLogger::GetStream() << "Processing: " << source_file << std::endl;
51
52 const std::string& source_filename =
53 source_file.substr(source_file.find_last_of("/") + 1);
54
55 cyber::common::GetProtoFromFile(source_file, &learning_data_);
56
57 for (int i = 0; i < learning_data_.learning_data_frame_size(); ++i) {
58 auto learning_data_frame = learning_data_.mutable_learning_data_frame(i);
59 if (learning_data_frame->adc_trajectory_point_size() <= 0) {
60 continue;
61 }
62 const double start_point_timestamp_sec =
63 learning_data_frame
64 ->adc_trajectory_point(
65 learning_data_frame->adc_trajectory_point_size() - 1)
66 .timestamp_sec();
67
68 // evaluate adc trajectory
69 trajectory_evaluator_.EvaluateADCTrajectory(start_point_timestamp_sec,
70 FLAGS_trajectory_delta_t,
71 learning_data_frame);
72
73 // evaluate adc future trajectory
74 std::vector<TrajectoryPointFeature> adc_future_trajectory;
75 for (const auto& tp : learning_data_.learning_data_frame(i)
76 .output()
78 adc_future_trajectory.push_back(tp);
79 }
80 std::vector<TrajectoryPointFeature> evaluated_adc_future_trajectory;
81 trajectory_evaluator_.EvaluateADCFutureTrajectory(
82 learning_data_.learning_data_frame(i).frame_num(),
83 adc_future_trajectory, start_point_timestamp_sec,
84 FLAGS_trajectory_delta_t, &evaluated_adc_future_trajectory);
85 learning_data_frame->mutable_output()->clear_adc_future_trajectory_point();
86 for (const auto& tp : evaluated_adc_future_trajectory) {
87 auto adc_future_trajectory_point =
88 learning_data_frame->mutable_output()
89 ->add_adc_future_trajectory_point();
90 adc_future_trajectory_point->set_timestamp_sec(tp.timestamp_sec());
91 adc_future_trajectory_point->mutable_trajectory_point()->CopyFrom(
92 tp.trajectory_point());
93 }
94
95 // evaluate obstacle trajectory
96 trajectory_evaluator_.EvaluateObstacleTrajectory(start_point_timestamp_sec,
97 FLAGS_trajectory_delta_t,
98 learning_data_frame);
99
100 // evaluate obstacle prediction trajectory
101 trajectory_evaluator_.EvaluateObstaclePredictionTrajectory(
102 start_point_timestamp_sec, FLAGS_trajectory_delta_t,
103 learning_data_frame);
104 }
105
106 WriteOutData(source_filename, learning_data_);
107}
108
109void Evaluator::WriteOutData(const std::string& source_filename,
110 const LearningData& learning_data) {
111 const std::string file = FLAGS_planning_data_dir + "/" + source_filename;
112 cyber::common::SetProtoToBinaryFile(learning_data, file);
113 // cyber::common::SetProtoToASCIIFile(learning_data, file + ".txt");
114 learning_data_.Clear();
115}
116
117} // namespace planning
118} // namespace apollo
static std::ofstream & GetStream()
void Evaluate(const std::string &source_file)
Definition evaluator.cc:49
void EvaluateADCFutureTrajectory(const int frame_num, const std::vector< TrajectoryPointFeature > &adc_future_trajectory, const double start_point_timestamp_sec, const double delta_time, std::vector< TrajectoryPointFeature > *evaluated_adc_future_trajectory)
void EvaluateADCTrajectory(const double start_point_timestamp_sec, const double delta_time, LearningDataFrame *learning_data_frame)
void EvaluateObstacleTrajectory(const double start_point_timestamp_sec, const double delta_time, LearningDataFrame *learning_data_frame)
void EvaluateObstaclePredictionTrajectory(const double start_point_timestamp_sec, const double delta_time, LearningDataFrame *learning_data_frame)
Planning module main class.
DEFINE_double(trajectory_delta_t, 0.2, "delta time(sec) between trajectory points")
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
Definition file.cc:132
bool SetProtoToBinaryFile(const google::protobuf::Message &message, const std::string &file_name)
Sets the content of the file specified by the file_name to be the binary representation of the input ...
Definition file.cc:111
class register implement
Definition arena_queue.h:37
repeated LearningDataFrame learning_data_frame
repeated TrajectoryPointFeature adc_future_trajectory_point