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
20
21namespace apollo {
22namespace planning {
23
27
29 const common::VehicleStateProvider* vehicle_state_provider, Frame* frame,
30 const apollo::planning::ScenarioParkAndGoConfig& scenario_config) {
31 auto vehicle_status = vehicle_state_provider;
32 common::math::Vec2d adc_position = {vehicle_status->x(), vehicle_status->y()};
33 const double adc_heading = vehicle_status->heading();
34
35 common::SLPoint adc_position_sl;
36 // get nearest reference line
37 const auto& reference_line_list = frame->reference_line_info();
38 const auto reference_line_info = std::min_element(
39 reference_line_list.begin(), reference_line_list.end(),
40 [&](const ReferenceLineInfo& ref_a, const ReferenceLineInfo& ref_b) {
41 common::SLPoint adc_position_sl_a;
42 common::SLPoint adc_position_sl_b;
43 ref_a.reference_line().XYToSL(adc_position, &adc_position_sl_a);
44 ref_b.reference_line().XYToSL(adc_position, &adc_position_sl_b);
45 return std::fabs(adc_position_sl_a.l()) <
46 std::fabs(adc_position_sl_b.l());
47 });
48 reference_line_info->reference_line().XYToSL(adc_position, &adc_position_sl);
49 bool is_near_front_obstacle =
50 CheckADCSurroundObstacles(adc_position, adc_heading, frame,
51 scenario_config.front_obstacle_buffer());
52 bool heading_align_w_reference_line =
53 CheckADCHeading(adc_position, adc_heading, *reference_line_info,
54 scenario_config.heading_buffer());
55 ADEBUG << "is_near_front_obstacle: " << is_near_front_obstacle;
56 ADEBUG << "heading_align_w_reference_line: "
57 << heading_align_w_reference_line;
58 // check gear status
59 // TODO(SHU): align with vehicle parameters
60 static constexpr double kMinSpeed = 0.1; // m/s
61 return ((vehicle_status->gear() == canbus::Chassis::GEAR_DRIVE ||
62 std::fabs(vehicle_status->vehicle_state().linear_velocity()) <
63 kMinSpeed) &&
64 !is_near_front_obstacle && heading_align_w_reference_line &&
65 std::fabs(adc_position_sl.l()) < 0.5);
66}
67
73 const double adc_heading, Frame* frame,
74 const double front_obstacle_buffer) {
75 const auto& vehicle_config =
76 common::VehicleConfigHelper::Instance()->GetConfig();
77 const double adc_length = vehicle_config.vehicle_param().length();
78 const double adc_width = vehicle_config.vehicle_param().width();
79 // ADC box
80 Box2d adc_box(adc_position, adc_heading, adc_length + front_obstacle_buffer,
81 adc_width);
82 double shift_distance = front_obstacle_buffer / 2 +
83 vehicle_config.vehicle_param().back_edge_to_center();
84 Vec2d shift_vec{shift_distance * std::cos(adc_heading),
85 shift_distance * std::sin(adc_heading)};
86 adc_box.Shift(shift_vec);
87 const auto& adc_polygon = Polygon2d(adc_box);
88 // obstacle boxes
89 auto obstacles = frame->obstacles();
90 for (const auto& obstacle : obstacles) {
91 if (obstacle->IsVirtual()) {
92 continue;
93 }
94 const auto& obstacle_polygon = obstacle->PerceptionPolygon();
95 const Polygon2d& nudge_polygon = obstacle_polygon.ExpandByDistance(
96 std::fabs(FLAGS_static_obstacle_nudge_l_buffer));
97 if (adc_polygon.HasOverlap(nudge_polygon)) {
98 ADEBUG << "blocked obstacle: " << obstacle->Id();
99 return true;
100 }
101 }
102 return false;
103}
104
109bool CheckADCHeading(const common::math::Vec2d adc_position,
110 const double adc_heading,
111 const ReferenceLineInfo& reference_line_info,
112 const double heading_diff_to_reference_line) {
113 const double kReducedHeadingBuffer = 0.2; // (rad) TODO(Shu) move to config
114 const auto& reference_line = reference_line_info.reference_line();
115 common::SLPoint adc_position_sl;
116 reference_line.XYToSL(adc_position, &adc_position_sl);
117 // reference line heading angle at s
118 const auto reference_point =
119 reference_line.GetReferencePoint(adc_position_sl.s());
120 const auto path_point = reference_point.ToPathPoint(adc_position_sl.s());
121 AINFO << "heading difference: "
122 << common::math::NormalizeAngle(adc_heading - path_point.theta());
123 double angle_difference =
124 common::math::NormalizeAngle(adc_heading - path_point.theta());
125 if (angle_difference >
126 -1.0 * (heading_diff_to_reference_line - kReducedHeadingBuffer) &&
127 angle_difference < heading_diff_to_reference_line) {
128 return true;
129 }
130 return false;
131}
132
133} // namespace planning
134} // namespace apollo
Rectangular (undirected) bounding box in 2-D.
Definition box2d.h:52
void Shift(const Vec2d &shift_vec)
Shifts this box by a given vector
Definition box2d.cc:393
The class of polygon in 2-D.
Definition polygon2d.h:42
Polygon2d ExpandByDistance(const double distance) const
Expand this polygon by a distance.
Definition polygon2d.cc:604
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42
double x() const
Getter for x component
Definition vec2d.h:54
Frame holds all data for one planning cycle.
Definition frame.h:62
const std::vector< const Obstacle * > obstacles() const
Definition frame.cc:577
const std::list< ReferenceLineInfo > & reference_line_info() const
Definition frame.cc:123
ReferenceLineInfo holds all data for one reference line.
const ReferenceLine & reference_line() const
Planning module main class.
#define ADEBUG
Definition log.h:41
#define AINFO
Definition log.h:42
double NormalizeAngle(const double angle)
Normalize angle to [-PI, PI).
Definition math_utils.cc:53
bool CheckADCSurroundObstacles(const common::math::Vec2d adc_position, const double adc_heading, Frame *frame, const double front_obstacle_buffer)
: front obstacle is far enough before PardAndGo cruise stage (adc_position: center of rear wheel)
Definition util.cc:72
bool CheckADCReadyToCruise(const common::VehicleStateProvider *vehicle_state_provider, Frame *frame, const apollo::planning::ScenarioParkAndGoConfig &scenario_config)
Definition util.cc:28
bool CheckADCHeading(const common::math::Vec2d adc_position, const double adc_heading, const ReferenceLineInfo &reference_line_info, const double heading_diff_to_reference_line)
Park_and_go: heading angle should be close to reference line before PardAndGo cruise stage
Definition util.cc:109
class register implement
Definition arena_queue.h:37