Apollo 10.0
自动驾驶开放平台
cost_evaluator.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 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
19
20namespace apollo {
21namespace prediction {
22
26
28 ObstaclesContainer* obstacles_container) {
29 CHECK_NOTNULL(obstacle_ptr);
30
31 obstacle_ptr->SetEvaluatorType(evaluator_type_);
32
33 int id = obstacle_ptr->id();
34 if (!obstacle_ptr->latest_feature().IsInitialized()) {
35 AERROR << "Obstacle [" << id << "] has no latest feature.";
36 return false;
37 }
38
39 Feature* latest_feature_ptr = obstacle_ptr->mutable_latest_feature();
40 CHECK_NOTNULL(latest_feature_ptr);
41 if (!latest_feature_ptr->has_lane() ||
42 !latest_feature_ptr->lane().has_lane_graph()) {
43 ADEBUG << "Obstacle [" << id << "] has no lane graph.";
44 return false;
45 }
46
47 double obstacle_length = 0.0;
48 if (latest_feature_ptr->has_length()) {
49 obstacle_length = latest_feature_ptr->length();
50 }
51 double obstacle_width = 0.0;
52 if (latest_feature_ptr->has_width()) {
53 obstacle_width = latest_feature_ptr->width();
54 }
55
56 LaneGraph* lane_graph_ptr =
57 latest_feature_ptr->mutable_lane()->mutable_lane_graph();
58 CHECK_NOTNULL(lane_graph_ptr);
59 if (lane_graph_ptr->lane_sequence().empty()) {
60 AERROR << "Obstacle [" << id << "] has no lane sequences.";
61 return false;
62 }
63
64 for (int i = 0; i < lane_graph_ptr->lane_sequence_size(); ++i) {
65 LaneSequence* lane_sequence_ptr = lane_graph_ptr->mutable_lane_sequence(i);
66 CHECK_NOTNULL(lane_sequence_ptr);
67 double probability =
68 ComputeProbability(obstacle_length, obstacle_width, *lane_sequence_ptr);
69 lane_sequence_ptr->set_probability(probability);
70 }
71 return true;
72}
73
74double CostEvaluator::ComputeProbability(const double obstacle_length,
75 const double obstacle_width,
76 const LaneSequence& lane_sequence) {
77 double front_lateral_distance_cost =
78 FrontLateralDistanceCost(obstacle_length, obstacle_width, lane_sequence);
79 return apollo::common::math::Sigmoid(front_lateral_distance_cost);
80}
81
82double CostEvaluator::FrontLateralDistanceCost(
83 const double obstacle_length, const double obstacle_width,
84 const LaneSequence& lane_sequence) {
85 if (lane_sequence.lane_segment().empty() ||
86 lane_sequence.lane_segment(0).lane_point().empty()) {
87 AWARN << "Empty lane sequence.";
88 return 0.0;
89 }
90 const LanePoint& lane_point = lane_sequence.lane_segment(0).lane_point(0);
91 double lane_l = -lane_point.relative_l();
92 double distance = std::abs(lane_l - obstacle_length / 2.0 *
93 std::sin(lane_point.angle_diff()));
94 double half_lane_width = lane_point.width() / 2.0;
95 return half_lane_width - distance;
96}
97
98} // namespace prediction
99} // namespace apollo
bool Evaluate(Obstacle *obstacle_ptr, ObstaclesContainer *obstacles_container) override
Override Evaluate
ObstacleConf::EvaluatorType evaluator_type_
Definition evaluator.h:156
Prediction obstacle.
Definition obstacle.h:52
Feature * mutable_latest_feature()
Get a pointer to the latest feature.
Definition obstacle.cc:88
int id() const
Get the obstacle's ID.
Definition obstacle.cc:60
void SetEvaluatorType(const ObstacleConf::EvaluatorType &evaluator_type)
Definition obstacle.cc:1484
const Feature & latest_feature() const
Get the latest feature.
Definition obstacle.cc:78
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
#define AWARN
Definition log.h:43
double Sigmoid(const double x)
Definition math_utils.h:171
class register implement
Definition arena_queue.h:37
repeated LaneSequence lane_sequence