Apollo 11.0
自动驾驶开放平台
stage_standby.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 <string>
24#include <vector>
25
26#include "cyber/common/log.h"
30
31namespace apollo {
32namespace planning {
33
35
37 const TrajectoryPoint& planning_init_point, Frame* frame) {
38 ADEBUG << "stage: Standby";
39 CHECK_NOTNULL(frame);
40
41 scenario_config_.CopyFrom(
42 GetContextAs<EmergencyStopContext>()->scenario_config);
43
44 // add a stop fence
45 const auto& reference_line_info = frame->reference_line_info().front();
46 const auto& reference_line = reference_line_info.reference_line();
47 const double adc_front_edge_s = reference_line_info.AdcSlBoundary().end_s();
48 const double stop_distance = scenario_config_.stop_distance();
49
50 bool stop_fence_exist = false;
51 double stop_line_s;
52 const auto& emergency_stop_status =
53 injector_->planning_context()->planning_status().emergency_stop();
54 if (emergency_stop_status.has_stop_fence_point()) {
55 common::SLPoint stop_fence_sl;
56 reference_line.XYToSL(emergency_stop_status.stop_fence_point(),
57 &stop_fence_sl);
58 if (stop_fence_sl.s() > adc_front_edge_s) {
59 stop_fence_exist = true;
60 stop_line_s = stop_fence_sl.s();
61 }
62 }
63
64 if (!stop_fence_exist) {
65 static constexpr double kBuffer = 2.0;
66 stop_line_s = adc_front_edge_s + stop_distance + kBuffer;
67 const auto& stop_fence_point =
68 reference_line.GetReferencePoint(stop_line_s);
69 auto* emergency_stop_fence_point = injector_->planning_context()
70 ->mutable_planning_status()
71 ->mutable_emergency_stop()
72 ->mutable_stop_fence_point();
73 emergency_stop_fence_point->set_x(stop_fence_point.x());
74 emergency_stop_fence_point->set_y(stop_fence_point.y());
75 }
76
77 const std::string virtual_obstacle_id = "EMERGENCY_STOP";
78 const std::vector<std::string> wait_for_obstacle_ids;
80 virtual_obstacle_id, stop_line_s, stop_distance,
81 StopReasonCode::STOP_REASON_EMERGENCY, wait_for_obstacle_ids,
82 "EMERGENCY_STOP-scenario", frame,
83 &(frame->mutable_reference_line_info()->front()));
84 ADEBUG << "Build a stop fence for emergency_stop: id[" << virtual_obstacle_id
85 << "] s[" << stop_line_s << "]";
86
87 StageResult result = ExecuteTaskOnReferenceLine(planning_init_point, frame);
88 if (result.HasError()) {
89 AERROR << "EmergencyStopStageStandby planning error";
90 }
91
92 const auto& pad_msg_driving_action = frame->GetPadMsgDrivingAction();
93 if (pad_msg_driving_action != PadMessage::STOP) {
94 return FinishStage();
95 }
96
98}
99
100StageResult EmergencyStopStageStandby::FinishStage() {
101 return FinishScenario();
102}
103
104} // namespace planning
105} // 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 PadMessage::DrivingAction & GetPadMsgDrivingAction() const
Definition frame.h:173
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.
virtual StageResult FinishScenario()
Definition stage.cc:258
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