Apollo 11.0
自动驾驶开放平台
stage_retry_parking.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
25#include "cyber/common/log.h"
31
32namespace apollo {
33namespace planning {
34
36
38 const TrajectoryPoint& planning_init_point, Frame* frame) {
39 ADEBUG << "stage: RetryParking";
40 CHECK_NOTNULL(frame);
41 CHECK_NOTNULL(context_);
42
43 // Open space planning doesn't use planning_init_point from upstream because
44 // of different stitching strategy
46 StageResult result = ExecuteTaskOnOpenSpace(frame);
47 if (result.HasError()) {
48 AERROR << "PullOverStageRetryParking planning error";
50 }
51
52 // set debug info in planning_data
53 const auto& pull_over_status =
54 injector_->planning_context()->planning_status().pull_over();
55 auto* pull_over_debug = frame->mutable_open_space_info()
57 ->mutable_planning_data()
58 ->mutable_pull_over();
59 pull_over_debug->mutable_position()->CopyFrom(pull_over_status.position());
60 pull_over_debug->set_theta(pull_over_status.theta());
61 pull_over_debug->set_length_front(pull_over_status.length_front());
62 pull_over_debug->set_length_back(pull_over_status.length_back());
63 pull_over_debug->set_width_left(pull_over_status.width_left());
64 pull_over_debug->set_width_right(pull_over_status.width_right());
66
67 if (CheckADCPullOverOpenSpace()) {
68 return FinishStage();
69 }
70
72}
73
74StageResult PullOverStageRetryParking::FinishStage() {
75 return FinishScenario();
76}
77
78bool PullOverStageRetryParking::CheckADCPullOverOpenSpace() {
79 const auto& pull_over_status =
80 injector_->planning_context()->planning_status().pull_over();
81 if (!pull_over_status.has_position() ||
82 !pull_over_status.position().has_x() ||
83 !pull_over_status.position().has_y() || !pull_over_status.has_theta()) {
84 ADEBUG << "pull_over status not set properly: "
85 << pull_over_status.DebugString();
86 return false;
87 }
88
89 const common::math::Vec2d adc_position = {injector_->vehicle_state()->x(),
90 injector_->vehicle_state()->y()};
91 const common::math::Vec2d target_position = {pull_over_status.position().x(),
92 pull_over_status.position().y()};
93
94 const double distance_diff = adc_position.DistanceTo(target_position);
95 const double theta_diff = std::fabs(common::math::NormalizeAngle(
96 pull_over_status.theta() - injector_->vehicle_state()->heading()));
97 ADEBUG << "distance_diff[" << distance_diff << "] theta_diff[" << theta_diff
98 << "]";
99 const ScenarioPullOverConfig& scenario_config =
100 GetContextAs<PullOverContext>()->scenario_config;
101 // check distance/theta diff
102 return (distance_diff <= scenario_config.max_distance_error_to_end_point() &&
103 theta_diff <= scenario_config.max_theta_error_to_end_point());
104}
105
106} // namespace planning
107} // namespace apollo
Frame holds all data for one planning cycle.
Definition frame.h:62
OpenSpaceInfo * mutable_open_space_info()
Definition frame.h:169
void set_is_on_open_space_trajectory(const bool flag)
apollo::planning_internal::Debug * mutable_debug()
StageResult Process(const common::TrajectoryPoint &planning_init_point, Frame *frame) override
Each stage does its business logic inside Process function.
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
StageResult ExecuteTaskOnOpenSpace(Frame *frame)
Definition stage.cc:206
std::shared_ptr< DependencyInjector > injector_
Definition stage.h:91
Planning module main class.
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
double NormalizeAngle(const double angle)
Normalize angle to [-PI, PI).
Definition math_utils.cc:53
class register implement
Definition arena_queue.h:37