47 {
48 CHECK_NOTNULL(speed_limit_data);
49
52 PrintCurves print_curve;
53 for (uint32_t i = 0; i < discretized_path.size(); ++i) {
54 const double path_s = discretized_path.at(i).s();
55 const double reference_line_s = frenet_path.at(i).s();
56 if (reference_line_s > reference_line_.
Length()) {
57 AWARN <<
"path w.r.t. reference line at [" << reference_line_s
58 << "] is LARGER than reference_line_ length ["
59 << reference_line_.
Length() <<
"]. Please debug before proceeding.";
60 break;
61 }
62
63
64 double speed_limit_from_reference_line =
66 print_curve.AddPoint("speed_limit_from_ref", path_s,
67 speed_limit_from_reference_line);
68
69
70 const double speed_limit_from_centripetal_acc =
72 std::fmax(std::fabs(discretized_path.at(i).kappa()),
74 print_curve.AddPoint("speed_limit_from_centripetal_acc", path_s,
75 speed_limit_from_centripetal_acc);
76
77
78
79 double speed_limit_from_nearby_obstacles =
80 std::numeric_limits<double>::max();
81 const double collision_safety_range =
83 for (const auto* ptr_obstacle : obstacles.Items()) {
84 if (ptr_obstacle->IsVirtual()) {
85 continue;
86 }
87 if (!ptr_obstacle->LateralDecision().has_nudge()) {
88 continue;
89 }
90
91
92
93
94
95
96
97
98
99
100 const double vehicle_front_s =
102 const double vehicle_back_s =
104 const double obstacle_front_s =
105 ptr_obstacle->PerceptionSLBoundary().end_s();
106 const double obstacle_back_s =
107 ptr_obstacle->PerceptionSLBoundary().start_s();
108
109 if (vehicle_front_s < obstacle_back_s ||
110 vehicle_back_s > obstacle_front_s) {
111 continue;
112 }
113
114 const auto& nudge_decision = ptr_obstacle->LateralDecision().nudge();
115
116
117 const double frenet_point_l = frenet_path.at(i).l();
118
119
120 bool is_close_on_left =
121 (nudge_decision.type() == ObjectNudge::LEFT_NUDGE) &&
123 collision_safety_range <
124 ptr_obstacle->PerceptionSLBoundary().end_l());
125
126
127 bool is_close_on_right =
128 (nudge_decision.type() == ObjectNudge::RIGHT_NUDGE) &&
129 (ptr_obstacle->PerceptionSLBoundary().start_l() -
130 collision_safety_range <
132
133
134 if (is_close_on_left || is_close_on_right) {
135 double nudge_speed_ratio = 1.0;
136 if (ptr_obstacle->IsStatic()) {
137 nudge_speed_ratio =
139 } else {
140 nudge_speed_ratio =
142 }
143 speed_limit_from_nearby_obstacles =
144 nudge_speed_ratio * speed_limit_from_reference_line;
145 break;
146 }
147 }
148
149 double curr_speed_limit = 0.0;
151 curr_speed_limit =
153 std::min({speed_limit_from_reference_line,
154 speed_limit_from_centripetal_acc,
155 speed_limit_from_nearby_obstacles}));
156 } else {
157 curr_speed_limit =
159 std::min({speed_limit_from_reference_line,
160 speed_limit_from_centripetal_acc}));
161 }
162 if (speed_limit_from_nearby_obstacles <
163 std::numeric_limits<double>::max()) {
164 print_curve.AddPoint("speed_limit_from_nearby_obstacles", path_s,
165 speed_limit_from_nearby_obstacles);
166 }
167 speed_limit_data->AppendSpeedLimit(path_s, curr_speed_limit);
168 print_curve.AddPoint("curr_speed_limit", path_s, curr_speed_limit);
169 }
170 print_curve.PrintToLog();
172}
static Status OK()
generate a success status.
const FrenetFramePath & frenet_frame_path() const
const DiscretizedPath & discretized_path() const
double GetSpeedLimitFromS(const double s) const
optional double left_edge_to_center
optional double back_edge_to_center
optional double front_edge_to_center
optional double right_edge_to_center
optional double lowest_speed
optional double collision_safety_range
optional double dynamic_obs_nudge_speed_ratio
optional double max_centric_acceleration_limit
optional bool enable_nudge_slowdown
optional double minimal_kappa
optional double static_obs_nudge_speed_ratio