Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JTC] Invalidate empty trajectory messages (backport #902) #1000

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,12 @@ bool JointTrajectoryController::validate_trajectory_msg(
}
}

if (trajectory.points.empty())
{
RCLCPP_ERROR(get_node()->get_logger(), "Empty trajectory received.");
return false;
}

if (!params_.allow_nonzero_velocity_at_trajectory_end)
{
for (size_t i = 0; i < trajectory.points.back().velocities.size(); ++i)
Expand Down
42 changes: 40 additions & 2 deletions joint_trajectory_controller/test/test_trajectory_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,11 @@ TEST_P(TrajectoryControllerTestParameterized, invalid_message)
traj_msg.joint_names = {"bad_name"};
EXPECT_FALSE(traj_controller_->validate_trajectory_msg(traj_msg));

// empty message
traj_msg = good_traj_msg;
traj_msg.points.clear();
EXPECT_FALSE(traj_controller_->validate_trajectory_msg(traj_msg));

// No position data
traj_msg = good_traj_msg;
traj_msg.points[0].positions.clear();
Expand Down Expand Up @@ -1327,8 +1332,41 @@ TEST_P(TrajectoryControllerTestParameterized, invalid_message)
EXPECT_FALSE(traj_controller_->validate_trajectory_msg(traj_msg));
}

/// With allow_integration_in_goal_trajectories parameter trajectory missing position or
/// velocities are accepted
/**
* @brief Test invalid velocity at trajectory end with parameter set to false
*/
TEST_P(
TrajectoryControllerTestParameterized,
expect_invalid_when_message_with_nonzero_end_velocity_and_when_param_false)
{
rclcpp::Parameter nonzero_vel_parameters("allow_nonzero_velocity_at_trajectory_end", false);
rclcpp::executors::SingleThreadedExecutor executor;
SetUpAndActivateTrajectoryController(executor, {nonzero_vel_parameters});

trajectory_msgs::msg::JointTrajectory traj_msg;
traj_msg.joint_names = joint_names_;
traj_msg.header.stamp = rclcpp::Time(0);

// empty message (no throw!)
ASSERT_NO_THROW(traj_controller_->validate_trajectory_msg(traj_msg));
EXPECT_FALSE(traj_controller_->validate_trajectory_msg(traj_msg));

// Nonzero velocity at trajectory end!
traj_msg.points.resize(1);
traj_msg.points[0].time_from_start = rclcpp::Duration::from_seconds(0.25);
traj_msg.points[0].positions.resize(1);
traj_msg.points[0].positions = {1.0, 2.0, 3.0};
traj_msg.points[0].velocities.resize(1);
traj_msg.points[0].velocities = {-1.0, -2.0, -3.0};
EXPECT_FALSE(traj_controller_->validate_trajectory_msg(traj_msg));
}

/**
* @brief missing_positions_message_accepted Test mismatched joint and reference vector sizes
*
* @note With allow_integration_in_goal_trajectories parameter trajectory missing position or
* velocities are accepted
*/
TEST_P(TrajectoryControllerTestParameterized, missing_positions_message_accepted)
{
rclcpp::Parameter allow_integration_parameters("allow_integration_in_goal_trajectories", true);
Expand Down
Loading