Skip to content

Commit c01ded3

Browse files
soblinsaka1-s
authored andcommitted
chore(intersection): add const to member functions, replace enum with class tag for occlusion (autowarefoundation#6299)
Signed-off-by: Mamoru Sobue <mamoru.sobue@tier4.jp>
1 parent cdeed2b commit c01ded3

7 files changed

+91
-65
lines changed

planning/behavior_velocity_intersection_module/src/object_manager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ void ObjectInfoManager::clearObjects()
240240
parked_objects_.clear();
241241
};
242242

243-
std::vector<std::shared_ptr<ObjectInfo>> ObjectInfoManager::allObjects()
243+
std::vector<std::shared_ptr<ObjectInfo>> ObjectInfoManager::allObjects() const
244244
{
245245
std::vector<std::shared_ptr<ObjectInfo>> all_objects = attention_area_objects_;
246246
all_objects.insert(

planning/behavior_velocity_intersection_module/src/object_manager.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class ObjectInfo
109109
return predicted_object_;
110110
};
111111

112-
std::optional<CollisionInterval> is_unsafe() const
112+
std::optional<CollisionInterval> unsafe_info() const
113113
{
114114
if (safe_under_traffic_control_) {
115115
return std::nullopt;
@@ -246,7 +246,7 @@ class ObjectInfoManager
246246

247247
const std::vector<std::shared_ptr<ObjectInfo>> & parkedObjects() const { return parked_objects_; }
248248

249-
std::vector<std::shared_ptr<ObjectInfo>> allObjects();
249+
std::vector<std::shared_ptr<ObjectInfo>> allObjects() const;
250250

251251
const std::unordered_map<unique_identifier_msgs::msg::UUID, std::shared_ptr<ObjectInfo>> &
252252
getObjectsMap()

planning/behavior_velocity_intersection_module/src/scene_intersection.cpp

+25-16
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ IntersectionModule::IntersectionModule(
5151
const std::string & turn_direction, const bool has_traffic_light, rclcpp::Node & node,
5252
const rclcpp::Logger logger, const rclcpp::Clock::SharedPtr clock)
5353
: SceneModuleInterface(module_id, logger, clock),
54-
node_(node),
5554
lane_id_(lane_id),
5655
associative_ids_(associative_ids),
5756
turn_direction_(turn_direction),
@@ -87,10 +86,10 @@ IntersectionModule::IntersectionModule(
8786
}
8887

8988
decision_state_pub_ =
90-
node_.create_publisher<std_msgs::msg::String>("~/debug/intersection/decision_state", 1);
91-
ego_ttc_pub_ = node_.create_publisher<tier4_debug_msgs::msg::Float64MultiArrayStamped>(
89+
node.create_publisher<std_msgs::msg::String>("~/debug/intersection/decision_state", 1);
90+
ego_ttc_pub_ = node.create_publisher<tier4_debug_msgs::msg::Float64MultiArrayStamped>(
9291
"~/debug/intersection/ego_ttc", 1);
93-
object_ttc_pub_ = node_.create_publisher<tier4_debug_msgs::msg::Float64MultiArrayStamped>(
92+
object_ttc_pub_ = node.create_publisher<tier4_debug_msgs::msg::Float64MultiArrayStamped>(
9493
"~/debug/intersection/object_ttc", 1);
9594
}
9695

@@ -104,11 +103,13 @@ bool IntersectionModule::modifyPathVelocity(PathWithLaneId * path, StopReason *
104103
const auto decision_result = modifyPathVelocityDetail(path, stop_reason);
105104
prev_decision_result_ = decision_result;
106105

107-
const std::string decision_type = "intersection" + std::to_string(module_id_) + " : " +
108-
intersection::formatDecisionResult(decision_result);
109-
std_msgs::msg::String decision_result_msg;
110-
decision_result_msg.data = decision_type;
111-
decision_state_pub_->publish(decision_result_msg);
106+
{
107+
const std::string decision_type = "intersection" + std::to_string(module_id_) + " : " +
108+
intersection::formatDecisionResult(decision_result);
109+
std_msgs::msg::String decision_result_msg;
110+
decision_result_msg.data = decision_type;
111+
decision_state_pub_->publish(decision_result_msg);
112+
}
112113

113114
prepareRTCStatus(decision_result, *path);
114115

@@ -224,6 +225,14 @@ intersection::DecisionResult IntersectionModule::modifyPathVelocityDetail(
224225
updateObjectInfoManagerCollision(
225226
path_lanelets, time_distance_array, traffic_prioritized_level, safely_passed_1st_judge_line,
226227
safely_passed_2nd_judge_line);
228+
for (const auto & object_info : object_info_manager_.attentionObjects()) {
229+
if (!object_info->unsafe_info()) {
230+
continue;
231+
}
232+
setObjectsOfInterestData(
233+
object_info->predicted_object().kinematics.initial_pose_with_covariance.pose,
234+
object_info->predicted_object().shape, ColorName::RED);
235+
}
227236

228237
const auto [has_collision, collision_position, too_late_detect_objects, misjudge_objects] =
229238
detectCollision(is_over_1st_pass_judge_line, is_over_2nd_pass_judge_line);
@@ -240,17 +249,17 @@ intersection::DecisionResult IntersectionModule::modifyPathVelocityDetail(
240249
"no collision is detected", "ego can safely pass the intersection at this rate"};
241250
}
242251

243-
const bool collision_on_1st_attention_lane =
244-
has_collision && (collision_position == intersection::CollisionInterval::LanePosition::FIRST);
245252
// ==========================================================================================
246253
// this state is very dangerous because ego is very close/over the boundary of 1st attention lane
247254
// and collision is detected on the 1st lane. Since the 2nd attention lane also exists in this
248255
// case, possible another collision may be expected on the 2nd attention lane too.
249256
// ==========================================================================================
250257
std::string safety_report = safety_diag;
251-
if (
252-
is_over_1st_pass_judge_line && is_over_2nd_pass_judge_line &&
253-
is_over_2nd_pass_judge_line.value() && collision_on_1st_attention_lane) {
258+
if (const bool collision_on_1st_attention_lane =
259+
has_collision &&
260+
(collision_position == intersection::CollisionInterval::LanePosition::FIRST);
261+
is_over_1st_pass_judge_line && is_over_2nd_pass_judge_line.has_value() &&
262+
!is_over_2nd_pass_judge_line.value() && collision_on_1st_attention_lane) {
254263
safety_report +=
255264
"\nego is between the 1st and 2nd pass judge line but collision is expected on the 1st "
256265
"attention lane, which is dangerous.";
@@ -374,15 +383,15 @@ intersection::DecisionResult IntersectionModule::modifyPathVelocityDetail(
374383
closest_idx,
375384
first_attention_stopline_idx,
376385
occlusion_wo_tl_pass_judge_line_idx,
377-
safety_diag};
386+
safety_report};
378387
}
379388

380389
// ==========================================================================================
381390
// following remaining block is "has_traffic_light_"
382391
//
383392
// if ego is stuck by static occlusion in the presence of traffic light, start timeout count
384393
// ==========================================================================================
385-
const bool is_static_occlusion = occlusion_status == OcclusionType::STATICALLY_OCCLUDED;
394+
const bool is_static_occlusion = std::holds_alternative<StaticallyOccluded>(occlusion_status);
386395
const bool is_stuck_by_static_occlusion =
387396
stoppedAtPosition(
388397
occlusion_stopline_idx, planner_param_.occlusion.temporal_stop_time_before_peeking) &&

planning/behavior_velocity_intersection_module/src/scene_intersection.hpp

+33-22
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <string>
4242
#include <tuple>
4343
#include <utility>
44+
#include <variant>
4445
#include <vector>
4546

4647
namespace behavior_velocity_planner
@@ -166,16 +167,25 @@ class IntersectionModule : public SceneModuleInterface
166167
} debug;
167168
};
168169

169-
enum OcclusionType {
170-
//! occlusion is not detected
171-
NOT_OCCLUDED,
172-
//! occlusion is not caused by dynamic objects
173-
STATICALLY_OCCLUDED,
174-
//! occlusion is caused by dynamic objects
175-
DYNAMICALLY_OCCLUDED,
176-
//! actual occlusion does not exist, only disapproved by RTC
177-
RTC_OCCLUDED,
170+
//! occlusion is not detected
171+
struct NotOccluded
172+
{
173+
double best_clearance_distance{-1.0};
174+
};
175+
//! occlusion is not caused by dynamic objects
176+
struct StaticallyOccluded
177+
{
178+
double best_clearance_distance{0.0};
179+
};
180+
//! occlusion is caused by dynamic objects
181+
struct DynamicallyOccluded
182+
{
183+
double best_clearance_distance{0.0};
178184
};
185+
//! actual occlusion does not exist, only disapproved by RTC
186+
using RTCOccluded = std::monostate;
187+
using OcclusionType =
188+
std::variant<NotOccluded, StaticallyOccluded, DynamicallyOccluded, RTCOccluded>;
179189

180190
struct DebugData
181191
{
@@ -294,11 +304,9 @@ class IntersectionModule : public SceneModuleInterface
294304
bool getOcclusionSafety() const { return occlusion_safety_; }
295305
double getOcclusionDistance() const { return occlusion_stop_distance_; }
296306
void setOcclusionActivation(const bool activation) { occlusion_activated_ = activation; }
297-
bool isOcclusionFirstStopRequired() { return occlusion_first_stop_required_; }
307+
bool isOcclusionFirstStopRequired() const { return occlusion_first_stop_required_; }
298308

299309
private:
300-
rclcpp::Node & node_;
301-
302310
/**
303311
***********************************************************
304312
***********************************************************
@@ -396,7 +404,7 @@ class IntersectionModule : public SceneModuleInterface
396404
* @defgroup occlusion-variables [var] occlusion detection variables
397405
* @{
398406
*/
399-
OcclusionType prev_occlusion_status_;
407+
OcclusionType prev_occlusion_status_{NotOccluded{}};
400408

401409
//! debouncing for the first brief stop at the default stopline
402410
StateMachine before_creep_state_machine_;
@@ -499,7 +507,7 @@ class IntersectionModule : public SceneModuleInterface
499507
*/
500508
std::optional<size_t> getStopLineIndexFromMap(
501509
const intersection::InterpolatedPathInfo & interpolated_path_info,
502-
lanelet::ConstLanelet assigned_lanelet);
510+
lanelet::ConstLanelet assigned_lanelet) const;
503511

504512
/**
505513
* @brief generate IntersectionStopLines
@@ -510,15 +518,15 @@ class IntersectionModule : public SceneModuleInterface
510518
const lanelet::ConstLanelet & first_attention_lane,
511519
const std::optional<lanelet::CompoundPolygon3d> & second_attention_area_opt,
512520
const intersection::InterpolatedPathInfo & interpolated_path_info,
513-
autoware_auto_planning_msgs::msg::PathWithLaneId * original_path);
521+
autoware_auto_planning_msgs::msg::PathWithLaneId * original_path) const;
514522

515523
/**
516524
* @brief generate IntersectionLanelets
517525
*/
518526
intersection::IntersectionLanelets generateObjectiveLanelets(
519527
lanelet::LaneletMapConstPtr lanelet_map_ptr,
520528
lanelet::routing::RoutingGraphPtr routing_graph_ptr,
521-
const lanelet::ConstLanelet assigned_lanelet);
529+
const lanelet::ConstLanelet assigned_lanelet) const;
522530

523531
/**
524532
* @brief generate PathLanelets
@@ -529,14 +537,15 @@ class IntersectionModule : public SceneModuleInterface
529537
const lanelet::CompoundPolygon3d & first_conflicting_area,
530538
const std::vector<lanelet::CompoundPolygon3d> & conflicting_areas,
531539
const std::optional<lanelet::CompoundPolygon3d> & first_attention_area,
532-
const std::vector<lanelet::CompoundPolygon3d> & attention_areas, const size_t closest_idx);
540+
const std::vector<lanelet::CompoundPolygon3d> & attention_areas,
541+
const size_t closest_idx) const;
533542

534543
/**
535544
* @brief generate discretized detection lane linestring.
536545
*/
537546
std::vector<lanelet::ConstLineString3d> generateDetectionLaneDivisions(
538547
lanelet::ConstLanelets detection_lanelets,
539-
const lanelet::routing::RoutingGraphPtr routing_graph_ptr, const double resolution);
548+
const lanelet::routing::RoutingGraphPtr routing_graph_ptr, const double resolution) const;
540549
/** @} */
541550

542551
private:
@@ -636,7 +645,8 @@ class IntersectionModule : public SceneModuleInterface
636645
* @attention this function has access to value() of intersection_lanelets_,
637646
* intersection_lanelets.first_attention_area(), occlusion_attention_divisions_
638647
*/
639-
OcclusionType detectOcclusion(const intersection::InterpolatedPathInfo & interpolated_path_info);
648+
OcclusionType detectOcclusion(
649+
const intersection::InterpolatedPathInfo & interpolated_path_info) const;
640650
/** @} */
641651

642652
private:
@@ -699,7 +709,7 @@ class IntersectionModule : public SceneModuleInterface
699709
*/
700710
std::optional<intersection::NonOccludedCollisionStop> isGreenPseudoCollisionStatus(
701711
const size_t closest_idx, const size_t collision_stopline_idx,
702-
const intersection::IntersectionStopLines & intersection_stoplines);
712+
const intersection::IntersectionStopLines & intersection_stoplines) const;
703713

704714
/**
705715
* @brief generate the message explaining why too_late_detect_objects/misjudge_objects exist and
@@ -731,7 +741,8 @@ class IntersectionModule : public SceneModuleInterface
731741
* @brief return if collision is detected and the collision position
732742
*/
733743
CollisionStatus detectCollision(
734-
const bool is_over_1st_pass_judge_line, const std::optional<bool> is_over_2nd_pass_judge_line);
744+
const bool is_over_1st_pass_judge_line,
745+
const std::optional<bool> is_over_2nd_pass_judge_line) const;
735746

