24
24
#include < algorithm>
25
25
#include < limits>
26
26
#include < memory>
27
+ #include < utility>
27
28
#include < vector>
28
29
29
30
namespace behavior_path_planner ::helper::avoidance
@@ -32,7 +33,10 @@ namespace behavior_path_planner::helper::avoidance
32
33
using behavior_path_planner::PathShifter;
33
34
using behavior_path_planner::PlannerData;
34
35
using motion_utils::calcDecelDistWithJerkAndAccConstraints;
36
+ using motion_utils::calcLongitudinalOffsetPose;
37
+ using motion_utils::calcSignedArcLength;
35
38
using motion_utils::findNearestIndex;
39
+ using tier4_autoware_utils::getPose;
36
40
37
41
class AvoidanceHelper
38
42
{
@@ -61,6 +65,11 @@ class AvoidanceHelper
61
65
62
66
geometry_msgs::msg::Pose getEgoPose () const { return data_->self_odometry ->pose .pose ; }
63
67
68
+ geometry_msgs::msg::Point getEgoPosition () const
69
+ {
70
+ return data_->self_odometry ->pose .pose .position ;
71
+ }
72
+
64
73
static size_t getConstraintsMapIndex (const double velocity, const std::vector<double > & values)
65
74
{
66
75
const auto itr = std::find_if (
@@ -262,6 +271,20 @@ class AvoidanceHelper
262
271
return *itr;
263
272
}
264
273
274
+ std::pair<double , double > getDistanceToAccelEndPoint (const PathWithLaneId & path)
275
+ {
276
+ updateAccelEndPoint (path);
277
+
278
+ if (!max_v_point_.has_value ()) {
279
+ return std::make_pair (0.0 , std::numeric_limits<double >::max ());
280
+ }
281
+
282
+ const auto start_idx = data_->findEgoIndex (path.points );
283
+ const auto distance =
284
+ calcSignedArcLength (path.points , start_idx, max_v_point_.value ().first .position );
285
+ return std::make_pair (distance, max_v_point_.value ().second );
286
+ }
287
+
265
288
double getFeasibleDecelDistance (
266
289
const double target_velocity, const bool use_hard_constraints = true ) const
267
290
{
@@ -367,6 +390,56 @@ class AvoidanceHelper
367
390
return true ;
368
391
}
369
392
393
+ void updateAccelEndPoint (const PathWithLaneId & path)
394
+ {
395
+ const auto & p = parameters_;
396
+ const auto & a_now = data_->self_acceleration ->accel .accel .linear .x ;
397
+ if (a_now < 0.0 ) {
398
+ max_v_point_ = std::nullopt;
399
+ return ;
400
+ }
401
+
402
+ if (getEgoSpeed () < p->min_velocity_to_limit_max_acceleration ) {
403
+ max_v_point_ = std::nullopt;
404
+ return ;
405
+ }
406
+
407
+ if (max_v_point_.has_value ()) {
408
+ return ;
409
+ }
410
+
411
+ const auto v0 = getEgoSpeed () + p->buf_slow_down_speed ;
412
+
413
+ const auto t_neg_jerk = std::max (0.0 , a_now - p->max_acceleration ) / p->max_jerk ;
414
+ const auto v_neg_jerk = v0 + a_now * t_neg_jerk + std::pow (t_neg_jerk, 2.0 ) / 2.0 ;
415
+ const auto x_neg_jerk = v0 * t_neg_jerk + a_now * std::pow (t_neg_jerk, 2.0 ) / 2.0 +
416
+ p->max_jerk * std::pow (t_neg_jerk, 3.0 ) / 6.0 ;
417
+
418
+ const auto & v_max = data_->parameters .max_vel ;
419
+ if (v_max < v_neg_jerk) {
420
+ max_v_point_ = std::nullopt;
421
+ return ;
422
+ }
423
+
424
+ const auto t_max_accel = (v_max - v_neg_jerk) / p->max_acceleration ;
425
+ const auto x_max_accel =
426
+ v_neg_jerk * t_max_accel + p->max_acceleration * std::pow (t_max_accel, 2.0 ) / 2.0 ;
427
+
428
+ const auto point =
429
+ calcLongitudinalOffsetPose (path.points , getEgoPosition (), x_neg_jerk + x_max_accel);
430
+ if (point.has_value ()) {
431
+ max_v_point_ = std::make_pair (point.value (), v_max);
432
+ return ;
433
+ }
434
+
435
+ const auto x_end = calcSignedArcLength (path.points , getEgoPosition (), path.points .size () - 1 );
436
+ const auto t_end =
437
+ (std::sqrt (v0 * v0 + 2.0 * p->max_acceleration * x_end) - v0) / p->max_acceleration ;
438
+ const auto v_end = v0 + p->max_acceleration * t_end;
439
+
440
+ max_v_point_ = std::make_pair (getPose (path.points .back ()), v_end);
441
+ }
442
+
370
443
void reset ()
371
444
{
372
445
prev_reference_path_ = PathWithLaneId ();
@@ -417,6 +490,8 @@ class AvoidanceHelper
417
490
ShiftedPath prev_linear_shift_path_;
418
491
419
492
lanelet::ConstLanelets prev_driving_lanes_;
493
+
494
+ std::optional<std::pair<Pose, double >> max_v_point_;
420
495
};
421
496
} // namespace behavior_path_planner::helper::avoidance
422
497
0 commit comments