@@ -97,6 +97,34 @@ lanelet::BasicLineString3d toLineString3d(const std::vector<Point> & bound)
97
97
bound.begin (), bound.end (), [&](const auto & p) { ret.emplace_back (p.x , p.y , p.z ); });
98
98
return ret;
99
99
}
100
+
101
+ bool straddleRoadBound (
102
+ const ShiftedPath & path, const lanelet::ConstLanelets & lanes,
103
+ const vehicle_info_util::VehicleInfo & vehicle_info)
104
+ {
105
+ using boost::geometry::intersects;
106
+ using tier4_autoware_utils::pose2transform;
107
+ using tier4_autoware_utils::transformVector;
108
+
109
+ const auto footprint = vehicle_info.createFootprint ();
110
+
111
+ for (const auto & lane : lanes) {
112
+ for (const auto & p : path.path .points ) {
113
+ const auto transform = pose2transform (p.point .pose );
114
+ const auto shifted_vehicle_footprint = transformVector (footprint, transform);
115
+
116
+ if (intersects (lane.leftBound2d ().basicLineString (), shifted_vehicle_footprint)) {
117
+ return true ;
118
+ }
119
+
120
+ if (intersects (lane.rightBound2d ().basicLineString (), shifted_vehicle_footprint)) {
121
+ return true ;
122
+ }
123
+ }
124
+ }
125
+
126
+ return false ;
127
+ }
100
128
} // namespace
101
129
102
130
AvoidanceModule::AvoidanceModule (
@@ -894,6 +922,48 @@ BehaviorModuleOutput AvoidanceModule::plan()
894
922
planner_data_->parameters .ego_nearest_yaw_threshold );
895
923
}
896
924
925
+ // check if the ego straddles lane border
926
+ if (!is_recording_) {
927
+ is_record_necessary_ = straddleRoadBound (
928
+ spline_shift_path, data.current_lanelets , planner_data_->parameters .vehicle_info );
929
+ }
930
+
931
+ if (!path_shifter_.getShiftLines ().empty ()) {
932
+ const auto front_shift_line = path_shifter_.getShiftLines ().front ();
933
+ const double start_distance = calcSignedArcLength (
934
+ data.reference_path .points , getEgoPosition (), front_shift_line.start .position );
935
+ const double finish_distance = calcSignedArcLength (
936
+ data.reference_path .points , getEgoPosition (), front_shift_line.end .position );
937
+
938
+ const auto record_start_time = !is_recording_ && is_record_necessary_ && helper_->isShifted ();
939
+ const auto record_end_time = is_recording_ && !helper_->isShifted ();
940
+ const auto relative_shift_length = front_shift_line.end_shift_length - helper_->getEgoShift ();
941
+ const auto steering_direction =
942
+ relative_shift_length > 0.0 ? SteeringFactor::LEFT : SteeringFactor::RIGHT;
943
+ const auto steering_status = [&]() {
944
+ if (record_start_time) {
945
+ is_recording_ = true ;
946
+ RCLCPP_ERROR (getLogger (), " start right avoidance maneuver. get time stamp." );
947
+ return uint16_t (100 );
948
+ }
949
+
950
+ if (record_end_time) {
951
+ is_recording_ = false ;
952
+ is_record_necessary_ = false ;
953
+ RCLCPP_ERROR (getLogger (), " end avoidance maneuver. get time stamp." );
954
+ return uint16_t (200 );
955
+ }
956
+
957
+ return helper_->isShifted () ? SteeringFactor::TURNING : SteeringFactor::APPROACHING;
958
+ }();
959
+
960
+ if (finish_distance > -1.0e-03 ) {
961
+ steering_factor_interface_ptr_->updateSteeringFactor (
962
+ {front_shift_line.start , front_shift_line.end }, {start_distance, finish_distance},
963
+ PlanningBehavior::AVOIDANCE, steering_direction, steering_status, " " );
964
+ }
965
+ }
966
+
897
967
// sparse resampling for computational cost
898
968
{
899
969
spline_shift_path.path = utils::resamplePathWithSpline (
@@ -974,14 +1044,6 @@ CandidateOutput AvoidanceModule::planCandidate() const
974
1044
output.start_distance_to_path_change = sl_front.start_longitudinal ;
975
1045
output.finish_distance_to_path_change = sl_back.end_longitudinal ;
976
1046
977
- const uint16_t steering_factor_direction = std::invoke ([&output]() {
978
- return output.lateral_shift > 0.0 ? SteeringFactor::LEFT : SteeringFactor::RIGHT;
979
- });
980
- steering_factor_interface_ptr_->updateSteeringFactor (
981
- {sl_front.start , sl_back.end },
982
- {output.start_distance_to_path_change , output.finish_distance_to_path_change },
983
- PlanningBehavior::AVOIDANCE, steering_factor_direction, SteeringFactor::APPROACHING, " " );
984
-
985
1047
output.path_candidate = shifted_path.path ;
986
1048
return output;
987
1049
}
0 commit comments