Apollo 10.0
自动驾驶开放平台
stage_approach.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
22
23#include <memory>
24#include <string>
25#include <vector>
26
27#include "cyber/common/log.h"
32
33namespace apollo {
34namespace planning {
35
37
39 const TrajectoryPoint& planning_init_point, Frame* frame) {
40 ADEBUG << "stage: Approach";
41 CHECK_NOTNULL(frame);
42
43 scenario_config_.CopyFrom(
44 GetContextAs<EmergencyStopContext>()->scenario_config);
45
46 // set vehicle signal
47 frame->mutable_reference_line_info()->front().SetEmergencyLight();
48
49 // add a stop fence
50 const auto& reference_line_info = frame->reference_line_info().front();
51 const auto& reference_line = reference_line_info.reference_line();
52 const double adc_speed = injector_->vehicle_state()->linear_velocity();
53 const double adc_front_edge_s = reference_line_info.AdcSlBoundary().end_s();
54 const double stop_distance = scenario_config_.stop_distance();
55
56 bool stop_fence_exist = false;
57 double stop_line_s;
58 const auto& emergency_stop_status =
59 injector_->planning_context()->planning_status().emergency_stop();
60 if (emergency_stop_status.has_stop_fence_point()) {
61 common::SLPoint stop_fence_sl;
62 reference_line.XYToSL(emergency_stop_status.stop_fence_point(),
63 &stop_fence_sl);
64 if (stop_fence_sl.s() > adc_front_edge_s) {
65 stop_fence_exist = true;
66 stop_line_s = stop_fence_sl.s();
67 }
68 }
69
70 if (!stop_fence_exist) {
71 const double deceleration = scenario_config_.max_stop_deceleration();
72 const double travel_distance =
73 std::ceil(std::pow(adc_speed, 2) / (2 * deceleration));
74
75 static constexpr double kBuffer = 2.0;
76 stop_line_s = adc_front_edge_s + travel_distance + stop_distance + kBuffer;
77 ADEBUG << "travel_distance[" << travel_distance << "] [" << adc_speed
78 << "] adc_front_edge_s[" << adc_front_edge_s << "] stop_line_s["
79 << stop_line_s << "]";
80 const auto& stop_fence_point =
81 reference_line.GetReferencePoint(stop_line_s);
82 auto* emergency_stop_fence_point = injector_->planning_context()
83 ->mutable_planning_status()
84 ->mutable_emergency_stop()
85 ->mutable_stop_fence_point();
86 emergency_stop_fence_point->set_x(stop_fence_point.x());
87 emergency_stop_fence_point->set_y(stop_fence_point.y());
88 }
89
90 const std::string virtual_obstacle_id = "EMERGENCY_STOP";
91 const std::vector<std::string> wait_for_obstacle_ids;
93 virtual_obstacle_id, stop_line_s, stop_distance,
94 StopReasonCode::STOP_REASON_EMERGENCY, wait_for_obstacle_ids,
95 "EMERGENCY_STOP-scenario", frame,
96 &(frame->mutable_reference_line_info()->front()));
97 ADEBUG << "Build a stop fence for emergency_stop: id[" << virtual_obstacle_id
98 << "] s[" << stop_line_s << "]";
99
100 StageResult result = ExecuteTaskOnReferenceLine(planning_init_point, frame);
101 if (result.HasError()) {
102 AERROR << "EmergencyPullOverStageApproach planning error";
103 }
104
105 const double max_adc_stop_speed = common::VehicleConfigHelper::Instance()
106 ->GetConfig()
107 .vehicle_param()
108 .max_abs_speed_when_stopped();
109 if (adc_speed <= max_adc_stop_speed) {
110 return FinishStage();
111 }
112
114}
115
116StageResult EmergencyStopStageApproach::FinishStage() {
117 next_stage_ = "EMERGENCY_STOP_STANDBY";
119}
120
121} // namespace planning
122} // namespace apollo
StageResult Process(const common::TrajectoryPoint &planning_init_point, Frame *frame) override
Each stage does its business logic inside Process function.
Frame holds all data for one planning cycle.
Definition frame.h:62
const std::list< ReferenceLineInfo > & reference_line_info() const
Definition frame.cc:123
std::list< ReferenceLineInfo > * mutable_reference_line_info()
Definition frame.cc:127
const StageResult & SetStageStatus(const StageStatusType &stage_status)
Set the stage status.
bool HasError() const
Check if StageResult contains error.
std::string next_stage_
Definition stage.h:89
std::shared_ptr< DependencyInjector > injector_
Definition stage.h:91
StageResult ExecuteTaskOnReferenceLine(const common::TrajectoryPoint &planning_start_point, Frame *frame)
Definition stage.cc:101
Planning module main class.
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
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