Apollo 11.0
自动驾驶开放平台
stage_adjust.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
18
19#include "cyber/common/log.h"
24
25namespace apollo {
26namespace planning {
27
29
31 const TrajectoryPoint& planning_init_point, Frame* frame) {
32 ADEBUG << "stage: Adjust";
33 CHECK_NOTNULL(frame);
34
36 StageResult result = ExecuteTaskOnOpenSpace(frame);
37 if (result.HasError()) {
38 AERROR << "ParkAndGoStageAdjust planning error";
40 }
41 const bool is_ready_to_cruise =
42 CheckADCReadyToCruise(injector_->vehicle_state(), frame,
43 GetContextAs<ParkAndGoContext>()->scenario_config);
44
45 bool is_end_of_trajectory = false;
46 const auto& history_frame = injector_->frame_history()->Latest();
47 if (history_frame) {
48 const auto& trajectory_points =
49 history_frame->current_frame_planned_trajectory().trajectory_point();
50 if (!trajectory_points.empty()) {
51 is_end_of_trajectory =
52 (trajectory_points.rbegin()->relative_time() < 0.0);
53 }
54 }
55
56 if (!is_ready_to_cruise && !is_end_of_trajectory) {
58 }
59 return FinishStage();
60}
61
62StageResult ParkAndGoStageAdjust::FinishStage() {
63 const auto vehicle_status = injector_->vehicle_state();
64 ADEBUG << vehicle_status->steering_percentage();
65 if (std::fabs(vehicle_status->steering_percentage()) <
66 GetContextAs<ParkAndGoContext>()
67 ->scenario_config.max_steering_percentage_when_cruise()) {
68 next_stage_ = "PARK_AND_GO_CRUISE";
69 } else {
70 ResetInitPostion();
71 next_stage_ = "PARK_AND_GO_PRE_CRUISE";
72 }
73 return StageResult(StageStatusType::FINISHED);
74}
75
76void ParkAndGoStageAdjust::ResetInitPostion() {
77 auto* park_and_go_status = injector_->planning_context()
78 ->mutable_planning_status()
79 ->mutable_park_and_go();
80 park_and_go_status->mutable_adc_init_position()->set_x(
81 injector_->vehicle_state()->x());
82 park_and_go_status->mutable_adc_init_position()->set_y(
83 injector_->vehicle_state()->y());
84 park_and_go_status->mutable_adc_init_position()->set_z(0.0);
85 park_and_go_status->set_adc_init_heading(
86 injector_->vehicle_state()->heading());
87}
88
89} // namespace planning
90} // 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)
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.
std::string next_stage_
Definition stage.h:89
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
bool CheckADCReadyToCruise(const common::VehicleStateProvider *vehicle_state_provider, Frame *frame, const apollo::planning::ScenarioParkAndGoConfig &scenario_config)
Definition util.cc:28
class register implement
Definition arena_queue.h:37