42 const std::string& config_dir,
const std::string& name,
43 const std::shared_ptr<DependencyInjector>& injector) {
48 bool res = Decider::LoadConfig<OpenSpacePreStopDeciderConfig>(&config_);
49 AINFO <<
"Load config:" << config_.DebugString();
53Status OpenSpacePreStopDecider::Process(
56 CHECK_NOTNULL(reference_line_info);
57 double target_s = 0.0;
58 const auto& stop_type = config_.
stop_type();
61 if (!CheckParkingSpotPreStop(frame, reference_line_info, &target_s)) {
62 const std::string msg =
"Checking parking spot pre stop fails";
64 return Status(ErrorCode::PLANNING_ERROR, msg);
66 SetParkingSpotStopFence(target_s, frame, reference_line_info);
69 if (!CheckPullOverPreStop(frame, reference_line_info, &target_s)) {
70 const std::string msg =
"Checking pull over pre stop fails";
72 return Status(ErrorCode::PLANNING_ERROR, msg);
74 SetPullOverStopFence(target_s, frame, reference_line_info);
77 const std::string msg =
"This stop type not implemented";
79 return Status(ErrorCode::PLANNING_ERROR, msg);
84bool OpenSpacePreStopDecider::CheckPullOverPreStop(
85 Frame*
const frame, ReferenceLineInfo*
const reference_line_info,
88 const auto& pull_over_status =
89 injector_->planning_context()->planning_status().pull_over();
90 if (pull_over_status.has_position() && pull_over_status.position().has_x() &&
91 pull_over_status.position().has_y()) {
92 common::SLPoint pull_over_sl;
93 const auto& reference_line = reference_line_info->reference_line();
94 reference_line.XYToSL(pull_over_status.position(), &pull_over_sl);
95 *target_s = pull_over_sl.s();
100bool OpenSpacePreStopDecider::CheckParkingSpotPreStop(
101 Frame*
const frame, ReferenceLineInfo*
const reference_line_info,
103 const auto& target_parking_spot_id =
104 frame->open_space_info().target_parking_spot_id();
105 const auto& nearby_path = reference_line_info->reference_line().map_path();
106 if (target_parking_spot_id.empty()) {
107 AERROR <<
"no target parking spot id found when setting pre stop fence";
111 double target_area_center_s = 0.0;
112 bool target_area_found =
false;
113 const auto& parking_space_overlaps = nearby_path.parking_space_overlaps();
116 for (
const auto& parking_overlap : parking_space_overlaps) {
117 if (parking_overlap.object_id == target_parking_spot_id) {
122 id.set_id(parking_overlap.object_id);
123 target_parking_spot_ptr = hdmap->GetParkingSpaceById(
id);
124 Vec2d left_bottom_point =
125 target_parking_spot_ptr->polygon().points().at(0);
126 Vec2d right_bottom_point =
127 target_parking_spot_ptr->polygon().points().at(1);
128 Vec2d right_up_point = target_parking_spot_ptr->polygon().points().at(2);
129 Vec2d left_up_point = target_parking_spot_ptr->polygon().points().at(3);
130 Vec2d center_point = (left_bottom_point + right_bottom_point +
131 right_up_point + left_up_point) /
134 nearby_path.GetNearestPoint(center_point, &target_area_center_s,
136 target_area_found =
true;
140 if (!target_area_found) {
141 AERROR <<
"no target parking spot found on reference line";
144 *target_s = target_area_center_s;
148void OpenSpacePreStopDecider::SetParkingSpotStopFence(
149 const double target_s,
Frame*
const frame,
150 ReferenceLineInfo*
const reference_line_info) {
151 const auto& nearby_path = reference_line_info->reference_line().map_path();
152 const double adc_front_edge_s = reference_line_info->AdcSlBoundary().end_s();
153 const double front_edge_to_center = common::VehicleConfigHelper::Instance()
156 .front_edge_to_center();
157 double ego_s = adc_front_edge_s - front_edge_to_center;
158 const VehicleState& vehicle_state = frame->vehicle_state();
159 double stop_line_s = 0.0;
161 double static_linear_velocity_epsilon = 1.0e-2;
162 static constexpr double kStopBuffer = 0.2;
163 CHECK_GE(stop_distance_to_target, 1.0e-8);
166 const std::string stop_wall_id = OPEN_SPACE_STOP_ID;
167 std::vector<std::string> wait_for_obstacles;
168 frame->mutable_open_space_info()->set_open_space_pre_stop_fence_s(
171 StopReasonCode::STOP_REASON_PRE_OPEN_SPACE_STOP,
172 wait_for_obstacles,
"OpenSpacePreStopDecider", frame,
173 reference_line_info);
176void OpenSpacePreStopDecider::SetPullOverStopFence(
177 const double target_s,
Frame*
const frame,
178 ReferenceLineInfo*
const reference_line_info) {
179 const auto& nearby_path = reference_line_info->reference_line().map_path();
180 const double adc_front_edge_s = reference_line_info->AdcSlBoundary().end_s();
181 const VehicleState& vehicle_state = frame->vehicle_state();
182 double stop_line_s = 0.0;
184 double static_linear_velocity_epsilon = 1.0e-2;
185 CHECK_GE(stop_distance_to_target, 1.0e-8);
186 double target_vehicle_offset = target_s - adc_front_edge_s;
187 if (target_vehicle_offset > stop_distance_to_target) {
188 stop_line_s = target_s - stop_distance_to_target;
190 if (!frame->open_space_info().pre_stop_rightaway_flag()) {
194 if (std::abs(vehicle_state.linear_velocity()) <
195 static_linear_velocity_epsilon) {
196 stop_line_s = adc_front_edge_s;
198 *(frame->mutable_open_space_info()->mutable_pre_stop_rightaway_point()) =
199 nearby_path.GetSmoothPoint(stop_line_s);
200 frame->mutable_open_space_info()->set_pre_stop_rightaway_flag(
true);
202 double stop_point_s = 0.0;
203 double stop_point_l = 0.0;
204 nearby_path.GetNearestPoint(
205 frame->open_space_info().pre_stop_rightaway_point(), &stop_point_s,
207 stop_line_s = stop_point_s;
211 const std::string stop_wall_id = OPEN_SPACE_STOP_ID;
212 std::vector<std::string> wait_for_obstacles;
213 frame->mutable_open_space_info()->set_open_space_pre_stop_fence_s(
216 StopReasonCode::STOP_REASON_PRE_OPEN_SPACE_STOP,
217 wait_for_obstacles,
"OpenSpacePreStopDecider", frame,
218 reference_line_info);
A general class to denote the return status of an API call.
static Status OK()
generate a success status.
Implements a class of 2-dimensional vectors.
static const HDMap * BaseMapPtr()
Frame holds all data for one planning cycle.
bool Init(const std::string &config_dir, const std::string &name, const std::shared_ptr< DependencyInjector > &injector) override
ReferenceLineInfo holds all data for one reference line.
std::shared_ptr< DependencyInjector > injector_
virtual bool Init(const std::string &config_dir, const std::string &name, const std::shared_ptr< DependencyInjector > &injector)
Planning module main class.
std::shared_ptr< const ParkingSpaceInfo > ParkingSpaceInfoConstPtr
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)
optional double stop_distance_to_target
optional double rightaway_stop_distance
optional double stop_buffer_to_target
optional StopType stop_type