@@ -29,6 +29,7 @@ namespace {
2929
3030using apollo::hdmap::HDMapUtil;
3131using apollo::common::PathPoint;
32+ using apollo::hdmap::CrosswalkInfoConstPtr;
3233using apollo::hdmap::JunctionInfoConstPtr;
3334using apollo::hdmap::PNCJunctionInfoConstPtr;
3435using apollo::hdmap::SignalInfoConstPtr;
@@ -68,6 +69,22 @@ bool GetJunction(const PathPoint& point, std::string* junction_id) {
6869 return false ;
6970}
7071
72+ bool GetCrosswalk (const PathPoint& point, std::string* crosswalk_id) {
73+ common::PointENU hdmap_point;
74+ hdmap_point.set_x (point.x ());
75+ hdmap_point.set_y (point.y ());
76+ std::vector<CrosswalkInfoConstPtr> crosswalks;
77+ if (HDMapUtil::BaseMap ().GetCrosswalks (hdmap_point,
78+ FLAGS_search_radius,
79+ &crosswalks) == 0 ) {
80+ if (crosswalks.size () > 0 ) {
81+ *crosswalk_id = crosswalks.front ()->id ().id ();
82+ return true ;
83+ }
84+ }
85+ return false ;
86+ }
87+
7188bool GetSignal (const PathPoint& point, std::string* signal_id) {
7289 common::PointENU hdmap_point;
7390 hdmap_point.set_x (point.x ());
@@ -97,6 +114,8 @@ void CloseToJunctionTeller::GetOverlaps(const ADCTrajectory& adc_trajectory) {
97114
98115 junction_id_.clear ();
99116 junction_distance_ = -1 ;
117+ crosswalk_id_.clear ();
118+ crosswalk_distance_ = -1 ;
100119 signal_id_.clear ();
101120 signal_distance_ = -1 ;
102121 for (const auto & point : adc_trajectory.trajectory_point ()) {
@@ -130,6 +149,15 @@ void CloseToJunctionTeller::GetOverlaps(const ADCTrajectory& adc_trajectory) {
130149 }
131150 }
132151
152+ // crosswalk
153+ if (crosswalk_id_.empty () || crosswalk_distance_ < 0 ) {
154+ std::string crosswalk_id;
155+ if (GetCrosswalk (path_point, &crosswalk_id)) {
156+ crosswalk_id_ = crosswalk_id;
157+ crosswalk_distance_ = path_point.s () - s_start;
158+ }
159+ }
160+
133161 // signal
134162 if (signal_id_.empty () || signal_distance_ < 0 ) {
135163 std::string signal_id;
@@ -172,6 +200,19 @@ void CloseToJunctionTeller::Update(Stories* stories) {
172200 stories->clear_close_to_junction ();
173201 }
174202
203+ // CloseToCrosswalk
204+ if (!crosswalk_id_.empty () && crosswalk_distance_ >= 0 ) {
205+ if (!stories->has_close_to_crosswalk ()) {
206+ AINFO << " Enter CloseToCrosswalk story" ;
207+ }
208+ auto * story = stories->mutable_close_to_crosswalk ();
209+ story->set_id (crosswalk_id_);
210+ story->set_distance (crosswalk_distance_);
211+ } else if (stories->has_close_to_crosswalk ()) {
212+ AINFO << " Exit CloseToCrosswalk story" ;
213+ stories->clear_close_to_crosswalk ();
214+ }
215+
175216 // CloseToSignal
176217 if (!signal_id_.empty () && signal_distance_ >= 0 ) {
177218 if (!stories->has_close_to_signal ()) {
@@ -181,7 +222,7 @@ void CloseToJunctionTeller::Update(Stories* stories) {
181222 story->set_id (signal_id_);
182223 story->set_distance (signal_distance_);
183224 } else if (stories->has_close_to_signal ()) {
184- AINFO << " Exit CloseToJunction story" ;
225+ AINFO << " Exit CloseToSignal story" ;
185226 stories->clear_close_to_signal ();
186227 }
187228}
0 commit comments