Skip to content

Commit 2637566

Browse files
committed
storytelling: add CloseToCrosswalk
1 parent e66168e commit 2637566

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

modules/storytelling/proto/story.proto

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ package apollo.storytelling;
44

55
import "modules/common/proto/header.proto";
66

7-
// TODO(xiaoxq): State triggering conditions.
8-
message ProceedWithCaution {
7+
message CloseToCrosswalk {
8+
optional string id = 1;
9+
optional double distance = 2 [default = nan];
910
}
1011

11-
// Triggered when we are close to a junction.
1212
message CloseToJunction {
1313
enum JunctionType {
1414
PNC_JUNCTION = 1;
@@ -31,7 +31,7 @@ message CloseToSignal {
3131
message Stories {
3232
optional apollo.common.Header header = 1;
3333

34-
optional ProceedWithCaution proceed_with_caution = 2;
34+
optional CloseToCrosswalk close_to_crosswalk = 2;
3535
optional CloseToJunction close_to_junction = 3;
3636
optional CloseToSignal close_to_signal = 4;
3737
}

modules/storytelling/story_tellers/close_to_junction_teller.cc

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace {
2929

3030
using apollo::hdmap::HDMapUtil;
3131
using apollo::common::PathPoint;
32+
using apollo::hdmap::CrosswalkInfoConstPtr;
3233
using apollo::hdmap::JunctionInfoConstPtr;
3334
using apollo::hdmap::PNCJunctionInfoConstPtr;
3435
using 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+
7188
bool 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
}

modules/storytelling/story_tellers/close_to_junction_teller.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class CloseToJunctionTeller : public BaseTeller {
3636
std::string junction_id_;
3737
CloseToJunction::JunctionType junction_type_;
3838
double junction_distance_;
39+
std::string crosswalk_id_;
40+
double crosswalk_distance_;
3941
std::string signal_id_;
4042
double signal_distance_;
4143
};

0 commit comments

Comments
 (0)