Skip to content

Commit 52f4b3e

Browse files
authored
refactor(avoidance): rebuild object info list (#6913)
* refactor(avoidance): rebuild object info structure Signed-off-by: satoshi-ota <satoshi.ota928@gmail.com> * refactor(avoidance): add helper function to unify same process Signed-off-by: satoshi-ota <satoshi.ota928@gmail.com> * refactor(avoidance): remove unused header Signed-off-by: satoshi-ota <satoshi.ota928@gmail.com> --------- Signed-off-by: satoshi-ota <satoshi.ota928@gmail.com>
1 parent 7f9a322 commit 52f4b3e

File tree

8 files changed

+122
-97
lines changed

8 files changed

+122
-97
lines changed

planning/behavior_path_avoidance_by_lane_change_module/src/scene.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ void AvoidanceByLaneChange::fillAvoidanceTargetObjects(
164164
[](const auto & object) {
165165
ObjectData other_object;
166166
other_object.object = object;
167-
other_object.reason = "OutOfTargetArea";
167+
other_object.info = ObjectInfo::OUT_OF_TARGET_AREA;
168168
return other_object;
169169
});
170170
}

planning/behavior_path_avoidance_module/include/behavior_path_avoidance_module/data_structs.hpp

+30-2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,34 @@ using behavior_path_planner::utils::path_safety_checker::CollisionCheckDebug;
5353

5454
using route_handler::Direction;
5555

