Apollo 10.0
自动驾驶开放平台
evaluator.h
浏览该文件的文档.
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 *****************************************************************************/
16
22#pragma once
23
24#include <string>
25#include <utility>
26#include <vector>
27
29
32
37namespace apollo {
38namespace prediction {
39
40class Evaluator {
41 public:
45 Evaluator() = default;
46
50 virtual ~Evaluator() = default;
51
52 // TODO(all): Need to merge the following two functions into a single one.
53 // Can try using proto to pass static/dynamic env info.
54
60 virtual bool Evaluate(Obstacle* obstacle,
61 ObstaclesContainer* obstacles_container) = 0;
62
69 virtual bool Evaluate(Obstacle* obstacle,
70 ObstaclesContainer* obstacles_container,
71 std::vector<Obstacle*> dynamic_env) {
72 return Evaluate(obstacle, obstacles_container);
73 }
74
81 virtual bool Evaluate(const ADCTrajectoryContainer* adc_trajectory_container,
82 Obstacle* obstacle,
83 ObstaclesContainer* obstacles_container) {
84 return Evaluate(obstacle, obstacles_container);
85 }
89 virtual std::string GetName() = 0;
90
91 protected:
92 // Helper function to convert world coordinates to relative coordinates
93 // around the obstacle of interest.
94 std::pair<double, double> WorldCoordToObjCoord(
95 std::pair<double, double> input_world_coord,
96 std::pair<double, double> obj_world_coord, double obj_world_angle) {
97 double x_diff = input_world_coord.first - obj_world_coord.first;
98 double y_diff = input_world_coord.second - obj_world_coord.second;
99 double rho = std::sqrt(x_diff * x_diff + y_diff * y_diff);
100 double theta = std::atan2(y_diff, x_diff) - obj_world_angle;
101
102 return std::make_pair(std::cos(theta) * rho, std::sin(theta) * rho);
103 }
104
105 std::pair<double, double> WorldCoordToObjCoordNorth(
106 std::pair<double, double> input_world_coord,
107 std::pair<double, double> obj_world_coord, double obj_world_angle) {
108 double x_diff = input_world_coord.first - obj_world_coord.first;
109 double y_diff = input_world_coord.second - obj_world_coord.second;
110 double theta = M_PI / 2 - obj_world_angle;
111 double x = std::cos(theta) * x_diff - std::sin(theta) * y_diff;
112 double y = std::sin(theta) * x_diff + std::cos(theta) * y_diff;
113 return std::make_pair(x, y);
114 }
115
116 double WorldAngleToObjAngle(double input_world_angle,
117 double obj_world_angle) {
118 return common::math::NormalizeAngle(input_world_angle - obj_world_angle);
119 }
120
121 Eigen::MatrixXf VectorToMatrixXf(const std::vector<double>& nums,
122 const int start_index, const int end_index) {
123 CHECK_LT(start_index, end_index);
124 CHECK_GE(start_index, 0);
125 CHECK_LE(end_index, static_cast<int>(nums.size()));
126 Eigen::MatrixXf output_matrix;
127 output_matrix.resize(1, end_index - start_index);
128 for (int i = start_index; i < end_index; ++i) {
129 output_matrix(0, i - start_index) = static_cast<float>(nums[i]);
130 }
131 return output_matrix;
132 }
133
134 Eigen::MatrixXf VectorToMatrixXf(const std::vector<double>& nums,
135 const int start_index, const int end_index,
136 const int output_num_row,
137 const int output_num_col) {
138 CHECK_LT(start_index, end_index);
139 CHECK_GE(start_index, 0);
140 CHECK_LE(end_index, static_cast<int>(nums.size()));
141 CHECK_EQ(end_index - start_index, output_num_row * output_num_col);
142 Eigen::MatrixXf output_matrix;
143 output_matrix.resize(output_num_row, output_num_col);
144 int input_index = start_index;
145 for (int i = 0; i < output_num_row; ++i) {
146 for (int j = 0; j < output_num_col; ++j) {
147 output_matrix(i, j) = static_cast<float>(nums[input_index]);
148 ++input_index;
149 }
150 }
151 CHECK_EQ(input_index, end_index);
152 return output_matrix;
153 }
154
155 protected:
157};
158
159} // namespace prediction
160} // namespace apollo
ADC trajectory container
double WorldAngleToObjAngle(double input_world_angle, double obj_world_angle)
Definition evaluator.h:116
virtual bool Evaluate(Obstacle *obstacle, ObstaclesContainer *obstacles_container, std::vector< Obstacle * > dynamic_env)
Evaluate an obstacle
Definition evaluator.h:69
virtual bool Evaluate(Obstacle *obstacle, ObstaclesContainer *obstacles_container)=0
Evaluate an obstacle
Eigen::MatrixXf VectorToMatrixXf(const std::vector< double > &nums, const int start_index, const int end_index)
Definition evaluator.h:121
virtual bool Evaluate(const ADCTrajectoryContainer *adc_trajectory_container, Obstacle *obstacle, ObstaclesContainer *obstacles_container)
Evaluate an obstacle
Definition evaluator.h:81
Eigen::MatrixXf VectorToMatrixXf(const std::vector< double > &nums, const int start_index, const int end_index, const int output_num_row, const int output_num_col)
Definition evaluator.h:134
std::pair< double, double > WorldCoordToObjCoord(std::pair< double, double > input_world_coord, std::pair< double, double > obj_world_coord, double obj_world_angle)
Definition evaluator.h:94
Evaluator()=default
Constructor
ObstacleConf::EvaluatorType evaluator_type_
Definition evaluator.h:156
std::pair< double, double > WorldCoordToObjCoordNorth(std::pair< double, double > input_world_coord, std::pair< double, double > obj_world_coord, double obj_world_angle)
Definition evaluator.h:105
virtual ~Evaluator()=default
Destructor
virtual std::string GetName()=0
Get the name of evaluator
Prediction obstacle.
Definition obstacle.h:52
double NormalizeAngle(const double angle)
Normalize angle to [-PI, PI).
Definition math_utils.cc:53
class register implement
Definition arena_queue.h:37
Obstacles container
Obstacle