Apollo 11.0
自动驾驶开放平台
reverse_speed.cc
浏览该文件的文档.
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
21#include <algorithm>
22#include <memory>
23#include <vector>
26
31
32namespace apollo {
33namespace planning {
34
42
43bool ReverseSpeed::Init(const std::string &config_dir, const std::string &name,
44 const std::shared_ptr<DependencyInjector> &injector) {
45 if (!Task::Init(config_dir, name, injector)) {
46 return false;
47 }
48 // Load the config this task.
49 return Task::LoadConfig<ReverseSpeedConfig>(&config_);
50}
51
53 ReferenceLineInfo *reference_line_info) {
54 Task::Execute(frame, reference_line_info);
55 std::vector<const STBoundary *> boundaries;
56 const TrajectoryPoint init_point = frame->PlanningStartPoint();
57 const auto &path_data = reference_line_info->path_data();
58 GetSTboundaries(path_data.discretized_path(), frame, &boundaries);
59 SpeedLimit speed_limit;
60 speed_limit.AppendSpeedLimit(0, config_.speed_limit());
61 speed_limit.AppendSpeedLimit(config_.total_time(), config_.speed_limit());
62 StGraphData *st_graph_data = reference_line_info->mutable_st_graph_data();
63 auto *debug = reference_line_info_->mutable_debug();
64 auto *st_graph_debug = debug->mutable_planning_data()->add_st_graph();
65 st_graph_data->LoadData(boundaries, 0.0, init_point, speed_limit,
66 config_.speed_limit(),
67 path_data.discretized_path().Length(),
68 config_.total_time(), st_graph_debug);
69 return Status::OK();
70}
71
72void ReverseSpeed::GetSTboundaries(
73 const DiscretizedPath &path_data, Frame *frame,
74 std::vector<const STBoundary *> *boundaries) {
75 CHECK_NOTNULL(boundaries);
76 CHECK_NOTNULL(frame);
77 static constexpr double kEpsilon = 1e-2;
78 auto obstacles_by_frame = frame->GetObstacleList();
79
80 for (auto *obstacle : obstacles_by_frame->Items()) {
81 STBoundary st_boundary;
82 std::vector<STPoint> lower_points;
83 std::vector<STPoint> upper_points;
84 for (const auto &curr_point_on_path : path_data) {
85 if (CheckOverlap(curr_point_on_path, obstacle->PerceptionPolygon(),
86 config_.l_buffer())) {
87 const double backward_distance = -vehicle_param_.back_edge_to_center();
88 const double forward_distance =
89 obstacle->PerceptionBoundingBox().length();
90 double low_s =
91 std::fmax(0.0, curr_point_on_path.s() + backward_distance);
92 double high_s = std::fmax(low_s + kEpsilon,
93 std::fmin(path_data.Length(),
94 curr_point_on_path.s() + forward_distance));
95 // It is an unrotated rectangle appearing on the ST-graph.
96 // TODO(jiacheng): reconsider the backward_distance, it might be
97 // unnecessary, but forward_distance is indeed meaningful though.
98 lower_points.emplace_back(low_s, 0.0);
99 lower_points.emplace_back(low_s, config_.total_time());
100 upper_points.emplace_back(high_s, 0.0);
101 upper_points.emplace_back(high_s, config_.total_time());
102 STBoundary st_boundary =
103 STBoundary::CreateInstance(lower_points, upper_points);
104 st_boundary.ExpandByS(config_.s_buffer());
105 st_boundary.SetCharacteristicLength(config_.s_buffer());
107 auto *origin_obstacle = frame->Find(obstacle->Id());
108 origin_obstacle->set_path_st_boundary(st_boundary);
109 boundaries->push_back(&origin_obstacle->path_st_boundary());
110 break;
111 }
112 }
113 }
114}
115
116bool ReverseSpeed::CheckOverlap(const PathPoint &path_point,
117 const Polygon2d &obs_polygon,
118 const double l_buffer) {
119 // Convert reference point from center of rear axis to center of ADC.
120 Vec2d ego_center_map_frame((vehicle_param_.front_edge_to_center() -
121 vehicle_param_.back_edge_to_center()) *
122 0.5,
123 (vehicle_param_.left_edge_to_center() -
124 vehicle_param_.right_edge_to_center()) *
125 0.5);
126 ego_center_map_frame.SelfRotate(path_point.theta());
127 ego_center_map_frame.set_x(ego_center_map_frame.x() + path_point.x());
128 ego_center_map_frame.set_y(ego_center_map_frame.y() + path_point.y());
129
130 // Compute the ADC bounding box.
131 Box2d adc_box(ego_center_map_frame, path_point.theta(),
132 vehicle_param_.length(), vehicle_param_.width() + l_buffer * 2);
133
134 // Check whether ADC polygon overlaps with obstacle polygon.
135 Polygon2d adc_polygon(adc_box);
136 return obs_polygon.HasOverlap(adc_polygon);
137}
138
139} // namespace planning
140} // namespace apollo
A general class to denote the return status of an API call.
Definition status.h:43
static Status OK()
generate a success status.
Definition status.h:60
Rectangular (undirected) bounding box in 2-D.
Definition box2d.h:52
The class of polygon in 2-D.
Definition polygon2d.h:42
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42
Frame holds all data for one planning cycle.
Definition frame.h:62
ThreadSafeIndexedObstacles * GetObstacleList()
Definition frame.h:165
Obstacle * Find(const std::string &id)
Definition frame.cc:486
const common::TrajectoryPoint & PlanningStartPoint() const
Definition frame.cc:79
void set_path_st_boundary(const STBoundary &boundary)
Definition obstacle.cc:698
ReferenceLineInfo holds all data for one reference line.
planning_internal::Debug * mutable_debug()
bool Init(const std::string &config_dir, const std::string &name, const std::shared_ptr< DependencyInjector > &injector) override
apollo::common::Status Execute(Frame *frame, ReferenceLineInfo *reference_line_info) override
static STBoundary CreateInstance(const std::vector< STPoint > &lower_points, const std::vector< STPoint > &upper_points)
Wrapper of the constructor (old).
void SetCharacteristicLength(const double characteristic_length)
STBoundary ExpandByS(const double s) const
void SetBoundaryType(const BoundaryType &boundary_type)
void AppendSpeedLimit(const double s, const double v)
void LoadData(const std::vector< const STBoundary * > &st_boundaries, const double min_s_on_st_boundaries, const apollo::common::TrajectoryPoint &init_point, const SpeedLimit &speed_limit, const double cruise_speed, const double path_data_length, const double total_time_by_conf, planning_internal::STGraphDebug *st_graph_debug)
ReferenceLineInfo * reference_line_info_
Definition task.h:58
virtual bool Init(const std::string &config_dir, const std::string &name, const std::shared_ptr< DependencyInjector > &injector)
Definition task.cc:40
virtual common::Status Execute(Frame *frame, ReferenceLineInfo *reference_line_info)
Definition task.cc:60
Planning module main class.
Some util functions.
class register implement
Definition arena_queue.h:37