Skip to content

Commit 440d7d2

Browse files
Add tests
1 parent e38737f commit 440d7d2

File tree

1 file changed

+134
-2
lines changed

1 file changed

+134
-2
lines changed

joint_trajectory_controller/test/test_trajectory_actions.cpp

Lines changed: 134 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ TEST_P(TestTrajectoryActionsTestParameterized, test_success_multi_point_sendgoal
304304
/**
305305
* Makes sense with position command interface only,
306306
* because no integration to position state interface is implemented
307-
*/
307+
*/
308308
TEST_F(TestTrajectoryActions, test_goal_tolerances_single_point_success)
309309
{
310310
// set tolerance parameters
@@ -349,7 +349,7 @@ TEST_F(TestTrajectoryActions, test_goal_tolerances_single_point_success)
349349
/**
350350
* Makes sense with position command interface only,
351351
* because no integration to position state interface is implemented
352-
*/
352+
*/
353353
TEST_F(TestTrajectoryActions, test_goal_tolerances_multi_point_success)
354354
{
355355
// set tolerance parameters
@@ -616,6 +616,138 @@ TEST_P(TestTrajectoryActionsTestParameterized, test_cancel_hold_position)
616616
}
617617
}
618618

619+
TEST_F(TestTrajectoryActions, test_allow_nonzero_velocity_stop_true)
620+
{
621+
// set parameter
622+
command_interface_types_ = {"velocity"};
623+
std::vector<rclcpp::Parameter> params = {
624+
rclcpp::Parameter("command_interfaces", "velocity"),
625+
rclcpp::Parameter("allow_nonzero_velocity_stop", true)};
626+
627+
SetUpExecutor(params);
628+
SetUpControllerHardware();
629+
630+
std::shared_future<typename GoalHandle::SharedPtr> gh_future;
631+
// send goal
632+
{
633+
std::vector<JointTrajectoryPoint> points;
634+
JointTrajectoryPoint point1;
635+
point1.time_from_start = rclcpp::Duration::from_seconds(0.0);
636+
point1.positions.resize(joint_names_.size());
637+
point1.velocities.resize(joint_names_.size());
638+
639+
point1.positions[0] = 4.0;
640+
point1.positions[1] = 5.0;
641+
point1.positions[2] = 6.0;
642+
point1.velocities[0] = 4.0;
643+
point1.velocities[1] = 5.0;
644+
point1.velocities[2] = 6.0;
645+
points.push_back(point1);
646+
647+
JointTrajectoryPoint point2;
648+
point2.time_from_start = rclcpp::Duration::from_seconds(0.1);
649+
point2.positions.resize(joint_names_.size());
650+
point2.velocities.resize(joint_names_.size());
651+
652+
point2.positions[0] = 7.0;
653+
point2.positions[1] = 8.0;
654+
point2.positions[2] = 9.0;
655+
point2.velocities[0] = 4.0;
656+
point2.velocities[1] = 5.0;
657+
point2.velocities[2] = 6.0;
658+
points.push_back(point2);
659+
660+
gh_future = sendActionGoal(points, 1.0, goal_options_);
661+
}
662+
controller_hw_thread_.join();
663+
664+
// will be accepted despite nonzero last point
665+
EXPECT_TRUE(gh_future.get());
666+
EXPECT_EQ(rclcpp_action::ResultCode::SUCCEEDED, common_resultcode_);
667+
}
668+
669+
TEST_F(TestTrajectoryActions, test_allow_nonzero_velocity_stop_false)
670+
{
671+
// set parameter
672+
std::vector<rclcpp::Parameter> params = {
673+
rclcpp::Parameter("command_interfaces", "velocity"),
674+
rclcpp::Parameter("allow_nonzero_velocity_stop", false)};
675+
676+
SetUpExecutor(params);
677+
SetUpControllerHardware();
678+
679+
std::shared_future<typename GoalHandle::SharedPtr> gh_future;
680+
// send goal with nonzero last velocities
681+
{
682+
std::vector<JointTrajectoryPoint> points;
683+
JointTrajectoryPoint point1;
684+
point1.time_from_start = rclcpp::Duration::from_seconds(0.0);
685+
point1.positions.resize(joint_names_.size());
686+
point1.velocities.resize(joint_names_.size());
687+
688+
point1.positions[0] = 4.0;
689+
point1.positions[1] = 5.0;
690+
point1.positions[2] = 6.0;
691+
point1.velocities[0] = 4.0;
692+
point1.velocities[1] = 5.0;
693+
point1.velocities[2] = 6.0;
694+
points.push_back(point1);
695+
696+
JointTrajectoryPoint point2;
697+
point2.time_from_start = rclcpp::Duration::from_seconds(0.1);
698+
point2.positions.resize(joint_names_.size());
699+
point2.velocities.resize(joint_names_.size());
700+
701+
point2.positions[0] = 7.0;
702+
point2.positions[1] = 8.0;
703+
point2.positions[2] = 9.0;
704+
point2.velocities[0] = 4.0;
705+
point2.velocities[1] = 5.0;
706+
point2.velocities[2] = 6.0;
707+
points.push_back(point2);
708+
709+
gh_future = sendActionGoal(points, 1.0, goal_options_);
710+
}
711+
controller_hw_thread_.join();
712+
713+
EXPECT_FALSE(gh_future.get());
714+
715+
// send goal with last velocity being zero
716+
{
717+
std::vector<JointTrajectoryPoint> points;
718+
JointTrajectoryPoint point1;
719+
point1.time_from_start = rclcpp::Duration::from_seconds(0.0);
720+
point1.positions.resize(joint_names_.size());
721+
point1.velocities.resize(joint_names_.size());
722+
723+
point1.positions[0] = 4.0;
724+
point1.positions[1] = 5.0;
725+
point1.positions[2] = 6.0;
726+
point1.velocities[0] = 4.0;
727+
point1.velocities[1] = 5.0;
728+
point1.velocities[2] = 6.0;
729+
points.push_back(point1);
730+
731+
JointTrajectoryPoint point2;
732+
point2.time_from_start = rclcpp::Duration::from_seconds(0.1);
733+
point2.positions.resize(joint_names_.size());
734+
point2.velocities.resize(joint_names_.size());
735+
736+
point2.positions[0] = 7.0;
737+
point2.positions[1] = 8.0;
738+
point2.positions[2] = 9.0;
739+
point2.velocities[0] = 0.0;
740+
point2.velocities[1] = 0.0;
741+
point2.velocities[2] = 0.0;
742+
points.push_back(point2);
743+
744+
gh_future = sendActionGoal(points, 1.0, goal_options_);
745+
}
746+
747+
EXPECT_TRUE(gh_future.get());
748+
EXPECT_EQ(rclcpp_action::ResultCode::SUCCEEDED, common_resultcode_);
749+
}
750+
619751
// position controllers
620752
INSTANTIATE_TEST_SUITE_P(
621753
PositionTrajectoryControllersActions, TestTrajectoryActionsTestParameterized,

0 commit comments

Comments
 (0)