736747
std::optional<size_t> checkAngleForTargetLanelets(
737748
const geometry_msgs::msg::Pose & pose, const lanelet::ConstLanelets & target_lanelets,
@@ -747,7 +758,7 @@ class IntersectionModule : public SceneModuleInterface
747758
TimeDistanceArray calcIntersectionPassingTime(
748759
const autoware_auto_planning_msgs::msg::PathWithLaneId & path, const bool is_prioritized,
749760
const intersection::IntersectionStopLines & intersection_stoplines,
750-
tier4_debug_msgs::msg::Float64MultiArrayStamped * debug_ttc_array);
761+
tier4_debug_msgs::msg::Float64MultiArrayStamped * debug_ttc_array) const;
751762
/** @} */
752763

753764
mutable DebugData debug_data_;

planning/behavior_velocity_intersection_module/src/scene_intersection_collision.cpp

+15-10
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ void IntersectionModule::cutPredictPathWithinDuration(
346346
std::optional<intersection::NonOccludedCollisionStop>
347347
IntersectionModule::isGreenPseudoCollisionStatus(
348348
const size_t closest_idx, const size_t collision_stopline_idx,
349-
const intersection::IntersectionStopLines & intersection_stoplines)
349+
const intersection::IntersectionStopLines & intersection_stoplines) const
350350
{
351351
// ==========================================================================================
352352
// if there are any vehicles on the attention area when ego entered the intersection on green
@@ -588,7 +588,8 @@ std::string IntersectionModule::generateEgoRiskEvasiveDiagnosis(
588588
}
589589

590590
IntersectionModule::CollisionStatus IntersectionModule::detectCollision(
591-
const bool is_over_1st_pass_judge_line, const std::optional<bool> is_over_2nd_pass_judge_line)
591+
const bool is_over_1st_pass_judge_line,
592+
const std::optional<bool> is_over_2nd_pass_judge_line) const
592593
{
593594
// ==========================================================================================
594595
// if collision is detected for multiple objects, we prioritize collision on the first
@@ -598,14 +599,18 @@ IntersectionModule::CollisionStatus IntersectionModule::detectCollision(
598599
bool collision_at_non_first_lane = false;
599600

600601
// ==========================================================================================
601-
// find the objects which is judges as UNSAFE after ego passed pass judge lines.
602+
// find the objects which are judged as UNSAFE after ego passed pass judge lines.
602603
//
603604
// misjudge_objects are those that were once judged as safe when ego passed the pass judge line
604605
//
605-
// too_late_detect objects are those that (1) were not detected when ego passed the pass judge
606-
// line (2) were judged as dangerous at the same time when ego passed the pass judge, which are
607-
// expected to have been detected in the prior iteration because ego could have judged as UNSAFE
608-
// in the prior iteration
606+
// too_late_detect_objects are those that (1) were not detected when ego passed the pass judge
607+
// line (2) were judged as dangerous at the same time when ego passed the pass judge line, which
608+
// means they were expected to have been detected when ego passed the pass judge lines or in the
609+
// prior iteration, because ego could have judged them as UNSAFE if their information was
610+
// available at that time.
611+
//
612+
// that case is both "too late to stop" and "too late to go" for the planner. and basically
613+
// detection side is responsible for this fault
609614
// ==========================================================================================
610615
std::vector<std::pair<CollisionStatus::BlameType, std::shared_ptr<intersection::ObjectInfo>>>
611616
misjudge_objects;
@@ -617,10 +622,10 @@ IntersectionModule::CollisionStatus IntersectionModule::detectCollision(
617622
object_info->predicted_object());
618623
continue;
619624
}
620-
if (!object_info->is_unsafe()) {
625+
if (!object_info->unsafe_info()) {
621626
continue;
622627
}
623-
const auto & unsafe_info = object_info->is_unsafe().value();
628+
const auto & unsafe_info = object_info->unsafe_info().value();
624629
// ==========================================================================================
625630
// if ego is over the pass judge lines, then the visualization as "too_late_objects" or
626631
// "misjudge_objects" is more important than that for "unsafe"
@@ -986,7 +991,7 @@ std::optional<size_t> IntersectionModule::checkAngleForTargetLanelets(
986991
IntersectionModule::TimeDistanceArray IntersectionModule::calcIntersectionPassingTime(
987992
const autoware_auto_planning_msgs::msg::PathWithLaneId & path, const bool is_prioritized,
988993
const intersection::IntersectionStopLines & intersection_stoplines,
989-
tier4_debug_msgs::msg::Float64MultiArrayStamped * debug_ttc_array)
994+
tier4_debug_msgs::msg::Float64MultiArrayStamped * debug_ttc_array) const
990995
{
991996
const double intersection_velocity =
992997
planner_param_.collision_detection.velocity_profile.default_velocity;

0 commit comments

Comments
 (0)