@@ -357,15 +357,6 @@ ObstacleCruisePlannerNode::ObstacleCruisePlannerNode(const rclcpp::NodeOptions &
357
357
traj_sub_ = create_subscription<Trajectory>(
358
358
" ~/input/trajectory" , rclcpp::QoS{1 },
359
359
std::bind (&ObstacleCruisePlannerNode::onTrajectory, this , _1));
360
- objects_sub_ = create_subscription<PredictedObjects>(
361
- " ~/input/objects" , rclcpp::QoS{1 },
362
- [this ](const PredictedObjects::ConstSharedPtr msg) { objects_ptr_ = msg; });
363
- odom_sub_ = create_subscription<Odometry>(
364
- " ~/input/odometry" , rclcpp::QoS{1 },
365
- [this ](const Odometry::ConstSharedPtr msg) { ego_odom_ptr_ = msg; });
366
- acc_sub_ = create_subscription<AccelWithCovarianceStamped>(
367
- " ~/input/acceleration" , rclcpp::QoS{1 },
368
- [this ](const AccelWithCovarianceStamped::ConstSharedPtr msg) { ego_accel_ptr_ = msg; });
369
360
370
361
// publisher
371
362
trajectory_pub_ = create_publisher<Trajectory>(" ~/output/trajectory" , 1 );
@@ -492,10 +483,15 @@ rcl_interfaces::msg::SetParametersResult ObstacleCruisePlannerNode::onParam(
492
483
493
484
void ObstacleCruisePlannerNode::onTrajectory (const Trajectory::ConstSharedPtr msg)
494
485
{
495
- const auto traj_points = motion_utils::convertToTrajectoryPointArray (*msg);
486
+ if (
487
+ !ego_odom_sub_.updateLatestData () || !objects_sub_.updateLatestData () ||
488
+ !acc_sub_.updateLatestData ()) {
489
+ return ;
490
+ }
496
491
492
+ const auto traj_points = motion_utils::convertToTrajectoryPointArray (*msg);
497
493
// check if subscribed variables are ready
498
- if (traj_points.empty () || !ego_odom_ptr_ || !ego_accel_ptr_ || !objects_ptr_ ) {
494
+ if (traj_points.empty ()) {
499
495
return ;
500
496
}
501
497
@@ -607,11 +603,11 @@ std::vector<Obstacle> ObstacleCruisePlannerNode::convertToObstacles(
607
603
{
608
604
stop_watch_.tic (__func__);
609
605
610
- const auto obj_stamp = rclcpp::Time (objects_ptr_-> header .stamp );
606
+ const auto obj_stamp = rclcpp::Time (objects_sub_. getData (). header .stamp );
611
607
const auto & p = behavior_determination_param_;
612
608
613
609
std::vector<Obstacle> target_obstacles;
614
- for (const auto & predicted_object : objects_ptr_-> objects ) {
610
+ for (const auto & predicted_object : objects_sub_. getData (). objects ) {
615
611
const auto & object_id =
616
612
tier4_autoware_utils::toHexString (predicted_object.object_id ).substr (0 , 4 );
617
613
const auto & current_obstacle_pose =
@@ -629,7 +625,8 @@ std::vector<Obstacle> ObstacleCruisePlannerNode::convertToObstacles(
629
625
}
630
626
631
627
// 2. Check if the obstacle is in front of the ego.
632
- const size_t ego_idx = ego_nearest_param_.findIndex (traj_points, ego_odom_ptr_->pose .pose );
628
+ const size_t ego_idx =
629
+ ego_nearest_param_.findIndex (traj_points, ego_odom_sub_.getData ().pose .pose );
633
630
const auto ego_to_obstacle_distance =
634
631
calcDistanceToFrontVehicle (traj_points, ego_idx, current_obstacle_pose.pose .position );
635
632
if (!ego_to_obstacle_distance) {
@@ -725,7 +722,7 @@ ObstacleCruisePlannerNode::determineEgoBehaviorAgainstObstacles(
725
722
// calculated decimated trajectory points and trajectory polygon
726
723
const auto decimated_traj_points = decimateTrajectoryPoints (traj_points);
727
724
const auto decimated_traj_polys =
728
- createOneStepPolygons (decimated_traj_points, vehicle_info_, ego_odom_ptr_-> pose .pose );
725
+ createOneStepPolygons (decimated_traj_points, vehicle_info_, ego_odom_sub_. getData (). pose .pose );
729
726
debug_data_ptr_->detection_polygons = decimated_traj_polys;
730
727
731
728
// determine ego's behavior from stop, cruise and slow down
@@ -783,7 +780,7 @@ ObstacleCruisePlannerNode::determineEgoBehaviorAgainstObstacles(
783
780
slow_down_condition_counter_.removeCounterUnlessUpdated ();
784
781
785
782
// Check target obstacles' consistency
786
- checkConsistency (objects_ptr_-> header .stamp , *objects_ptr_ , stop_obstacles);
783
+ checkConsistency (objects_sub_. getData (). header .stamp , objects_sub_. getData () , stop_obstacles);
787
784
788
785
// update previous obstacles
789
786
prev_stop_obstacles_ = stop_obstacles;
@@ -805,7 +802,7 @@ std::vector<TrajectoryPoint> ObstacleCruisePlannerNode::decimateTrajectoryPoints
805
802
806
803
// trim trajectory
807
804
const size_t ego_seg_idx =
808
- ego_nearest_param_.findSegmentIndex (traj_points, ego_odom_ptr_-> pose .pose );
805
+ ego_nearest_param_.findSegmentIndex (traj_points, ego_odom_sub_. getData (). pose .pose );
809
806
const size_t traj_start_point_idx = ego_seg_idx;
810
807
const auto trimmed_traj_points =
811
808
std::vector<TrajectoryPoint>(traj_points.begin () + traj_start_point_idx, traj_points.end ());
@@ -1189,7 +1186,7 @@ std::optional<StopObstacle> ObstacleCruisePlannerNode::createStopObstacle(
1189
1186
1190
1187
// calculate collision points with trajectory with lateral stop margin
1191
1188
const auto traj_polys_with_lat_margin = createOneStepPolygons (
1192
- traj_points, vehicle_info_, ego_odom_ptr_-> pose .pose , p.max_lat_margin_for_stop );
1189
+ traj_points, vehicle_info_, ego_odom_sub_. getData (). pose .pose , p.max_lat_margin_for_stop );
1193
1190
1194
1191
const auto collision_point = polygon_utils::getCollisionPoint (
1195
1192
traj_points, traj_polys_with_lat_margin, obstacle, is_driving_forward_, vehicle_info_);
@@ -1259,7 +1256,7 @@ std::optional<SlowDownObstacle> ObstacleCruisePlannerNode::createSlowDownObstacl
1259
1256
// calculate collision points with trajectory with lateral stop margin
1260
1257
// NOTE: For additional margin, hysteresis is not divided by two.
1261
1258
const auto traj_polys_with_lat_margin = createOneStepPolygons (
1262
- traj_points, vehicle_info_, ego_odom_ptr_-> pose .pose ,
1259
+ traj_points, vehicle_info_, ego_odom_sub_. getData (). pose .pose ,
1263
1260
p.max_lat_margin_for_slow_down + p.lat_hysteresis_margin_for_slow_down );
1264
1261
1265
1262
std::vector<Polygon2d> front_collision_polygons;
@@ -1422,8 +1419,8 @@ double ObstacleCruisePlannerNode::calcCollisionTimeMargin(
1422
1419
const std::vector<PointWithStamp> & collision_points,
1423
1420
const std::vector<TrajectoryPoint> & traj_points, const bool is_driving_forward) const
1424
1421
{
1425
- const auto & ego_pose = ego_odom_ptr_-> pose .pose ;
1426
- const double ego_vel = ego_odom_ptr_-> twist .twist .linear .x ;
1422
+ const auto & ego_pose = ego_odom_sub_. getData (). pose .pose ;
1423
+ const double ego_vel = ego_odom_sub_. getData (). twist .twist .linear .x ;
1427
1424
1428
1425
const double time_to_reach_collision_point = [&]() {
1429
1426
const double abs_ego_offset = is_driving_forward
@@ -1455,9 +1452,9 @@ PlannerData ObstacleCruisePlannerNode::createPlannerData(
1455
1452
PlannerData planner_data;
1456
1453
planner_data.current_time = now ();
1457
1454
planner_data.traj_points = traj_points;
1458
- planner_data.ego_pose = ego_odom_ptr_-> pose .pose ;
1459
- planner_data.ego_vel = ego_odom_ptr_-> twist .twist .linear .x ;
1460
- planner_data.ego_acc = ego_accel_ptr_-> accel .accel .linear .x ;
1455
+ planner_data.ego_pose = ego_odom_sub_. getData (). pose .pose ;
1456
+ planner_data.ego_vel = ego_odom_sub_. getData (). twist .twist .linear .x ;
1457
+ planner_data.ego_acc = acc_sub_. getData (). accel .accel .linear .x ;
1461
1458
planner_data.is_driving_forward = is_driving_forward_;
1462
1459
return planner_data;
1463
1460
}
0 commit comments