Skip to content

Commit bedc68f

Browse files
authored
fix(motion_velocity_smoother): reverse velocity handling (autowarefoundation#1465)
* fix(motion_velocity_smoother): negative velocity handling Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * add reverse velocity handling for debug trajectories, and fix initialmotion calculation Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com>
1 parent 9f4c833 commit bedc68f

File tree

2 files changed

+44
-22
lines changed

2 files changed

+44
-22
lines changed

planning/motion_velocity_smoother/include/motion_velocity_smoother/motion_velocity_smoother_node.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ class MotionVelocitySmootherNode : public rclcpp::Node
9393

9494
tier4_autoware_utils::SelfPoseListener self_pose_listener_{this};
9595

96+
bool is_reverse_;
97+
9698
enum class AlgorithmType {
9799
INVALID = 0,
98100
JERK_FILTERED = 1,

planning/motion_velocity_smoother/src/motion_velocity_smoother_node.cpp

+42-22
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,15 @@ void MotionVelocitySmootherNode::onCurrentTrajectory(const Trajectory::ConstShar
361361
updateDataForExternalVelocityLimit();
362362

363363
// 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+
365373
const auto output = calcTrajectoryVelocity(input_points);
366374
if (output.empty()) {
367375
RCLCPP_WARN(get_logger(), "Output Point is empty");
@@ -382,6 +390,12 @@ void MotionVelocitySmootherNode::onCurrentTrajectory(const Trajectory::ConstShar
382390
// update previous step infomation
383391
updatePrevValues(output);
384392

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+
385399
// publish message
386400
publishTrajectory(*output_resampled);
387401

@@ -430,16 +444,11 @@ TrajectoryPoints MotionVelocitySmootherNode::calcTrajectoryVelocity(
430444
return prev_output_;
431445
}
432446

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-
440447
// Debug
441448
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));
443452
}
444453

445454
// Apply external velocity limit
@@ -458,6 +467,8 @@ TrajectoryPoints MotionVelocitySmootherNode::calcTrajectoryVelocity(
458467

459468
// Debug
460469
if (publish_debug_trajs_) {
470+
auto tmp = traj_extracted;
471+
if (is_reverse_) flipVelocity(tmp);
461472
pub_trajectory_vel_lim_->publish(toTrajectoryMsg(traj_extracted));
462473
}
463474

@@ -466,11 +477,6 @@ TrajectoryPoints MotionVelocitySmootherNode::calcTrajectoryVelocity(
466477
return prev_output_;
467478
}
468479

469-
// for reverse velocity
470-
if (is_reverse) {
471-
flipVelocity(output);
472-
}
473-
474480
return output;
475481
}
476482

@@ -549,8 +555,16 @@ bool MotionVelocitySmootherNode::smoothVelocity(
549555

550556
RCLCPP_DEBUG(get_logger(), "smoothVelocity : traj_smoothed.size() = %lu", traj_smoothed.size());
551557
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+
}
554568

555569
if (!debug_trajectories.empty()) {
556570
for (auto & debug_trajectory : debug_trajectories) {
@@ -652,7 +666,7 @@ MotionVelocitySmootherNode::calcInitialMotion(
652666
}
653667

654668
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);
656670

657671
// when velocity tracking deviation is large
658672
const double desired_vel{prev_output_closest_point.longitudinal_velocity_mps};
@@ -805,16 +819,22 @@ void MotionVelocitySmootherNode::applyStopApproachingVelocity(TrajectoryPoints &
805819
void MotionVelocitySmootherNode::publishDebugTrajectories(
806820
const std::vector<TrajectoryPoints> & debug_trajectories) const
807821
{
822+
auto debug_trajectories_tmp = debug_trajectories;
808823
if (node_param_.algorithm_type == AlgorithmType::JERK_FILTERED) {
809-
if (debug_trajectories.size() != 3) {
824+
if (debug_trajectories_tmp.size() != 3) {
810825
RCLCPP_DEBUG(get_logger(), "Size of the debug trajectories is incorrect");
811826
return;
812827
}
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)));
816836
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_);
818838
}
819839
}
820840

0 commit comments

Comments
 (0)