Apollo 11.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
39
41 const TrajectoryPoint& planning_init_point, Frame* frame) {
42 ADEBUG << "stage: Approach";
43 CHECK_NOTNULL(frame);
44 auto scenario_context = GetContextAs<EmergencyPullOverContext>();
45 const auto& scenario_config = scenario_context->scenario_config;
46
47 auto& reference_line_info = frame->mutable_reference_line_info()->front();
48 reference_line_info.LimitCruiseSpeed(
49 scenario_context->target_slow_down_speed);
50 // set vehicle signal
51 reference_line_info.SetTurnSignal(VehicleSignal::TURN_RIGHT);
52
53 double stop_line_s = 0.0;
54
55 // add a stop fence
56 const auto& pull_over_status =
57 injector_->planning_context()->planning_status().pull_over();
58 if (pull_over_status.has_position() && pull_over_status.position().has_x() &&
59 pull_over_status.position().has_y()) {
60 const auto& reference_line = reference_line_info.reference_line();
61 common::SLPoint pull_over_sl;
62 reference_line.XYToSL(pull_over_status.position(), &pull_over_sl);
63 const double stop_distance = scenario_config.stop_distance();
64 stop_line_s =
65 pull_over_sl.s() + stop_distance +
67 const std::string virtual_obstacle_id = "EMERGENCY_PULL_OVER";
68 const std::vector<std::string> wait_for_obstacle_ids;
70 virtual_obstacle_id, stop_line_s, stop_distance,
71 StopReasonCode::STOP_REASON_PULL_OVER, wait_for_obstacle_ids,
72 "EMERGENCY_PULL_OVER-scenario", frame,
73 &(frame->mutable_reference_line_info()->front()));
74
75 ADEBUG << "Build a stop fence for emergency_pull_over: id["
76 << virtual_obstacle_id << "] s[" << stop_line_s << "]";
77 }
78
79 StageResult result = ExecuteTaskOnReferenceLine(planning_init_point, frame);
80 if (result.HasError()) {
81 AERROR << "EmergencyPullOverStageApproach planning error";
82 }
83
84 if (stop_line_s > 0.0) {
85 const double adc_front_edge_s = reference_line_info.AdcSlBoundary().end_s();
86 double distance = stop_line_s - adc_front_edge_s;
87 const double adc_speed = injector_->vehicle_state()->linear_velocity();
88 const double max_adc_stop_speed = common::VehicleConfigHelper::Instance()
89 ->GetConfig()
90 .vehicle_param()
91 .max_abs_speed_when_stopped();
92 ADEBUG << "adc_speed[" << adc_speed << "] distance[" << distance << "]";
93 static constexpr double kStopSpeedTolerance = 0.4;
94 static constexpr double kStopDistanceTolerance = 3.0;
95 if (adc_speed <= max_adc_stop_speed + kStopSpeedTolerance &&
96 std::fabs(distance) <= kStopDistanceTolerance) {
97 return FinishStage();
98 }
99 }
100
102}
103
104StageResult EmergencyPullOverStageApproach::FinishStage() {
105 next_stage_ = "EMERGENCY_PULL_OVER_STANDBY";
107}
108
109} // namespace planning
110} // namespace apollo
@Brief This is a helper class that can load vehicle configurations.
static const VehicleConfig & GetConfig()
Get the current vehicle configuration.
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
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
optional VehicleParam vehicle_param