Apollo 11.0
自动驾驶开放平台
lane_escape_stage.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2024 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
23#include <string>
24#include <vector>
27
28namespace apollo {
29namespace planning {
30
34
36 const StagePipeline& config,
37 const std::shared_ptr<DependencyInjector>& injector,
38 const std::string& config_dir,
39 void* context) {
40 CHECK_NOTNULL(context);
41 bool ret = Stage::Init(config, injector, config_dir, context);
42 if (!ret) {
43 AERROR << Name() << "init failed!";
44 return false;
45 }
46 scenario_config_.CopyFrom(GetContextAs<LaneEscapeContext>()->scenario_config);
47 return ret;
48}
49
51 apollo::common::VehicleState vehicle_state = injector_->vehicle_state()->vehicle_state();
52 if (vehicle_state.gear() != canbus::Chassis::GEAR_REVERSE) {
55 static constexpr double gear_shift_max_t = 5.0;
56 static constexpr double gear_shift_unit_t = 0.1;
57 for (double t = 0.0; t < gear_shift_max_t; t += gear_shift_unit_t) {
58 TrajectoryPoint point;
59 point.mutable_path_point()->set_x(frame->vehicle_state().x());
60 point.mutable_path_point()->set_y(frame->vehicle_state().y());
61 point.mutable_path_point()->set_theta(frame->vehicle_state().heading());
62 point.mutable_path_point()->set_s(0.0);
63 point.mutable_path_point()->set_kappa(0);
64 point.set_relative_time(t);
65 point.set_v(0.0);
66 point.set_a(0.0);
67 traj_pair->first.emplace_back(point);
68 }
69 traj_pair->second = apollo::canbus::Chassis::GEAR_REVERSE;
70 AINFO << "GENERATE REVERSE TRAJECTORY";
71 need_to_stop_ = false;
73 }
74 auto& reference_line_info = frame->mutable_reference_line_info()->back();
75 const auto& reference_line = reference_line_info.reference_line();
76 double adc_start_s = reference_line_info.AdcSlBoundary().start_s();
77
78 if (stop_point_ == nullptr) {
80 auto ref_point = reference_line.GetReferencePoint(adc_start_s - scenario_config_.escape_reverse_distance());
81 stop_point_ = std::make_shared<common::PathPoint>(ref_point.ToPathPoint(0.0));
82 }
83 AINFO << "need to stop";
84 common::SLPoint sl_point;
85 reference_line.XYToSL(*stop_point_, &sl_point);
86 std::vector<std::string> wait_for_obstacles;
88 "reverse_stop",
89 sl_point.s(),
90 0.1,
91 StopReasonCode::STOP_REASON_STOP_SIGN,
92 wait_for_obstacles,
93 "reverse stop",
94 frame,
95 &(frame->mutable_reference_line_info()->front()),
96 10.0);
97 StageResult result = ExecuteTaskOnReferenceLine(planning_init_point, frame);
98 const auto& candidate_paths = reference_line_info.GetCandidatePathData();
99 bool has_regular_path = false;
100 for (const auto& path_data : candidate_paths) {
101 if (path_data.path_label().find("regular") != std::string::npos) {
102 AINFO << "path_label: true";
103 }
104 double distance_to_block_obs = std::numeric_limits<double>::max();
105 if (!path_data.blocking_obstacle_id().empty()) {
106 auto obstacle = reference_line_info.path_decision()->Find(path_data.blocking_obstacle_id());
107 distance_to_block_obs
108 = obstacle->PerceptionSLBoundary().start_s() - reference_line_info.AdcSlBoundary().end_s();
109 AINFO << "blocking_obstacle_id: " << path_data.blocking_obstacle_id()
110 << " distance_to_block_obs: " << distance_to_block_obs;
111 }
112 if (path_data.discretized_path().Length() > scenario_config_.forward_path_length()) {
113 AINFO << "discretized_path().Length(): true";
114 }
115 if (path_data.path_label().find("regular") != std::string::npos
116 && path_data.discretized_path().Length() > scenario_config_.forward_path_length()
117 && distance_to_block_obs > scenario_config_.forward_path_length()) {
118 AINFO << "find regular path: " << path_data.path_label();
119 AINFO << "distance_to_block_obs: " << distance_to_block_obs;
120 has_regular_path = true;
121 break;
122 }
123 }
124 if (has_regular_path) {
125 success_path_times_++;
126 } else {
127 success_path_times_ = 0;
128 AINFO << "reset";
129 need_to_stop_ = false;
130 }
131 AINFO << "success_path_times_: " << success_path_times_;
132 if (success_path_times_ > scenario_config_.success_path_count()
133 && !reference_line_info.path_data().discretized_path().empty()
134 && !need_to_stop_) {
135 AINFO << "find square path change stage";
136 need_to_stop_ = true;
137 double ego_speed = frame->vehicle_state().linear_velocity();
138 double deceleration_distance = ego_speed * ego_speed / (2 * 0.5);
139 double stop_distance = std::min(
140 std::max(deceleration_distance, scenario_config_.escape_stop_distance()),
141 reference_line_info.mutable_path_data()->discretized_path().Length());
142 *stop_point_ = reference_line_info.mutable_path_data()->discretized_path().Evaluate(stop_distance);
143 AINFO << "length: " << reference_line_info.mutable_path_data()->discretized_path().Length()
144 << " stop_distance: " << stop_distance << " deceleration_distance: " << deceleration_distance
145 << std::setprecision(9) << "stop_point_:" << stop_point_->x() << "," << stop_point_->y();
146 }
147 stop_check_count_ = std::fabs(vehicle_state.linear_velocity()) < 0.05 ? stop_check_count_ + 1 : 0;
148 if (success_path_times_ > scenario_config_.success_path_count()
149 && stop_check_count_ > scenario_config_.stop_check_window()) {
150 AINFO << "already stopped change stage" << vehicle_state.linear_velocity() << " " << vehicle_state.x() << ", "
151 << vehicle_state.y();
152 return FinishStage();
153 }
155}
156
157StageResult LaneEscapeParkStage::FinishStage() {
158 next_stage_.clear();
159 ParkDataCenter::Instance()->set_need_escape(false);
161}
162
163} // namespace planning
164} // namespace apollo
A general class to denote the return status of an API call.
Definition status.h:43
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42
Frame holds all data for one planning cycle.
Definition frame.h:62
const common::VehicleState & vehicle_state() const
Definition frame.cc:83
OpenSpaceInfo * mutable_open_space_info()
Definition frame.h:169
std::list< ReferenceLineInfo > * mutable_reference_line_info()
Definition frame.cc:127
StageResult Process(const common::TrajectoryPoint &planning_init_point, Frame *frame) override
Each stage does its business logic inside Process function.
bool Init(const StagePipeline &config, const std::shared_ptr< DependencyInjector > &injector, const std::string &config_dir, void *context)
void set_is_on_open_space_trajectory(const bool flag)
std::pair< PublishableTrajectory, canbus::Chassis::GearPosition > * mutable_publishable_trajectory_data()
const StageResult & SetStageStatus(const StageStatusType &stage_status)
Set the stage status.
std::string next_stage_
Definition stage.h:89
virtual bool Init(const StagePipeline &config, const std::shared_ptr< DependencyInjector > &injector, const std::string &config_dir, void *context)
Definition stage.cc:43
std::shared_ptr< DependencyInjector > injector_
Definition stage.h:91
StageResult ExecuteTaskOnReferenceLine(const common::TrajectoryPoint &planning_start_point, Frame *frame)
Definition stage.cc:101
const std::string & Name() const
Definition stage.cc:99
Planning module main class.
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
int BuildStopDecision(const std::string &stop_wall_id, const double stop_line_s, const double stop_distance, const StopReasonCode &stop_reason_code, const std::vector< std::string > &wait_for_obstacles, const std::string &decision_tag, Frame *const frame, ReferenceLineInfo *const reference_line_info, double stop_wall_width)
Definition common.cc:28
class register implement
Definition arena_queue.h:37
optional apollo::canbus::Chassis::GearPosition gear