Skip to content

Commit cbaaa69

Browse files
authored
refactor(avoidance): parameterize magic number (#4116)
Signed-off-by: satoshi-ota <satoshi.ota928@gmail.com>
1 parent 365f16e commit cbaaa69

File tree

6 files changed

+19
-12
lines changed

6 files changed

+19
-12
lines changed

planning/behavior_path_planner/config/avoidance/avoidance.param.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
lateral:
139139
lateral_execution_threshold: 0.499 # [m]
140140
lateral_small_shift_threshold: 0.101 # [m]
141+
lateral_avoid_check_threshold: 0.1 # [m]
141142
road_shoulder_safety_margin: 0.3 # [m]
142143
max_right_shift_length: 5.0
143144
max_left_shift_length: 5.0

planning/behavior_path_planner/include/behavior_path_planner/utils/avoidance/avoidance_module_data.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ struct AvoidanceParameters
248248
// line.
249249
double lateral_small_shift_threshold;
250250

251+
// use for judge if the ego is shifting or not.
252+
double lateral_avoid_check_threshold;
253+
251254
// For shift line generation process. The continuous shift length is quantized by this value.
252255
double quantize_filter_threshold;
253256

@@ -460,8 +463,6 @@ struct AvoidancePlanningData
460463

461464
bool safe{false};
462465

463-
bool avoiding_now{false};
464-
465466
bool avoid_required{false};
466467

467468
bool yield_required{false};

planning/behavior_path_planner/include/behavior_path_planner/utils/avoidance/helper.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ class AvoidanceHelper
224224
return std::numeric_limits<double>::max();
225225
}
226226

227+
bool isShifted() const
228+
{
229+
return std::abs(getEgoShift()) > parameters_->lateral_avoid_check_threshold;
230+
}
231+
227232
bool isInitialized() const
228233
{
229234
if (prev_spline_shift_path_.path.points.empty()) {

planning/behavior_path_planner/src/marker_utils/avoidance/debug.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,7 @@ MarkerArray createEgoStatusMarkerArray(
200200
{
201201
std::ostringstream string_stream;
202202
string_stream << std::fixed << std::setprecision(2) << std::boolalpha;
203-
string_stream << "avoid_now:" << data.avoiding_now << ","
204-
<< "avoid_req:" << data.avoid_required << ","
203+
string_stream << "avoid_req:" << data.avoid_required << ","
205204
<< "yield_req:" << data.yield_required << ","
206205
<< "safe:" << data.safe;
207206
marker.text = string_stream.str();

planning/behavior_path_planner/src/scene_module/avoidance/avoidance_module.cpp

+5-8
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ ObjectData AvoidanceModule::createObjectData(
379379
bool AvoidanceModule::canYieldManeuver(const AvoidancePlanningData & data) const
380380
{
381381
// transit yield maneuver only when the avoidance maneuver is not initiated.
382-
if (data.avoiding_now) {
382+
if (helper_.isShifted()) {
383383
return false;
384384
}
385385

@@ -413,9 +413,6 @@ bool AvoidanceModule::canYieldManeuver(const AvoidancePlanningData & data) const
413413

414414
void AvoidanceModule::fillShiftLine(AvoidancePlanningData & data, DebugData & debug) const
415415
{
416-
constexpr double AVOIDING_SHIFT_THR = 0.1;
417-
data.avoiding_now = std::abs(helper_.getEgoShift()) > AVOIDING_SHIFT_THR;
418-
419416
auto path_shifter = path_shifter_;
420417

421418
/**
@@ -578,7 +575,7 @@ void AvoidanceModule::fillDebugData(const AvoidancePlanningData & data, DebugDat
578575
return;
579576
}
580577

581-
if (data.avoiding_now) {
578+
if (helper_.isShifted()) {
582579
return;
583580
}
584581

@@ -3189,7 +3186,7 @@ void AvoidanceModule::insertWaitPoint(
31893186
return;
31903187
}
31913188

3192-
if (data.avoiding_now) {
3189+
if (helper_.isShifted()) {
31933190
return;
31943191
}
31953192

@@ -3280,7 +3277,7 @@ void AvoidanceModule::insertYieldVelocity(ShiftedPath & shifted_path) const
32803277
return;
32813278
}
32823279

3283-
if (data.avoiding_now) {
3280+
if (helper_.isShifted()) {
32843281
return;
32853282
}
32863283

@@ -3299,7 +3296,7 @@ void AvoidanceModule::insertPrepareVelocity(ShiftedPath & shifted_path) const
32993296
}
33003297

33013298
// insert slow down speed only when the avoidance maneuver is not initiated.
3302-
if (data.avoiding_now) {
3299+
if (helper_.isShifted()) {
33033300
return;
33043301
}
33053302

planning/behavior_path_planner/src/scene_module/avoidance/manager.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ AvoidanceModuleManager::AvoidanceModuleManager(
156156
p.lateral_execution_threshold = get_parameter<double>(node, ns + "lateral_execution_threshold");
157157
p.lateral_small_shift_threshold =
158158
get_parameter<double>(node, ns + "lateral_small_shift_threshold");
159+
p.lateral_avoid_check_threshold =
160+
get_parameter<double>(node, ns + "lateral_avoid_check_threshold");
159161
p.max_right_shift_length = get_parameter<double>(node, ns + "max_right_shift_length");
160162
p.max_left_shift_length = get_parameter<double>(node, ns + "max_left_shift_length");
161163
}
@@ -302,6 +304,8 @@ void AvoidanceModuleManager::updateModuleParams(const std::vector<rclcpp::Parame
302304
parameters, ns + "lateral_execution_threshold", p->lateral_execution_threshold);
303305
updateParam<double>(
304306
parameters, ns + "lateral_small_shift_threshold", p->lateral_small_shift_threshold);
307+
updateParam<double>(
308+
parameters, ns + "lateral_avoid_check_threshold", p->lateral_avoid_check_threshold);
305309
updateParam<double>(
306310
parameters, ns + "road_shoulder_safety_margin", p->road_shoulder_safety_margin);
307311
}

0 commit comments

Comments
 (0)