Apollo 11.0
自动驾驶开放平台
stage_parking_park.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
20#include <vector>
22
24
25namespace apollo {
26namespace planning {
27
29 const common::TrajectoryPoint& planning_init_point, Frame* frame) {
30 AINFO << "new version of stage parking park";
31 // Open space planning doesn't use planning_init_point from upstream because
32 // of different stitching strategy
33 auto scenario_context = GetContextAs<ValetParkingContext>();
34
35 if (arrive_parking_spot_) {
36 AINFO << "Stage Parking finish";
39 }
40
41 scenario_config_ = scenario_context->scenario_config;
44 scenario_context->target_parking_spot_id;
45 StageResult result = ExecuteTaskOnOpenSpace(frame);
46 if (result.HasError()) {
47 AERROR << "StageParking planning error";
49 }
50 if (frame->open_space_info().destination_reached()) {
51 arrive_parking_spot_ = true;
52 if (!CheckADCParkingCompleted(frame)) {
53 AINFO << "Stage Parking finish but do not reach parking spot,"
54 "retry parking";
55 return FinishStage(frame);
56 } else {
58 AINFO << "Stage Parking finish";
59 parking_mission_info_.status = ParkingMissionStatus::DONE;
61 }
62 }
64}
65
66StageResult StageParkingPark::FinishStage(Frame* frame) {
67 next_stage_ = "VALET_PARKING_RETRY_PARK";
69 mutable_optimizer_trajectory_data()->clear();
71 mutable_path_planning_trajectory_result()->clear();
73 mutable_interpolated_trajectory_result()->clear();
75 mutable_partitioned_trajectories()->clear();
77 mutable_chosen_partitioned_trajectory()->first.clear();
79 // const auto vehicle_status = injector_->vehicle_state();
80 // if (std::fabs(vehicle_status->steering_percentage()) <
81 // GetContextAs<ParkAndGoContext>()
82 // ->scenario_config.max_steering_percentage_when_cruise()) {
83 // next_stage_ = "VALET_PARKING_RETRY";
84 // return StageResult(StageStatusType::FINISHED);
85 // }
86 // return StageResult(StageStatusType::RUNNING);
87}
88
89bool StageParkingPark::CheckADCParkingCompleted(Frame* frame) {
90 double ego_x = injector_->vehicle_state()->x();
91 double ego_y = injector_->vehicle_state()->y();
92 double ego_theta = injector_->vehicle_state()->heading();
94 frame->open_space_info().origin_heading(),
95 frame->open_space_info().origin_point(),
96 &ego_x, &ego_y, &ego_theta);
97 const std::vector<double>& end_pose =
98 frame->open_space_info().open_space_end_pose();
99 double delta_theta = fabs(
100 common::math::NormalizeAngle(ego_theta - end_pose[2]));
101 common::math::Vec2d vec(ego_x - end_pose[0], ego_y - end_pose[1]);
103 double lat_error = park_unit_vec.CrossProd(vec);
104 double lon_error = park_unit_vec.InnerProd(vec);
105 AINFO << "lat error: " << lat_error << " "
106 << "lon error: " << lon_error << " "
107 << "delta_theta: " << delta_theta;
108 if (frame->open_space_info().parking_type() == ParkingType::PARALLEL_PARKING &&
109 !scenario_config_.enable_parallel_retry_parking()){
110 AINFO << "parallel parking no retry";
111 return true;
112 }
113 if (std::fabs(lat_error) < scenario_config_.max_lat_error() &&
114 std::fabs(lon_error) < scenario_config_.max_lon_error() &&
115 std::fabs(delta_theta) < scenario_config_.max_heading_error()) {
116 return true;
117 }
118 return false;
119}
120
121bool StageParkingPark::CheckParkingMissionInfo(const ValetParkingContext& planning_command) {
122 if (parking_mission_info_.parking_spot_id != planning_command.target_parking_spot_id) {
123 parking_mission_info_.parking_spot_id = planning_command.target_parking_spot_id;
124 parking_mission_info_.command_sequence_num = planning_command.command_sequence_num;
125 parking_mission_info_.status = ParkingMissionStatus::RUNNING;
126 AINFO << "Get new parking spot id from routing: " << parking_mission_info_.parking_spot_id
127 << " command sequence num: " << (int)parking_mission_info_.command_sequence_num;
128 return true;
129 } else if (parking_mission_info_.command_sequence_num != planning_command.command_sequence_num) {
130 parking_mission_info_.command_sequence_num = planning_command.command_sequence_num;
131 parking_mission_info_.status = ParkingMissionStatus::RUNNING;
132 AINFO << "Get new command sequence num from routing: " << parking_mission_info_.parking_spot_id
133 << " command sequence num: " << (int)parking_mission_info_.command_sequence_num;
134 return true;
135 } else if (parking_mission_info_.status == ParkingMissionStatus::RUNNING) {
136 AINFO << "Get same parking spot id from routing: " << parking_mission_info_.parking_spot_id
137 << " command sequence num: " << (int)parking_mission_info_.command_sequence_num;
138 return true;
139 } else if (parking_mission_info_.status == ParkingMissionStatus::DONE) {
140 AINFO << "Get same parking spot id from routing: " << parking_mission_info_.parking_spot_id << "but status is DONE";
141 return false;
142 }
143 AINFO << "UNKNOW STATUS";
144 return false;
145}
146
147} // namespace planning
148} // namespace apollo
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42
static Vec2d CreateUnitVec2d(const double angle)
Creates a unit-vector with a given angle to the positive x semi-axis
Definition vec2d.cc:29
double InnerProd(const Vec2d &other) const
Returns the inner product between these two Vec2d.
Definition vec2d.cc:61
double CrossProd(const Vec2d &other) const
Returns the "cross" product between these two Vec2d (non-standard).
Definition vec2d.cc:57
Frame holds all data for one planning cycle.
Definition frame.h:62
const OpenSpaceInfo & open_space_info() const
Definition frame.h:167
OpenSpaceInfo * mutable_open_space_info()
Definition frame.h:169
std::string * mutable_target_parking_spot_id()
void set_is_on_open_space_trajectory(const bool flag)
void set_openspace_planning_finish(const bool flag)
static void PathPointNormalizing(double rotate_angle, const common::math::Vec2d &translate_origin, double *x, double *y, double *phi)
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 AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
double NormalizeAngle(const double angle)
Normalize angle to [-PI, PI).
Definition math_utils.cc:53
class register implement
Definition arena_queue.h:37