@@ -657,6 +657,104 @@ TEST_P(TrajectoryControllerTestParameterized, position_error_not_normalized)
657
657
executor.cancel ();
658
658
}
659
659
660
+ /* *
661
+ * @brief check if no timeout is triggered
662
+ */
663
+ TEST_P (TrajectoryControllerTestParameterized, no_timeout)
664
+ {
665
+ rclcpp::executors::MultiThreadedExecutor executor;
666
+ // zero is default value, just for demonstration
667
+ rclcpp::Parameter cmd_timeout_parameter (" cmd_timeout" , 0.0 );
668
+ SetUpAndActivateTrajectoryController (executor, true , {cmd_timeout_parameter}, false );
669
+ subscribeToState ();
670
+
671
+ size_t n_joints = joint_names_.size ();
672
+
673
+ // send msg
674
+ constexpr auto FIRST_POINT_TIME = std::chrono::milliseconds (250 );
675
+ builtin_interfaces::msg::Duration time_from_start{rclcpp::Duration (FIRST_POINT_TIME)};
676
+ // *INDENT-OFF*
677
+ std::vector<std::vector<double >> points{
678
+ {{3.3 , 4.4 , 6.6 }}, {{7.7 , 8.8 , 9.9 }}, {{10.10 , 11.11 , 12.12 }}};
679
+ std::vector<std::vector<double >> points_velocities{
680
+ {{0.01 , 0.01 , 0.01 }}, {{0.05 , 0.05 , 0.05 }}, {{0.06 , 0.06 , 0.06 }}};
681
+ // *INDENT-ON*
682
+ publish (time_from_start, points, rclcpp::Time (), {}, points_velocities);
683
+ traj_controller_->wait_for_trajectory (executor);
684
+
685
+ // first update
686
+ updateController (rclcpp::Duration (FIRST_POINT_TIME));
687
+
688
+ // Spin to receive latest state
689
+ executor.spin_some ();
690
+ auto state_msg = getState ();
691
+ ASSERT_TRUE (state_msg);
692
+
693
+ // has the msg the correct vector sizes?
694
+ EXPECT_EQ (n_joints, state_msg->reference .positions .size ());
695
+
696
+ // is the desired position sampled?
697
+ EXPECT_NEAR (state_msg->reference .positions [0 ], points.at (0 ).at (0 ), 1e-2 );
698
+ EXPECT_NEAR (state_msg->reference .positions [1 ], points.at (0 ).at (1 ), 1e-2 );
699
+ EXPECT_NEAR (state_msg->reference .positions [2 ], points.at (0 ).at (2 ), 1e-2 );
700
+
701
+ executor.cancel ();
702
+ }
703
+
704
+ /* *
705
+ * @brief check if timeout is triggered
706
+ */
707
+ TEST_P (TrajectoryControllerTestParameterized, timeout)
708
+ {
709
+ rclcpp::executors::MultiThreadedExecutor executor;
710
+ constexpr double cmd_timeout = 0.1 ;
711
+ rclcpp::Parameter cmd_timeout_parameter (" cmd_timeout" , cmd_timeout);
712
+ SetUpAndActivateTrajectoryController (executor, true , {cmd_timeout_parameter}, false );
713
+ subscribeToState ();
714
+
715
+ size_t n_joints = joint_names_.size ();
716
+
717
+ // send msg
718
+ constexpr auto FIRST_POINT_TIME = std::chrono::milliseconds (250 );
719
+ builtin_interfaces::msg::Duration time_from_start{rclcpp::Duration (FIRST_POINT_TIME)};
720
+ // *INDENT-OFF*
721
+ std::vector<std::vector<double >> points{
722
+ {{3.3 , 4.4 , 6.6 }}, {{7.7 , 8.8 , 9.9 }}, {{10.10 , 11.11 , 12.12 }}};
723
+ std::vector<std::vector<double >> points_velocities{
724
+ {{0.01 , 0.01 , 0.01 }}, {{0.05 , 0.05 , 0.05 }}, {{0.06 , 0.06 , 0.06 }}};
725
+ // *INDENT-ON*
726
+
727
+ // auto clock = rclcpp::Clock(RCL_STEADY_TIME);
728
+ // rclcpp::Duration wait_time = rclcpp::Duration::from_seconds(1.0);
729
+ publish (time_from_start, points, rclcpp::Time (), {}, points_velocities);
730
+ traj_controller_->wait_for_trajectory (executor);
731
+
732
+ // first update
733
+ updateController (rclcpp::Duration (FIRST_POINT_TIME));
734
+
735
+ // Spin to receive latest state
736
+ executor.spin_some ();
737
+ auto state_msg = getState ();
738
+ ASSERT_TRUE (state_msg);
739
+
740
+ // has the msg the correct vector sizes?
741
+ EXPECT_EQ (n_joints, state_msg->reference .positions .size ());
742
+
743
+ // TODO(christophfroehlich): using EXPECT_LT now ->
744
+ // better calculate the true expected value after timeout
745
+ EXPECT_LT (
746
+ state_msg->reference .positions [0 ],
747
+ INITIAL_POS_JOINTS[0 ] + (points.at (0 ).at (0 ) - INITIAL_POS_JOINTS[0 ]) * cmd_timeout / 0.25 );
748
+ EXPECT_LT (
749
+ state_msg->reference .positions [1 ],
750
+ INITIAL_POS_JOINTS[1 ] + (points.at (0 ).at (1 ) - INITIAL_POS_JOINTS[0 ]) * cmd_timeout / 0.25 );
751
+ EXPECT_LT (
752
+ state_msg->reference .positions [2 ],
753
+ INITIAL_POS_JOINTS[2 ] + (points.at (0 ).at (2 ) - INITIAL_POS_JOINTS[0 ]) * cmd_timeout / 0.25 );
754
+
755
+ executor.cancel ();
756
+ }
757
+
660
758
/* *
661
759
* @brief check if position error of revolute joints are normalized if configured so
662
760
*/
0 commit comments