Apollo 11.0
自动驾驶开放平台
util.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 "modules/planning/scenarios/pull_over/proto/pull_over.pb.h"
26
27namespace apollo {
28namespace planning {
29
31
36 const common::VehicleStateProvider* vehicle_state_provider,
37 const ReferenceLineInfo& reference_line_info,
38 const ScenarioPullOverConfig& scenario_config,
39 const PlanningContext* planning_context) {
40 const auto& pull_over_status =
41 planning_context->planning_status().pull_over();
42 if (!pull_over_status.has_position() ||
43 !pull_over_status.position().has_x() ||
44 !pull_over_status.position().has_y() || !pull_over_status.has_theta()) {
45 ADEBUG << "pull_over status not set properly: "
46 << pull_over_status.DebugString();
48 }
49
50 const auto& reference_line = reference_line_info.reference_line();
51 common::SLPoint pull_over_sl;
52 reference_line.XYToSL(pull_over_status.position(), &pull_over_sl);
53
54 const double adc_front_edge_s = reference_line_info.AdcSlBoundary().end_s();
55 double distance = adc_front_edge_s - pull_over_sl.s();
56 if (distance >= scenario_config.pass_destination_threshold()) {
57 ADEBUG << "ADC passed pull-over spot: distance[" << distance << "]";
59 }
60
61 const double adc_speed = vehicle_state_provider->linear_velocity();
62 const double max_adc_stop_speed = common::VehicleConfigHelper::Instance()
63 ->GetConfig()
64 .vehicle_param()
65 .max_abs_speed_when_stopped();
66 if (adc_speed > max_adc_stop_speed) {
67 ADEBUG << "ADC not stopped: speed[" << adc_speed << "]";
69 }
70
71 static constexpr double kStartParkCheckRange = 3.0; // meter
72 if (distance <= -kStartParkCheckRange) {
73 ADEBUG << "ADC still far: distance[" << distance << "]";
75 }
76
77 const common::math::Vec2d adc_position = {vehicle_state_provider->x(),
78 vehicle_state_provider->y()};
79 const common::math::Vec2d target_position = {pull_over_status.position().x(),
80 pull_over_status.position().y()};
81
82 const bool position_check = CheckPullOverPositionBySL(
83 reference_line_info, scenario_config, adc_position,
84 vehicle_state_provider->heading(), target_position,
85 pull_over_status.theta(), true);
86
87 return position_check ? PullOverState::PARK_COMPLETE
89}
90
95 const ReferenceLineInfo& reference_line_info,
96 const ScenarioPullOverConfig& scenario_config,
97 const common::PathPoint& path_point,
98 const PlanningContext* planning_context) {
99 const auto& pull_over_status =
100 planning_context->planning_status().pull_over();
101 if (!pull_over_status.has_position() ||
102 !pull_over_status.position().has_x() ||
103 !pull_over_status.position().has_y() || !pull_over_status.has_theta()) {
104 ADEBUG << "pull_over status not set properly: "
105 << pull_over_status.DebugString();
107 }
108
109 const common::math::Vec2d target_position = {pull_over_status.position().x(),
110 pull_over_status.position().y()};
111 const bool position_check = CheckPullOverPositionBySL(
112 reference_line_info, scenario_config, {path_point.x(), path_point.y()},
113 path_point.theta(), target_position, pull_over_status.theta(),
114 false); // check l + theta only
115
116 return position_check ? PullOverState::PARK_COMPLETE
118}
119
120bool CheckPullOverPositionBySL(const ReferenceLineInfo& reference_line_info,
121 const ScenarioPullOverConfig& scenario_config,
122 const common::math::Vec2d& adc_position,
123 const double adc_theta,
124 const common::math::Vec2d& target_position,
125 const double target_theta, const bool check_s) {
126 const auto& reference_line = reference_line_info.reference_line();
127 common::SLPoint target_sl;
128 reference_line.XYToSL(target_position, &target_sl);
129 common::SLPoint adc_position_sl;
130 reference_line.XYToSL(adc_position, &adc_position_sl);
131
132 const double s_diff = target_sl.s() - adc_position_sl.s();
133 const double l_diff = std::fabs(target_sl.l() - adc_position_sl.l());
134 const double theta_diff =
135 std::fabs(common::math::NormalizeAngle(target_theta - adc_theta));
136
137 ADEBUG << "adc_position_s[" << adc_position_sl.s() << "] adc_position_l["
138 << adc_position_sl.l() << "] target_s[" << target_sl.s()
139 << "] target_l[" << target_sl.l() << "] s_diff[" << s_diff
140 << "] l_diff[" << l_diff << "] theta_diff[" << theta_diff << "]";
141
142 // check s/l/theta diff
143 bool ret = (l_diff <= scenario_config.max_l_error_to_end_point() &&
144 theta_diff <= scenario_config.max_theta_error_to_end_point());
145 if (check_s) {
146 ret = (ret && s_diff >= 0 &&
147 s_diff <= scenario_config.max_s_error_to_end_point());
148 }
149
150 return ret;
151}
152
153} // namespace planning
154} // namespace apollo
double linear_velocity() const
Get the vehicle's linear velocity.
double x() const
Get the x-coordinate of vehicle position.
double y() const
Get the y-coordinate of vehicle position.
double heading() const
Get the heading of vehicle position, which is the angle between the vehicle's heading direction and t...
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42
double x() const
Getter for x component
Definition vec2d.h:54
const PlanningStatus & planning_status() const
ReferenceLineInfo holds all data for one reference line.
const ReferenceLine & reference_line() const
const SLBoundary & AdcSlBoundary() const
Planning module main class.
#define ADEBUG
Definition log.h:41
Some util functions.
double NormalizeAngle(const double angle)
Normalize angle to [-PI, PI).
Definition math_utils.cc:53
PullOverState CheckADCPullOver(const common::VehicleStateProvider *vehicle_state_provider, const ReferenceLineInfo &reference_line_info, const ScenarioPullOverConfig &scenario_config, const PlanningContext *planning_context)
: check adc parked properly
Definition util.cc:35
PullOverState CheckADCPullOverPathPoint(const ReferenceLineInfo &reference_line_info, const ScenarioPullOverConfig &scenario_config, const common::PathPoint &path_point, const PlanningContext *planning_context)
: check path data to see properly
Definition util.cc:94
bool CheckPullOverPositionBySL(const ReferenceLineInfo &reference_line_info, const ScenarioPullOverConfig &scenario_config, const common::math::Vec2d &adc_position, const double adc_theta, const common::math::Vec2d &target_position, const double target_theta, const bool check_s)
Definition util.cc:120
class register implement
Definition arena_queue.h:37