File tree 1 file changed +32
-0
lines changed
common/autoware_motion_utils/include/autoware/motion_utils/trajectory
1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -2149,6 +2149,38 @@ size_t findFirstNearestIndexWithSoftConstraints(
2149
2149
}
2150
2150
}
2151
2151
2152
+ { // with yaw threshold
2153
+ double min_squared_dist = std::numeric_limits<double >::max ();
2154
+ size_t min_idx = 0 ;
2155
+ bool is_within_constraints = false ;
2156
+ for (size_t i = 0 ; i < points.size (); ++i) {
2157
+ const auto yaw =
2158
+ autoware_utils::calc_yaw_deviation (autoware_utils::get_pose (points.at (i)), pose);
2159
+ const auto squared_dist =
2160
+ autoware_utils::calc_squared_distance2d (points.at (i), pose.position );
2161
+
2162
+ if (yaw_threshold < std::abs (yaw)) {
2163
+ if (is_within_constraints) {
2164
+ break ;
2165
+ }
2166
+ continue ;
2167
+ }
2168
+
2169
+ if (min_squared_dist <= squared_dist) {
2170
+ continue ;
2171
+ }
2172
+
2173
+ min_squared_dist = squared_dist;
2174
+ min_idx = i;
2175
+ is_within_constraints = true ;
2176
+ }
2177
+
2178
+ // nearest index is found
2179
+ if (is_within_constraints) {
2180
+ return min_idx;
2181
+ }
2182
+ }
2183
+
2152
2184
// without any threshold
2153
2185
return findNearestIndex (points, pose.position );
2154
2186
}
You can’t perform that action at this time.
0 commit comments