@@ -361,7 +361,15 @@ void MotionVelocitySmootherNode::onCurrentTrajectory(const Trajectory::ConstShar
361
361
updateDataForExternalVelocityLimit ();
362
362
363
363
// calculate trajectory velocity
364
- const auto input_points = motion_utils::convertToTrajectoryPointArray (*base_traj_raw_ptr_);
364
+ auto input_points = motion_utils::convertToTrajectoryPointArray (*base_traj_raw_ptr_);
365
+
366
+ // For negative velocity handling, multiple -1 to velocity if it is for reverse.
367
+ // NOTE: this process must be in the beginning of the process
368
+ is_reverse_ = isReverse (input_points);
369
+ if (is_reverse_) {
370
+ flipVelocity (input_points);
371
+ }
372
+
365
373
const auto output = calcTrajectoryVelocity (input_points);
366
374
if (output.empty ()) {
367
375
RCLCPP_WARN (get_logger (), " Output Point is empty" );
@@ -382,6 +390,12 @@ void MotionVelocitySmootherNode::onCurrentTrajectory(const Trajectory::ConstShar
382
390
// update previous step infomation
383
391
updatePrevValues (output);
384
392
393
+ // for reverse velocity
394
+ // NOTE: this process must be in the end of the process
395
+ if (is_reverse_) {
396
+ flipVelocity (*output_resampled);
397
+ }
398
+
385
399
// publish message
386
400
publishTrajectory (*output_resampled);
387
401
@@ -430,16 +444,11 @@ TrajectoryPoints MotionVelocitySmootherNode::calcTrajectoryVelocity(
430
444
return prev_output_;
431
445
}
432
446
433
- // Smoother can not handle negative velocity, so multiple -1 to velocity if any trajectory points
434
- // have reverse velocity
435
- const bool is_reverse = isReverse (traj_extracted);
436
- if (is_reverse) {
437
- flipVelocity (traj_extracted);
438
- }
439
-
440
447
// Debug
441
448
if (publish_debug_trajs_) {
442
- pub_trajectory_raw_->publish (toTrajectoryMsg (traj_extracted));
449
+ auto tmp = traj_extracted;
450
+ if (is_reverse_) flipVelocity (tmp);
451
+ pub_trajectory_raw_->publish (toTrajectoryMsg (tmp));
443
452
}
444
453
445
454
// Apply external velocity limit
@@ -458,6 +467,8 @@ TrajectoryPoints MotionVelocitySmootherNode::calcTrajectoryVelocity(
458
467
459
468
// Debug
460
469
if (publish_debug_trajs_) {
470
+ auto tmp = traj_extracted;
471
+ if (is_reverse_) flipVelocity (tmp);
461
472
pub_trajectory_vel_lim_->publish (toTrajectoryMsg (traj_extracted));
462
473
}
463
474
@@ -466,11 +477,6 @@ TrajectoryPoints MotionVelocitySmootherNode::calcTrajectoryVelocity(
466
477
return prev_output_;
467
478
}
468
479
469
- // for reverse velocity
470
- if (is_reverse) {
471
- flipVelocity (output);
472
- }
473
-
474
480
return output;
475
481
}
476
482
@@ -549,8 +555,16 @@ bool MotionVelocitySmootherNode::smoothVelocity(
549
555
550
556
RCLCPP_DEBUG (get_logger (), " smoothVelocity : traj_smoothed.size() = %lu" , traj_smoothed.size ());
551
557
if (publish_debug_trajs_) {
552
- pub_trajectory_latacc_filtered_->publish (toTrajectoryMsg (*traj_lateral_acc_filtered));
553
- pub_trajectory_resampled_->publish (toTrajectoryMsg (*traj_resampled));
558
+ {
559
+ auto tmp = *traj_lateral_acc_filtered;
560
+ if (is_reverse_) flipVelocity (tmp);
561
+ pub_trajectory_latacc_filtered_->publish (toTrajectoryMsg (tmp));
562
+ }
563
+ {
564
+ auto tmp = *traj_resampled;
565
+ if (is_reverse_) flipVelocity (tmp);
566
+ pub_trajectory_resampled_->publish (toTrajectoryMsg (tmp));
567
+ }
554
568
555
569
if (!debug_trajectories.empty ()) {
556
570
for (auto & debug_trajectory : debug_trajectories) {
@@ -652,7 +666,7 @@ MotionVelocitySmootherNode::calcInitialMotion(
652
666
}
653
667
654
668
const auto prev_output_closest_point =
655
- trajectory_utils::calcInterpolatedTrajectoryPoint (prev_traj, input_traj. at (input_closest). pose );
669
+ trajectory_utils::calcInterpolatedTrajectoryPoint (prev_traj, current_pose_ptr_-> pose );
656
670
657
671
// when velocity tracking deviation is large
658
672
const double desired_vel{prev_output_closest_point.longitudinal_velocity_mps };
@@ -805,16 +819,22 @@ void MotionVelocitySmootherNode::applyStopApproachingVelocity(TrajectoryPoints &
805
819
void MotionVelocitySmootherNode::publishDebugTrajectories (
806
820
const std::vector<TrajectoryPoints> & debug_trajectories) const
807
821
{
822
+ auto debug_trajectories_tmp = debug_trajectories;
808
823
if (node_param_.algorithm_type == AlgorithmType::JERK_FILTERED) {
809
- if (debug_trajectories .size () != 3 ) {
824
+ if (debug_trajectories_tmp .size () != 3 ) {
810
825
RCLCPP_DEBUG (get_logger (), " Size of the debug trajectories is incorrect" );
811
826
return ;
812
827
}
813
- pub_forward_filtered_trajectory_->publish (toTrajectoryMsg (debug_trajectories.at (0 )));
814
- pub_backward_filtered_trajectory_->publish (toTrajectoryMsg (debug_trajectories.at (1 )));
815
- pub_merged_filtered_trajectory_->publish (toTrajectoryMsg (debug_trajectories.at (2 )));
828
+ if (is_reverse_) {
829
+ flipVelocity (debug_trajectories_tmp.at (0 ));
830
+ flipVelocity (debug_trajectories_tmp.at (1 ));
831
+ flipVelocity (debug_trajectories_tmp.at (2 ));
832
+ }
833
+ pub_forward_filtered_trajectory_->publish (toTrajectoryMsg (debug_trajectories_tmp.at (0 )));
834
+ pub_backward_filtered_trajectory_->publish (toTrajectoryMsg (debug_trajectories_tmp.at (1 )));
835
+ pub_merged_filtered_trajectory_->publish (toTrajectoryMsg (debug_trajectories_tmp.at (2 )));
816
836
publishClosestVelocity (
817
- debug_trajectories .at (2 ), current_pose_ptr_->pose , pub_closest_merged_velocity_);
837
+ debug_trajectories_tmp .at (2 ), current_pose_ptr_->pose , pub_closest_merged_velocity_);
818
838
}
819
839
}
820
840
0 commit comments