56+
enum class ObjectInfo {
57+
NONE = 0,
58+
// ignore reasons
59+
OUT_OF_TARGET_AREA,
60+
FURTHER_THAN_THRESHOLD,
61+
FURTHER_THAN_GOAL,
62+
IS_NOT_TARGET_OBJECT,
63+
IS_NOT_PARKING_OBJECT,
64+
TOO_NEAR_TO_CENTERLINE,
65+
TOO_NEAR_TO_GOAL,
66+
MOVING_OBJECT,
67+
UNSTABLE_OBJECT,
68+
CROSSWALK_USER,
69+
ENOUGH_LATERAL_DISTANCE,
70+
LESS_THAN_EXECUTION_THRESHOLD,
71+
PARALLEL_TO_EGO_LANE,
72+
MERGING_TO_EGO_LANE,
73+
DEVIATING_FROM_EGO_LANE,
74+
// unavoidable reasons
75+
NEED_DECELERATION,
76+
SAME_DIRECTION_SHIFT,
77+
INSUFFICIENT_DRIVABLE_SPACE,
78+
INSUFFICIENT_LONGITUDINAL_DISTANCE,
79+
INVALID_SHIFT_LINE,
80+
// others
81+
AMBIGUOUS_STOPPED_VEHICLE,
82+
};
83+
5684
struct ObjectParameter
5785
{
5886
bool is_avoidance_target{false};
@@ -423,8 +451,8 @@ struct ObjectData // avoidance target
423451
// overhang points (sort by distance)
424452
std::vector<std::pair<double, Point>> overhang_points{};
425453

426-
// unavoidable reason
427-
std::string reason{};
454+
// object detail info
455+
ObjectInfo info{ObjectInfo::NONE};
428456

429457
// lateral avoid margin
430458
std::optional<double> avoid_margin{std::nullopt};

planning/behavior_path_avoidance_module/include/behavior_path_avoidance_module/debug.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ using behavior_path_planner::AvoidancePlanningData;
3131
using behavior_path_planner::AvoidLineArray;
3232
using behavior_path_planner::DebugData;
3333
using behavior_path_planner::ObjectDataArray;
34+
using behavior_path_planner::ObjectInfo;
3435
using behavior_path_planner::PathShifter;
3536
using behavior_path_planner::ShiftLineArray;
3637
using geometry_msgs::msg::Pose;
@@ -47,7 +48,7 @@ MarkerArray createPredictedVehiclePositions(const PathWithLaneId & path, std::st
4748

4849
MarkerArray createTargetObjectsMarkerArray(const ObjectDataArray & objects, const std::string & ns);
4950

50-
MarkerArray createOtherObjectsMarkerArray(const ObjectDataArray & objects, const std::string & ns);
51+
MarkerArray createOtherObjectsMarkerArray(const ObjectDataArray & objects, const ObjectInfo & info);
5152

5253
MarkerArray createDebugMarkerArray(
5354
const AvoidancePlanningData & data, const PathShifter & shifter, const DebugData & debug);

planning/behavior_path_avoidance_module/include/behavior_path_avoidance_module/helper.hpp

+14
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,20 @@ class AvoidanceHelper
343343
parameters_->closest_distance_to_wait_and_see_for_ambiguous_vehicle;
344344
}
345345

346+
static bool isAbsolutelyNotAvoidable(const ObjectData & object)
347+
{
348+
if (object.is_avoidable) {
349+
return false;
350+
}
351+
352+
// can avoid it after deceleration.
353+
if (object.info == ObjectInfo::NEED_DECELERATION) {
354+
return false;
355+
}
356+
357+
return true;
358+
}
359+
346360
bool isReady(const AvoidLineArray & new_shift_lines, const double current_shift_length) const
347361
{
348362
if (std::abs(current_shift_length) < 1e-3) {

planning/behavior_path_avoidance_module/src/debug.cpp

+31-35
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
#include <magic_enum.hpp>
2222
#include <tier4_autoware_utils/ros/uuid_helper.hpp>
2323

24-
#include <tier4_planning_msgs/msg/avoidance_debug_factor.hpp>
25-
2624
#include <string>
2725
#include <vector>
2826

@@ -176,7 +174,8 @@ MarkerArray createObjectInfoMarkerArray(const ObjectDataArray & objects, std::st
176174
marker.id = uuidToInt32(object.object.object_id);
177175
marker.pose.position.z += 2.0;
178176
std::ostringstream string_stream;
179-
string_stream << object.reason << (object.is_parked ? "(PARKED)" : "");
177+
string_stream << magic_enum::enum_name(object.info) << (object.is_parked ? "(PARKED)" : "");
178+
string_stream << (object.is_ambiguous ? "(WAIT AND SEE)" : "");
180179
marker.text = string_stream.str();
181180
marker.color = createMarkerColor(1.0, 1.0, 1.0, 0.999);
182181
marker.scale = createMarkerScale(0.6, 0.6, 0.6);
@@ -441,14 +440,12 @@ MarkerArray createTargetObjectsMarkerArray(const ObjectDataArray & objects, cons
441440
return msg;
442441
}
443442

444-
MarkerArray createOtherObjectsMarkerArray(const ObjectDataArray & objects, const std::string & ns)
443+
MarkerArray createOtherObjectsMarkerArray(const ObjectDataArray & objects, const ObjectInfo & info)
445444
{
446-
using behavior_path_planner::utils::convertToSnakeCase;
447-
448-
const auto filtered_objects = [&objects, &ns]() {
445+
const auto filtered_objects = [&objects, &info]() {
449446
ObjectDataArray ret{};
450447
for (const auto & o : objects) {
451-
if (o.reason != ns) {
448+
if (o.info != info) {
452449
continue;
453450
}
454451
ret.push_back(o);
@@ -460,18 +457,20 @@ MarkerArray createOtherObjectsMarkerArray(const ObjectDataArray & objects, const
460457
MarkerArray msg;
461458
msg.markers.reserve(filtered_objects.size() * 2);
462459

460+
std::ostringstream string_stream;
461+
string_stream << magic_enum::enum_name(info);
462+
463+
std::string ns = string_stream.str();
464+
transform(ns.begin(), ns.end(), ns.begin(), tolower);
465+
463466
appendMarkerArray(
464467
createObjectsCubeMarkerArray(
465-
filtered_objects, "others_" + convertToSnakeCase(ns) + "_cube",
466-
createMarkerScale(3.0, 1.5, 1.5), createMarkerColor(0.0, 1.0, 0.0, 0.8)),
468+
filtered_objects, "others_" + ns + "_cube", createMarkerScale(3.0, 1.5, 1.5),
469+
createMarkerColor(0.0, 1.0, 0.0, 0.8)),
467470
&msg);
471+
appendMarkerArray(createObjectInfoMarkerArray(filtered_objects, "others_" + ns + "_info"), &msg);
468472
appendMarkerArray(
469-
createObjectInfoMarkerArray(filtered_objects, "others_" + convertToSnakeCase(ns) + "_info"),
470-
&msg);
471-
appendMarkerArray(
472-
createOverhangLaneletMarkerArray(
473-
filtered_objects, "others_" + convertToSnakeCase(ns) + "_overhang_lanelet"),
474-
&msg);
473+
createOverhangLaneletMarkerArray(filtered_objects, "others_" + ns + "_overhang_lanelet"), &msg);
475474

476475
return msg;
477476
}
@@ -528,7 +527,6 @@ MarkerArray createDebugMarkerArray(
528527
using marker_utils::showPolygon;
529528
using marker_utils::showPredictedPath;
530529
using marker_utils::showSafetyCheckInfo;
531-
using tier4_planning_msgs::msg::AvoidanceDebugFactor;
532530

533531
const auto current_time = rclcpp::Clock{RCL_ROS_TIME}.now();
534532
MarkerArray msg;
@@ -564,24 +562,22 @@ MarkerArray createDebugMarkerArray(
564562

565563
// ignore objects
566564
{
567-
addObjects(data.other_objects, AvoidanceDebugFactor::OBJECT_IS_BEHIND_THRESHOLD);
568-
addObjects(data.other_objects, AvoidanceDebugFactor::OBJECT_IS_IN_FRONT_THRESHOLD);
569-
addObjects(data.other_objects, AvoidanceDebugFactor::OBJECT_IS_NOT_TYPE);
570-
addObjects(data.other_objects, AvoidanceDebugFactor::OBJECT_BEHIND_PATH_GOAL);
571-
addObjects(data.other_objects, AvoidanceDebugFactor::TOO_NEAR_TO_CENTERLINE);
572-
addObjects(data.other_objects, AvoidanceDebugFactor::NOT_PARKING_OBJECT);
573-
addObjects(data.other_objects, std::string("MovingObject"));
574-
addObjects(data.other_objects, std::string("CrosswalkUser"));
575-
addObjects(data.other_objects, std::string("OutOfTargetArea"));
576-
addObjects(data.other_objects, std::string("NotNeedAvoidance"));
577-
addObjects(data.other_objects, std::string("LessThanExecutionThreshold"));
578-
addObjects(data.other_objects, std::string("TooNearToGoal"));
579-
addObjects(data.other_objects, std::string("ParallelToEgoLane"));
580-
addObjects(data.other_objects, std::string("MergingToEgoLane"));
581-
addObjects(data.other_objects, std::string("DeviatingFromEgoLane"));
582-
addObjects(data.other_objects, std::string("UnstableObject"));
583-
addObjects(data.other_objects, std::string("AmbiguousStoppedVehicle"));
584-
addObjects(data.other_objects, std::string("AmbiguousStoppedVehicle(wait-and-see)"));
565+
addObjects(data.other_objects, ObjectInfo::FURTHER_THAN_THRESHOLD);
566+
addObjects(data.other_objects, ObjectInfo::IS_NOT_TARGET_OBJECT);
567+
addObjects(data.other_objects, ObjectInfo::FURTHER_THAN_GOAL);
568+
addObjects(data.other_objects, ObjectInfo::TOO_NEAR_TO_CENTERLINE);
569+
addObjects(data.other_objects, ObjectInfo::IS_NOT_PARKING_OBJECT);
570+
addObjects(data.other_objects, ObjectInfo::MOVING_OBJECT);
571+
addObjects(data.other_objects, ObjectInfo::CROSSWALK_USER);
572+
addObjects(data.other_objects, ObjectInfo::OUT_OF_TARGET_AREA);
573+
addObjects(data.other_objects, ObjectInfo::ENOUGH_LATERAL_DISTANCE);
574+
addObjects(data.other_objects, ObjectInfo::LESS_THAN_EXECUTION_THRESHOLD);
575+
addObjects(data.other_objects, ObjectInfo::TOO_NEAR_TO_GOAL);
576+
addObjects(data.other_objects, ObjectInfo::PARALLEL_TO_EGO_LANE);
577+
addObjects(data.other_objects, ObjectInfo::MERGING_TO_EGO_LANE);
578+
addObjects(data.other_objects, ObjectInfo::DEVIATING_FROM_EGO_LANE);
579+
addObjects(data.other_objects, ObjectInfo::UNSTABLE_OBJECT);
580+
addObjects(data.other_objects, ObjectInfo::AMBIGUOUS_STOPPED_VEHICLE);
585581
}
586582

587583
// shift line pre-process

planning/behavior_path_avoidance_module/src/scene.cpp

+9-18
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include <tier4_autoware_utils/ros/marker_helper.hpp>
3232

3333
#include "tier4_planning_msgs/msg/detail/avoidance_debug_msg_array__struct.hpp"
34-
#include <tier4_planning_msgs/msg/detail/avoidance_debug_factor__struct.hpp>
3534

3635
#include <algorithm>
3736
#include <limits>
@@ -52,7 +51,6 @@ using tier4_autoware_utils::calcLateralDeviation;
5251
using tier4_autoware_utils::getPoint;
5352
using tier4_autoware_utils::getPose;
5453
using tier4_autoware_utils::toHexString;
55-
using tier4_planning_msgs::msg::AvoidanceDebugFactor;
5654

5755
namespace
5856
{
@@ -119,9 +117,8 @@ bool AvoidanceModule::isExecutionRequested() const
119117
}
120118

121119
return std::any_of(
122-
avoid_data_.target_objects.begin(), avoid_data_.target_objects.end(), [](const auto & o) {
123-
return o.is_avoidable || o.reason == AvoidanceDebugFactor::TOO_LARGE_JERK;
124-
});
120+
avoid_data_.target_objects.begin(), avoid_data_.target_objects.end(),
121+
[this](const auto & o) { return !helper_->isAbsolutelyNotAvoidable(o); });
125122
}
126123

127124
bool AvoidanceModule::isExecutionReady() const
@@ -136,10 +133,9 @@ bool AvoidanceModule::isExecutionReady() const
136133

137134
bool AvoidanceModule::isSatisfiedSuccessCondition(const AvoidancePlanningData & data) const
138135
{
139-
const bool has_avoidance_target =
140-
std::any_of(data.target_objects.begin(), data.target_objects.end(), [](const auto & o) {
141-
return o.is_avoidable || o.reason == AvoidanceDebugFactor::TOO_LARGE_JERK;
142-
});
136+
const bool has_avoidance_target = std::any_of(
137+
data.target_objects.begin(), data.target_objects.end(),
138+
[this](const auto & o) { return !helper_->isAbsolutelyNotAvoidable(o); });
143139

144140
if (has_avoidance_target) {
145141
return false;
@@ -337,7 +333,7 @@ void AvoidanceModule::fillAvoidanceTargetObjects(
337333

338334
for (const auto & object : object_outside_target_lane.objects) {
339335
ObjectData other_object = createObjectData(data, object);
340-
other_object.reason = "OutOfTargetArea";
336+
other_object.info = ObjectInfo::OUT_OF_TARGET_AREA;
341337
data.other_objects.push_back(other_object);
342338
}
343339

@@ -367,8 +363,6 @@ void AvoidanceModule::fillAvoidanceTargetObjects(
367363
debug_info.object_id = toHexString(o.object.object_id);
368364
debug_info.longitudinal_distance = o.longitudinal;
369365
debug_info.lateral_distance_from_centerline = o.to_centerline;
370-
debug_info.allow_avoidance = o.reason == "";
371-
debug_info.failed_reason = o.reason;
372366
debug_info_array.push_back(debug_info);
373367
};
374368

@@ -530,12 +524,11 @@ void AvoidanceModule::fillEgoStatus(
530524
* if the both of following two conditions are satisfied, the module surely avoid the object.
531525
* Condition1: there is risk to collide with object without avoidance.
532526
* Condition2: there is enough space to avoid.
533-
* In TOO_LARGE_JERK condition, it is possible to avoid object by deceleration even if the flag
527+
* In NEED_DECELERATION condition, it is possible to avoid object by deceleration even if the flag
534528
* is_avoidable is FALSE. So, the module inserts stop point for such a object.
535529
*/
536530
for (const auto & o : data.target_objects) {
537-
const auto enough_space = o.is_avoidable || o.reason == AvoidanceDebugFactor::TOO_LARGE_JERK;
538-
if (o.avoid_required && enough_space) {
531+
if (o.avoid_required && !helper_->isAbsolutelyNotAvoidable(o)) {
539532
data.avoid_required = true;
540533
data.stop_target_object = o;
541534
data.to_stop_line = o.to_stop_line;
@@ -1667,9 +1660,7 @@ void AvoidanceModule::insertPrepareVelocity(ShiftedPath & shifted_path) const
16671660
return;
16681661
}
16691662

1670-
const auto enough_space =
1671-
object.value().is_avoidable || object.value().reason == AvoidanceDebugFactor::TOO_LARGE_JERK;
1672-
if (!enough_space) {
1663+
if (helper_->isAbsolutelyNotAvoidable(object.value())) {
16731664
return;
16741665
}
16751666

planning/behavior_path_avoidance_module/src/shift_line_generator.cpp

+9-12
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,11 @@
1919

2020
#include <tier4_autoware_utils/ros/uuid_helper.hpp>
2121

22-
#include <tier4_planning_msgs/msg/detail/avoidance_debug_factor__struct.hpp>
23-
2422
namespace behavior_path_planner::utils::avoidance
2523
{
2624

2725
using tier4_autoware_utils::generateUUID;
2826
using tier4_autoware_utils::getPoint;
29-
using tier4_planning_msgs::msg::AvoidanceDebugFactor;
3027

3128
namespace
3229
{
@@ -182,7 +179,7 @@ AvoidOutlines ShiftLineGenerator::generateAvoidOutline(
182179

183180
// prepare distance is not enough. unavoidable.
184181
if (avoidance_distance < 1e-3) {
185-
object.reason = AvoidanceDebugFactor::REMAINING_DISTANCE_LESS_THAN_ZERO;
182+
object.info = ObjectInfo::INSUFFICIENT_LONGITUDINAL_DISTANCE;
186183
return std::nullopt;
187184
}
188185

@@ -200,10 +197,10 @@ AvoidOutlines ShiftLineGenerator::generateAvoidOutline(
200197
// avoidance distance is not enough. unavoidable.
201198
if (!isBestEffort(parameters_->policy_deceleration)) {
202199
if (avoidance_distance < helper_->getMinAvoidanceDistance(avoiding_shift) + LON_DIST_BUFFER) {
203-
object.reason = AvoidanceDebugFactor::REMAINING_DISTANCE_LESS_THAN_ZERO;
200+
object.info = ObjectInfo::INSUFFICIENT_LONGITUDINAL_DISTANCE;
204201
return std::nullopt;
205202
} else {
206-
object.reason = AvoidanceDebugFactor::TOO_LARGE_JERK;
203+
object.info = ObjectInfo::NEED_DECELERATION;
207204
return std::nullopt;
208205
}
209206
}
@@ -213,7 +210,7 @@ AvoidOutlines ShiftLineGenerator::generateAvoidOutline(
213210
avoidance_distance, helper_->getLateralMaxJerkLimit(), helper_->getAvoidanceEgoSpeed());
214211

215212
if (std::abs(feasible_relative_shift_length) < parameters_->lateral_execution_threshold) {
216-
object.reason = "LessThanExecutionThreshold";
213+
object.info = ObjectInfo::LESS_THAN_EXECUTION_THRESHOLD;
217214
return std::nullopt;
218215
}
219216

@@ -224,7 +221,7 @@ AvoidOutlines ShiftLineGenerator::generateAvoidOutline(
224221
if (
225222
avoidance_distance <
226223
helper_->getMinAvoidanceDistance(feasible_shift_length) + LON_DIST_BUFFER) {
227-
object.reason = AvoidanceDebugFactor::REMAINING_DISTANCE_LESS_THAN_ZERO;
224+
object.info = ObjectInfo::INSUFFICIENT_LONGITUDINAL_DISTANCE;
228225
return std::nullopt;
229226
}
230227

@@ -238,7 +235,7 @@ AvoidOutlines ShiftLineGenerator::generateAvoidOutline(
238235
0.5 * data_->parameters.vehicle_width + lateral_hard_margin;
239236
if (infeasible) {
240237
RCLCPP_DEBUG(rclcpp::get_logger(""), "feasible shift length is not enough to avoid. ");
241-
object.reason = AvoidanceDebugFactor::TOO_LARGE_JERK;
238+
object.info = ObjectInfo::NEED_DECELERATION;
242239
return std::nullopt;
243240
}
244241

@@ -254,7 +251,7 @@ AvoidOutlines ShiftLineGenerator::generateAvoidOutline(
254251
AvoidOutlines outlines;
255252
for (auto & o : data.target_objects) {
256253
if (!o.avoid_margin.has_value()) {
257-
o.reason = AvoidanceDebugFactor::INSUFFICIENT_LATERAL_MARGIN;
254+
o.info = ObjectInfo::INSUFFICIENT_DRIVABLE_SPACE;
258255
if (o.avoid_required && is_forward_object(o)) {
259256
break;
260257
} else {
@@ -266,7 +263,7 @@ AvoidOutlines ShiftLineGenerator::generateAvoidOutline(
266263
const auto desire_shift_length =
267264
helper_->getShiftLength(o, is_object_on_right, o.avoid_margin.value());
268265
if (utils::avoidance::isSameDirectionShift(is_object_on_right, desire_shift_length)) {
269-
o.reason = AvoidanceDebugFactor::SAME_DIRECTION_SHIFT;
266+
o.info = ObjectInfo::SAME_DIRECTION_SHIFT;
270267
if (o.avoid_required && is_forward_object(o)) {
271268
break;
272269
} else {
@@ -377,7 +374,7 @@ AvoidOutlines ShiftLineGenerator::generateAvoidOutline(
377374
} else if (is_valid_shift_line(al_avoid) && is_valid_shift_line(al_return)) {
378375
outlines.emplace_back(al_avoid, al_return);
379376
} else {
380-
o.reason = "InvalidShiftLine";
377+
o.info = ObjectInfo::INVALID_SHIFT_LINE;
381378
continue;
382379
}
383380

0 commit comments

Comments
 (0)