Apollo 11.0
自动驾驶开放平台
park_and_go_scenario.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"
26
27namespace apollo {
28namespace planning {
29
31
32bool ParkAndGoScenario::Init(std::shared_ptr<DependencyInjector> injector,
33 const std::string& name) {
34 if (init_) {
35 return true;
36 }
37
38 if (!Scenario::Init(injector, name)) {
39 AERROR << "failed to init scenario" << Name();
40 return false;
41 }
42
43 if (!Scenario::LoadConfig<apollo::planning::ScenarioParkAndGoConfig>(
44 &context_.scenario_config)) {
45 AERROR << "fail to get config of scenario" << Name();
46 return false;
47 }
48
49 init_ = true;
50 return true;
51}
52
53bool ParkAndGoScenario::IsTransferable(const Scenario* const other_scenario,
54 const Frame& frame) {
55 if (!frame.local_view().planning_command->has_lane_follow_command()) {
56 AINFO << "PARK_AND_GO: Don't has lane follow command!";
57 return false;
58 }
59 if (other_scenario == nullptr || frame.reference_line_info().empty()) {
60 AINFO << "PARK_AND_GO: Don't has reference line info or other scenario!";
61 return false;
62 }
63 bool park_and_go = false;
64 const auto& scenario_config = context_.scenario_config;
65 const auto vehicle_state_provider = injector_->vehicle_state();
66 common::VehicleState vehicle_state = vehicle_state_provider->vehicle_state();
67 auto adc_point = common::util::PointFactory::ToPointENU(vehicle_state);
68 // TODO(SHU) might consider gear == GEAR_PARKING
69 double adc_speed = vehicle_state_provider->linear_velocity();
70 double s = 0.0;
71 double l = 0.0;
72 const double max_abs_speed_when_stopped =
73 common::VehicleConfigHelper::Instance()
74 ->GetConfig()
75 .vehicle_param()
76 .max_abs_speed_when_stopped();
77
79
80 // check ego vehicle distance to destination
81 const auto routing_end = frame.local_view().end_lane_way_point;
82 if (nullptr == routing_end) {
83 AINFO << "PARK_AND_GO: Don't has end lane way point!";
84 return false;
85 }
86 common::SLPoint dest_sl;
87 const auto& reference_line_info = frame.reference_line_info().front();
88 const auto& reference_line = reference_line_info.reference_line();
89 reference_line.XYToSL(routing_end->pose(), &dest_sl);
90 const double adc_front_edge_s = reference_line_info.AdcSlBoundary().end_s();
91
92 bool is_ego_on_lane = false;
93 bool is_lane_type_city_driving = false;
95 adc_point, 5.0, &lane, &s, &l);
96 if (lane != nullptr && lane->IsOnLane({adc_point.x(), adc_point.y()})) {
97 is_ego_on_lane = true;
98 if (lane->lane().type() == hdmap::Lane::CITY_DRIVING) {
99 is_lane_type_city_driving = true;
100 }
101 }
102
103 const double adc_distance_to_dest = dest_sl.s() - adc_front_edge_s;
104 ADEBUG << "adc_distance_to_dest:" << adc_distance_to_dest;
105 bool is_vehicle_static = (std::fabs(adc_speed) < max_abs_speed_when_stopped);
106 bool is_distance_far_enough =
107 (adc_distance_to_dest > scenario_config.min_dist_to_dest());
108 AINFO << "PARK_AND_GO: " << is_vehicle_static << "," << is_distance_far_enough
109 << "," << is_ego_on_lane << "," << is_lane_type_city_driving;
110 // if vehicle is static, far enough to destination and (off-lane or not on
111 // city_driving lane)
112 if (std::fabs(adc_speed) < max_abs_speed_when_stopped &&
113 adc_distance_to_dest > scenario_config.min_dist_to_dest() &&
114 (!is_ego_on_lane || !is_lane_type_city_driving)) {
115 park_and_go = true;
116 }
117 return park_and_go;
118}
119
120} // namespace planning
121} // namespace apollo
static PointENU ToPointENU(const double x, const double y, const double z=0)
static const HDMap & BaseMap()
int GetNearestLaneWithDistance(const apollo::common::PointENU &point, const double distance, LaneInfoConstPtr *nearest_lane, double *nearest_s, double *nearest_l) const
get nearest lane from target point with search radius,
Definition hdmap.cc:161
Frame holds all data for one planning cycle.
Definition frame.h:62
const LocalView & local_view() const
Definition frame.h:163
const std::list< ReferenceLineInfo > & reference_line_info() const
Definition frame.cc:123
bool Init(std::shared_ptr< DependencyInjector > injector, const std::string &name) override
bool IsTransferable(const Scenario *const other_scenario, const Frame &frame) override
Each scenario should define its own transfer condition, i.e., when it should allow to transfer from o...
virtual bool Init(std::shared_ptr< DependencyInjector > injector, const std::string &name)
Definition scenario.cc:43
std::shared_ptr< DependencyInjector > injector_
Definition scenario.h:113
const std::string & Name() const
Definition scenario.h:98
Planning module main class.
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
std::shared_ptr< const LaneInfo > LaneInfoConstPtr
class register implement
Definition arena_queue.h:37
std::shared_ptr< routing::LaneWaypoint > end_lane_way_point
Definition local_view.h:49
std::shared_ptr< PlanningCommand > planning_command
Definition local_view.h:48
apollo::planning::ScenarioParkAndGoConfig scenario_config
Definition context.h:29