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,37 @@ class AvoidanceHelper
367
390
return true ;
368
391
}
369
392
393
+ void updateAccelEndPoint (const PathWithLaneId & path)
394
+ {
395
+ const auto & a_now = data_->self_acceleration ->accel .accel .linear .x ;
396
+ if (a_now < 0.0 ) {
397
+ max_v_point_ = std::nullopt;
398
+ return ;
399
+ }
400
+
401
+ if (max_v_point_.has_value ()) {
402
+ return ;
403
+ }
404
+
405
+ const auto & p = parameters_;
406
+ const auto & v_max = data_->parameters .max_vel ;
407
+ const auto v0 = getEgoSpeed () + p->buf_slow_down_speed ;
408
+ const auto t_accel = (v_max - v0) / p->max_acceleration ;
409
+ const auto x_accel = v0 * t_accel + 0.5 * p->max_acceleration * t_accel * t_accel;
410
+
411
+ const auto point = calcLongitudinalOffsetPose (path.points , getEgoPosition (), x_accel);
412
+ if (point.has_value ()) {
413
+ max_v_point_ = std::make_pair (point.value (), v_max);
414
+ }
415
+
416
+ const auto x_end = calcSignedArcLength (path.points , getEgoPosition (), path.points .size () - 1 );
417
+ const auto t_end =
418
+ (std::sqrt (v0 * v0 + 2.0 * p->max_acceleration * x_end) - v0) / p->max_acceleration ;
419
+ const auto v_end = v0 + p->max_acceleration * t_end;
420
+
421
+ max_v_point_ = std::make_pair (getPose (path.points .back ()), v_end);
422
+ }
423
+
370
424
void reset ()
371
425
{
372
426
prev_reference_path_ = PathWithLaneId ();
@@ -417,6 +471,8 @@ class AvoidanceHelper
417
471
ShiftedPath prev_linear_shift_path_;
418
472
419
473
lanelet::ConstLanelets prev_driving_lanes_;
474
+
475
+ std::optional<std::pair<Pose, double >> max_v_point_;
420
476
};
421
477
} // namespace behavior_path_planner::helper::avoidance
422
478
0 commit comments