26#include "modules/common_msgs/perception_msgs/perception_obstacle.pb.h"
51 std::unordered_map<std::string, std::vector<std::string>>;
55 ADEBUG <<
"stage: PreStop";
61 AERROR <<
"StopSignUnprotectedStagePreStop planning error";
65 auto context = GetContextAs<StopSignUnprotectedContext>();
66 std::string stop_sign_overlap_id = context->current_stop_sign_overlap_id;
70 reference_line_info.GetOverlapOnReferenceLine(
72 if (!current_stop_sign_overlap) {
76 static constexpr double kPassStopLineBuffer = 0.3;
77 const double adc_front_edge_s = reference_line_info.AdcSlBoundary().end_s();
78 const double distance_adc_pass_stop_sign =
79 adc_front_edge_s - current_stop_sign_overlap->
start_s;
80 if (distance_adc_pass_stop_sign <= kPassStopLineBuffer) {
82 if (CheckADCStop(adc_front_edge_s, current_stop_sign_overlap->
start_s)) {
91 const PathDecision& path_decision = reference_line_info.path_decision();
92 auto& watch_vehicles = context->watch_vehicles;
94 std::vector<std::string> watch_vehicle_ids;
95 for (
const auto& vehicle : watch_vehicles) {
96 std::copy(vehicle.second.begin(), vehicle.second.end(),
97 std::back_inserter(watch_vehicle_ids));
100 std::string associated_lane_id = vehicle.first;
102 for (
const std::string& vehicle_id : vehicle.second) {
103 s = s.empty() ? vehicle_id : s +
"," + vehicle_id;
105 ADEBUG <<
"watch_vehicles: lane_id[" << associated_lane_id <<
"] vehicle["
111 for (
const auto& perception_obstacle_id : watch_vehicle_ids) {
113 ->mutable_planning_status()
114 ->mutable_stop_sign()
115 ->add_wait_for_obstacle_id(perception_obstacle_id);
120 AddWatchVehicle(*obstacle, &watch_vehicles);
129int StopSignUnprotectedStagePreStop::AddWatchVehicle(
131 CHECK_NOTNULL(watch_vehicles);
134 const std::string& perception_obstacle_id =
135 std::to_string(perception_obstacle.
id());
137 std::string obstacle_type_name = PerceptionObstacle_Type_Name(obstacle_type);
144 ADEBUG <<
"obstacle_id[" << perception_obstacle_id <<
"] type["
145 << obstacle_type_name <<
"]. skip";
151 double obstacle_s = 0.0;
152 double obstacle_l = 0.0;
153 LaneInfoConstPtr obstacle_lane;
155 point, 5.0, perception_obstacle.
theta(), M_PI / 3.0, &obstacle_lane,
156 &obstacle_s, &obstacle_l) != 0) {
157 ADEBUG <<
"obstacle_id[" << perception_obstacle_id <<
"] type["
158 << obstacle_type_name
159 <<
"]: Failed to find nearest lane from map for position: "
160 << point.DebugString() <<
"; heading[" << perception_obstacle.
theta()
166 ADEBUG <<
"obstacle_id[" << perception_obstacle_id <<
"] type["
167 << obstacle_type_name <<
"]: is off road. " << point.DebugString()
168 <<
"; heading[" << perception_obstacle.
theta() <<
"]";
173 std::string obstable_lane_id = obstacle_lane.get()->id().id();
174 auto context = GetContextAs<StopSignUnprotectedContext>();
175 auto assoc_lane_it = std::find_if(
176 context->associated_lanes.begin(), context->associated_lanes.end(),
178 std::pair<LaneInfoConstPtr, OverlapInfoConstPtr>& assc_lane) {
179 return assc_lane.first.get()->id().id() == obstable_lane_id;
181 if (assoc_lane_it == context->associated_lanes.end()) {
182 ADEBUG <<
"obstacle_id[" << perception_obstacle_id <<
"] type["
183 << obstacle_type_name <<
"] lane_id[" << obstable_lane_id
184 <<
"] not associated with current stop_sign. skip";
189 auto over_lap_info = assoc_lane_it->second.get()->GetObjectOverlapInfo(
190 obstacle_lane.get()->id());
191 if (over_lap_info ==
nullptr) {
192 AERROR <<
"can't find over_lap_info for id: " << obstable_lane_id;
195 const double stop_line_s = over_lap_info->lane_overlap_info().start_s();
196 const double obstacle_end_s = obstacle_s + perception_obstacle.
length() / 2;
197 const double distance_to_stop_line = stop_line_s - obstacle_end_s;
198 if (distance_to_stop_line >
199 GetContextAs<StopSignUnprotectedContext>()
200 ->scenario_config.watch_vehicle_max_valid_stop_distance()) {
201 ADEBUG <<
"obstacle_id[" << perception_obstacle_id <<
"] type["
202 << obstacle_type_name <<
"] distance_to_stop_line["
203 << distance_to_stop_line <<
"]; stop_line_s" << stop_line_s
204 <<
"]; obstacle_end_s[" << obstacle_end_s
205 <<
"] too far from stop line. skip";
210 std::vector<std::string> vehicles =
211 (*watch_vehicles)[obstacle_lane->id().id()];
212 if (std::find(vehicles.begin(), vehicles.end(), perception_obstacle_id) ==
214 ADEBUG <<
"AddWatchVehicle: lane[" << obstacle_lane->id().id()
215 <<
"] obstacle_id[" << perception_obstacle_id <<
"]";
216 (*watch_vehicles)[obstacle_lane->id().id()].push_back(
217 perception_obstacle_id);
226bool StopSignUnprotectedStagePreStop::CheckADCStop(
227 const double adc_front_edge_s,
const double stop_line_s) {
228 const double adc_speed =
injector_->vehicle_state()->linear_velocity();
229 const double max_adc_stop_speed = common::VehicleConfigHelper::Instance()
232 .max_abs_speed_when_stopped();
233 if (adc_speed > max_adc_stop_speed) {
234 ADEBUG <<
"ADC not stopped: speed[" << adc_speed <<
"]";
239 const double distance_stop_line_to_adc_front_edge =
240 stop_line_s - adc_front_edge_s;
241 ADEBUG <<
"distance_stop_line_to_adc_front_edge["
242 << distance_stop_line_to_adc_front_edge <<
"]";
244 if (distance_stop_line_to_adc_front_edge >
245 GetContextAs<StopSignUnprotectedContext>()
246 ->scenario_config.max_valid_stop_distance()) {
247 ADEBUG <<
"not a valid stop. too far from stop line.";
256StageResult StopSignUnprotectedStagePreStop::FinishStage() {
257 auto scenario_context = GetContextAs<StopSignUnprotectedContext>();
static math::Vec2d ToVec2d(const XY &xy)
static PointENU ToPointENU(const double x, const double y, const double z=0)
a singleton clock that can be used to get the current timestamp.
static double NowInSeconds()
gets the current time in second.
static const HDMap & BaseMap()
Frame holds all data for one planning cycle.
const std::list< ReferenceLineInfo > & reference_line_info() const
const std::vector< const T * > & Items() const
List all the items in the container.
This is the class that associates an Obstacle with its path properties.
const perception::PerceptionObstacle & Perception() const
PathDecision represents all obstacle decisions on one path.
const IndexedList< std::string, Obstacle > & obstacles() const
const StageResult & SetStageStatus(const StageStatusType &stage_status)
Set the stage status.
bool HasError() const
Check if StageResult contains error.
virtual StageResult FinishScenario()
std::shared_ptr< DependencyInjector > injector_
StageResult ExecuteTaskOnReferenceLine(const common::TrajectoryPoint &planning_start_point, Frame *frame)
StageResult Process(const common::TrajectoryPoint &planning_init_point, Frame *frame) override
Each stage does its business logic inside Process function.
Planning module main class.
std::shared_ptr< const LaneInfo > LaneInfoConstPtr
std::shared_ptr< const OverlapInfo > OverlapInfoConstPtr
std::unordered_map< std::string, std::vector< std::string > > StopSignLaneVehicles
optional apollo::common::Point3D position