Skip to content

Commit 050fa29

Browse files
authored
fix(static_obstacle_avoidance): stop position is unstable (#7880)
fix(static_obstacle_avoidance): fix stop position Signed-off-by: satoshi-ota <satoshi.ota928@gmail.com>
1 parent 12b31ab commit 050fa29

File tree

7 files changed

+119
-86
lines changed

7 files changed

+119
-86
lines changed

planning/behavior_path_planner/autoware_behavior_path_avoidance_by_lane_change_module/src/scene.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,8 @@ void AvoidanceByLaneChange::updateSpecialData()
113113
: Direction::RIGHT;
114114
}
115115

116-
utils::static_obstacle_avoidance::updateRegisteredObject(
117-
registered_objects_, avoidance_data_.target_objects, p);
118-
utils::static_obstacle_avoidance::compensateDetectionLost(
119-
registered_objects_, avoidance_data_.target_objects, avoidance_data_.other_objects);
116+
utils::static_obstacle_avoidance::compensateLostTargetObjects(
117+
registered_objects_, avoidance_data_, clock_.now(), planner_data_, p);
120118

121119
std::sort(
122120
avoidance_data_.target_objects.begin(), avoidance_data_.target_objects.end(),

planning/behavior_path_planner/autoware_behavior_path_static_obstacle_avoidance_module/include/autoware/behavior_path_static_obstacle_avoidance_module/debug.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ MarkerArray createTargetObjectsMarkerArray(const ObjectDataArray & objects, cons
4747
MarkerArray createOtherObjectsMarkerArray(
4848
const ObjectDataArray & objects, const ObjectInfo & info, const bool verbose);
4949

50+
MarkerArray createStopTargetObjectMarkerArray(const AvoidancePlanningData & data);
51+
5052
MarkerArray createDebugMarkerArray(
5153
const AvoidancePlanningData & data, const PathShifter & shifter, const DebugData & debug,
5254
const std::shared_ptr<AvoidanceParameters> & parameters);

planning/behavior_path_planner/autoware_behavior_path_static_obstacle_avoidance_module/include/autoware/behavior_path_static_obstacle_avoidance_module/scene.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,12 @@ class StaticObstacleAvoidanceModule : public SceneModuleInterface
266266
*/
267267
void fillAvoidanceTargetObjects(AvoidancePlanningData & data, DebugData & debug) const;
268268

269+
/**
270+
* @brief fill additional data which are necessary to plan avoidance path/velocity.
271+
* @param avoidance target objects.
272+
*/
273+
void fillAvoidanceTargetData(ObjectDataArray & objects) const;
274+
269275
/**
270276
* @brief fill candidate shift lines.
271277
* @param avoidance data.

planning/behavior_path_planner/autoware_behavior_path_static_obstacle_avoidance_module/include/autoware/behavior_path_static_obstacle_avoidance_module/utils.hpp

+4-7
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,12 @@ void fillObjectStoppableJudge(
118118
ObjectData & object_data, const ObjectDataArray & registered_objects,
119119
const double feasible_stop_distance, const std::shared_ptr<AvoidanceParameters> & parameters);
120120

121-
void updateRegisteredObject(
122-
ObjectDataArray & registered_objects, const ObjectDataArray & now_objects,
123-
const std::shared_ptr<AvoidanceParameters> & parameters);
124-
125121
void updateClipObject(ObjectDataArray & clip_objects, AvoidancePlanningData & data);
126122

127-
void compensateDetectionLost(
128-
const ObjectDataArray & registered_objects, ObjectDataArray & now_objects,
129-
ObjectDataArray & other_objects);
123+
void compensateLostTargetObjects(
124+
ObjectDataArray & stored_objects, AvoidancePlanningData & data, const rclcpp::Time & now,
125+
const std::shared_ptr<const PlannerData> & planner_data,
126+
const std::shared_ptr<AvoidanceParameters> & parameters);
130127

131128
void filterTargetObjects(
132129
ObjectDataArray & objects, AvoidancePlanningData & data, const double forward_detection_range,

planning/behavior_path_planner/autoware_behavior_path_static_obstacle_avoidance_module/src/debug.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,23 @@ MarkerArray createOtherObjectsMarkerArray(
466466
return msg;
467467
}
468468

469+
MarkerArray createStopTargetObjectMarkerArray(const AvoidancePlanningData & data)
470+
{
471+
MarkerArray msg;
472+
473+
if (!data.stop_target_object.has_value()) {
474+
return msg;
475+
}
476+
477+
appendMarkerArray(
478+
createObjectsCubeMarkerArray(
479+
{data.stop_target_object.value()}, "stop_target", createMarkerScale(3.4, 1.9, 1.9),
480+
createMarkerColor(1.0, 0.0, 0.42, 0.5)),
481+
&msg);
482+
483+
return msg;
484+
}
485+
469486
MarkerArray createDrivableBounds(
470487
const AvoidancePlanningData & data, std::string && ns, const float & r, const float & g,
471488
const float & b)

planning/behavior_path_planner/autoware_behavior_path_static_obstacle_avoidance_module/src/scene.cpp

+29-17
Original file line numberDiff line numberDiff line change
@@ -286,16 +286,22 @@ void StaticObstacleAvoidanceModule::fillFundamentalData(
286286
data.to_start_point = utils::static_obstacle_avoidance::calcDistanceToAvoidStartLine(
287287
data.current_lanelets, data.reference_path_rough, planner_data_, parameters_);
288288

289-
// target objects for avoidance
289+
// filter only for the latest detected objects.
290290
fillAvoidanceTargetObjects(data, debug);
291291

292-
// lost object compensation
293-
utils::static_obstacle_avoidance::updateRegisteredObject(
294-
registered_objects_, data.target_objects, parameters_);
295-
utils::static_obstacle_avoidance::compensateDetectionLost(
296-
registered_objects_, data.target_objects, data.other_objects);
292+
// compensate lost object which was avoidance target. if the time hasn't passed more than
293+
// threshold since perception module lost the target yet, this module keeps it as avoidance
294+
// target.
295+
utils::static_obstacle_avoidance::compensateLostTargetObjects(
296+
registered_objects_, data, clock_->now(), planner_data_, parameters_);
297+
298+
// once an object filtered for boundary clipping, this module keeps the information until the end
299+
// of execution.
297300
utils::static_obstacle_avoidance::updateClipObject(clip_objects_, data);
298301

302+
// calculate various data for each target objects.
303+
fillAvoidanceTargetData(data.target_objects);
304+
299305
// sort object order by longitudinal distance
300306
std::sort(data.target_objects.begin(), data.target_objects.end(), [](auto a, auto b) {
301307
return a.longitudinal < b.longitudinal;
@@ -308,8 +314,6 @@ void StaticObstacleAvoidanceModule::fillFundamentalData(
308314
void StaticObstacleAvoidanceModule::fillAvoidanceTargetObjects(
309315
AvoidancePlanningData & data, DebugData & debug) const
310316
{
311-
using utils::static_obstacle_avoidance::fillAvoidanceNecessity;
312-
using utils::static_obstacle_avoidance::fillObjectStoppableJudge;
313317
using utils::static_obstacle_avoidance::filterTargetObjects;
314318
using utils::static_obstacle_avoidance::separateObjectsByPath;
315319
using utils::static_obstacle_avoidance::updateRoadShoulderDistance;
@@ -345,15 +349,6 @@ void StaticObstacleAvoidanceModule::fillAvoidanceTargetObjects(
345349
filterTargetObjects(objects, data, forward_detection_range, planner_data_, parameters_);
346350
updateRoadShoulderDistance(data, planner_data_, parameters_);
347351

348-
// Calculate the distance needed to safely decelerate the ego vehicle to a stop line.
349-
const auto & vehicle_width = planner_data_->parameters.vehicle_width;
350-
const auto feasible_stop_distance = helper_->getFeasibleDecelDistance(0.0, false);
351-
std::for_each(data.target_objects.begin(), data.target_objects.end(), [&, this](auto & o) {
352-
fillAvoidanceNecessity(o, registered_objects_, vehicle_width, parameters_);
353-
o.to_stop_line = calcDistanceToStopLine(o);
354-
fillObjectStoppableJudge(o, registered_objects_, feasible_stop_distance, parameters_);
355-
});
356-
357352
// debug
358353
{
359354
std::vector<AvoidanceDebugMsg> debug_info_array;
@@ -371,6 +366,21 @@ void StaticObstacleAvoidanceModule::fillAvoidanceTargetObjects(
371366
}
372367
}
373368

369+
void StaticObstacleAvoidanceModule::fillAvoidanceTargetData(ObjectDataArray & objects) const
370+
{
371+
using utils::static_obstacle_avoidance::fillAvoidanceNecessity;
372+
using utils::static_obstacle_avoidance::fillObjectStoppableJudge;
373+
374+
// Calculate the distance needed to safely decelerate the ego vehicle to a stop line.
375+
const auto & vehicle_width = planner_data_->parameters.vehicle_width;
376+
const auto feasible_stop_distance = helper_->getFeasibleDecelDistance(0.0, false);
377+
std::for_each(objects.begin(), objects.end(), [&, this](auto & o) {
378+
fillAvoidanceNecessity(o, registered_objects_, vehicle_width, parameters_);
379+
o.to_stop_line = calcDistanceToStopLine(o);
380+
fillObjectStoppableJudge(o, registered_objects_, feasible_stop_distance, parameters_);
381+
});
382+
}
383+
374384
ObjectData StaticObstacleAvoidanceModule::createObjectData(
375385
const AvoidancePlanningData & data, const PredictedObject & object) const
376386
{
@@ -1376,11 +1386,13 @@ void StaticObstacleAvoidanceModule::updateRTCData()
13761386

13771387
void StaticObstacleAvoidanceModule::updateInfoMarker(const AvoidancePlanningData & data) const
13781388
{
1389+
using utils::static_obstacle_avoidance::createStopTargetObjectMarkerArray;
13791390
using utils::static_obstacle_avoidance::createTargetObjectsMarkerArray;
13801391

13811392
info_marker_.markers.clear();
13821393
appendMarkerArray(
13831394
createTargetObjectsMarkerArray(data.target_objects, "target_objects"), &info_marker_);
1395+
appendMarkerArray(createStopTargetObjectMarkerArray(data), &info_marker_);
13841396
}
13851397

13861398
void StaticObstacleAvoidanceModule::updateDebugMarker(

planning/behavior_path_planner/autoware_behavior_path_static_obstacle_avoidance_module/src/utils.cpp

+59-58
Original file line numberDiff line numberDiff line change
@@ -1645,93 +1645,94 @@ void fillObjectStoppableJudge(
16451645
object_data.is_stoppable = same_id_obj->is_stoppable;
16461646
}
16471647

1648-
void updateRegisteredObject(
1649-
ObjectDataArray & registered_objects, const ObjectDataArray & now_objects,
1648+
void compensateLostTargetObjects(
1649+
ObjectDataArray & stored_objects, AvoidancePlanningData & data, const rclcpp::Time & now,
1650+
const std::shared_ptr<const PlannerData> & planner_data,
16501651
const std::shared_ptr<AvoidanceParameters> & parameters)
16511652
{
1652-
const auto updateIfDetectedNow = [&now_objects](auto & registered_object) {
1653-
const auto & n = now_objects;
1654-
const auto r_id = registered_object.object.object_id;
1655-
const auto same_id_obj = std::find_if(
1656-
n.begin(), n.end(), [&r_id](const auto & o) { return o.object.object_id == r_id; });
1653+
const auto include = [](const auto & objects, const auto & search_id) {
1654+
return std::all_of(objects.begin(), objects.end(), [&search_id](const auto & o) {
1655+
return o.object.object_id != search_id;
1656+
});
1657+
};
1658+
1659+
// STEP.1 UPDATE STORED OBJECTS.
1660+
const auto match = [&data](auto & object) {
1661+
const auto & search_id = object.object.object_id;
1662+
const auto same_id_object = std::find_if(
1663+
data.target_objects.begin(), data.target_objects.end(),
1664+
[&search_id](const auto & o) { return o.object.object_id == search_id; });
16571665

16581666
// same id object is detected. update registered.
1659-
if (same_id_obj != n.end()) {
1660-
registered_object = *same_id_obj;
1667+
if (same_id_object != data.target_objects.end()) {
1668+
object = *same_id_object;
16611669
return true;
16621670
}
16631671

1664-
constexpr auto POS_THR = 1.5;
1665-
const auto r_pos = registered_object.getPose();
1666-
const auto similar_pos_obj = std::find_if(n.begin(), n.end(), [&](const auto & o) {
1667-
return calcDistance2d(r_pos, o.getPose()) < POS_THR;
1668-
});
1672+
const auto similar_pos_obj = std::find_if(
1673+
data.target_objects.begin(), data.target_objects.end(), [&object](const auto & o) {
1674+
constexpr auto POS_THR = 1.5;
1675+
return calcDistance2d(object.getPose(), o.getPose()) < POS_THR;
1676+
});
16691677

16701678
// same id object is not detected, but object is found around registered. update registered.
1671-
if (similar_pos_obj != n.end()) {
1672-
registered_object = *similar_pos_obj;
1679+
if (similar_pos_obj != data.target_objects.end()) {
1680+
object = *similar_pos_obj;
16731681
return true;
16741682
}
16751683

16761684
// Same ID nor similar position object does not found.
16771685
return false;
16781686
};
16791687

1680-
const rclcpp::Time now = rclcpp::Clock(RCL_ROS_TIME).now();
1681-
1682-
// -- check registered_objects, remove if lost_count exceeds limit. --
1683-
for (int i = static_cast<int>(registered_objects.size()) - 1; i >= 0; --i) {
1684-
auto & r = registered_objects.at(i);
1685-
1686-
// registered object is not detected this time. lost count up.
1687-
if (!updateIfDetectedNow(r)) {
1688-
r.lost_time = (now - r.last_seen).seconds();
1689-
} else {
1690-
r.last_seen = now;
1691-
r.lost_time = 0.0;
1692-
}
1688+
// STEP1-1: REMOVE EXPIRED OBJECTS.
1689+
const auto itr = std::remove_if(
1690+
stored_objects.begin(), stored_objects.end(), [&now, &match, &parameters](auto & o) {
1691+
if (!match(o)) {
1692+
o.lost_time = (now - o.last_seen).seconds();
1693+
} else {
1694+
o.last_seen = now;
1695+
o.lost_time = 0.0;
1696+
}
16931697

1694-
// lost count exceeds threshold. remove object from register.
1695-
if (r.lost_time > parameters->object_last_seen_threshold) {
1696-
registered_objects.erase(registered_objects.begin() + i);
1697-
}
1698-
}
1698+
return o.lost_time > parameters->object_last_seen_threshold;
1699+
});
16991700

1700-
const auto isAlreadyRegistered = [&](const auto & n_id) {
1701-
const auto & r = registered_objects;
1702-
return std::any_of(
1703-
r.begin(), r.end(), [&n_id](const auto & o) { return o.object.object_id == n_id; });
1704-
};
1701+
stored_objects.erase(itr, stored_objects.end());
17051702

1706-
// -- check now_objects, add it if it has new object id --
1707-
for (const auto & now_obj : now_objects) {
1708-
if (!isAlreadyRegistered(now_obj.object.object_id)) {
1709-
registered_objects.push_back(now_obj);
1703+
// STEP1-2: UPDATE STORED OBJECTS IF THERE ARE NEW OBJECTS.
1704+
for (const auto & current_object : data.target_objects) {
1705+
if (!include(stored_objects, current_object.object.object_id)) {
1706+
stored_objects.push_back(current_object);
17101707
}
17111708
}
1712-
}
17131709

1714-
void compensateDetectionLost(
1715-
const ObjectDataArray & registered_objects, ObjectDataArray & now_objects,
1716-
ObjectDataArray & other_objects)
1717-
{
1718-
const auto isDetectedNow = [&](const auto & r_id) {
1719-
const auto & n = now_objects;
1710+
// STEP2: COMPENSATE CURRENT TARGET OBJECTS
1711+
const auto is_detected = [&](const auto & object_id) {
17201712
return std::any_of(
1721-
n.begin(), n.end(), [&r_id](const auto & o) { return o.object.object_id == r_id; });
1713+
data.target_objects.begin(), data.target_objects.end(),
1714+
[&object_id](const auto & o) { return o.object.object_id == object_id; });
17221715
};
17231716

1724-
const auto isIgnoreObject = [&](const auto & r_id) {
1725-
const auto & n = other_objects;
1717+
const auto is_ignored = [&](const auto & object_id) {
17261718
return std::any_of(
1727-
n.begin(), n.end(), [&r_id](const auto & o) { return o.object.object_id == r_id; });
1719+
data.other_objects.begin(), data.other_objects.end(),
1720+
[&object_id](const auto & o) { return o.object.object_id == object_id; });
17281721
};
17291722

1730-
for (const auto & registered : registered_objects) {
1731-
if (
1732-
!isDetectedNow(registered.object.object_id) && !isIgnoreObject(registered.object.object_id)) {
1733-
now_objects.push_back(registered);
1723+
for (auto & stored_object : stored_objects) {
1724+
if (is_detected(stored_object.object.object_id)) {
1725+
continue;
1726+
}
1727+
if (is_ignored(stored_object.object.object_id)) {
1728+
continue;
17341729
}
1730+
1731+
const auto & ego_pos = planner_data->self_odometry->pose.pose.position;
1732+
fillLongitudinalAndLengthByClosestEnvelopeFootprint(
1733+
data.reference_path_rough, ego_pos, stored_object);
1734+
1735+
data.target_objects.push_back(stored_object);
17351736
}
17361737
}
17371738

0 commit comments

Comments
 (0)