41 using namespace std::chrono_literals;
47 auto log_time_start = node_->now();
48 ASSERT_TRUE(setupStartClient());
49 ASSERT_TRUE(setupCommandSub(servo_parameters_->command_out_type));
50 auto log_time_end = node_->now();
51 RCLCPP_INFO_STREAM(LOGGER,
"Setup time: " << (log_time_end - log_time_start).seconds());
58 auto time_start = node_->now();
61 rclcpp::WallRate publish_loop_rate(test_parameters_->publish_hz);
62 size_t num_commands = 30;
64 for (
size_t i = 0; i < num_commands && rclcpp::ok(); ++i)
66 auto msg = std::make_unique<geometry_msgs::msg::TwistStamped>();
67 msg->header.stamp = node_->now();
68 msg->twist.linear.x = 0.1;
69 msg->twist.angular.z = 0.5;
70 pub_twist_cmd_->publish(std::move(msg));
71 publish_loop_rate.sleep();
75 auto time_end = node_->now();
76 auto num_received = getNumCommands();
79 auto num_expected = (time_end - time_start).seconds() / servo_parameters_->publish_period;
80 RCLCPP_INFO_STREAM(LOGGER,
"Wait publish messages: " << (time_end - time_start).seconds());
82 EXPECT_GT(num_received, 0.5 * num_expected);
83 EXPECT_LT(num_received, 1.5 * num_expected);
88 auto log_time_start = node_->now();
89 ASSERT_TRUE(setupStartClient());
90 ASSERT_TRUE(setupCommandSub(servo_parameters_->command_out_type));
91 auto log_time_end = node_->now();
92 RCLCPP_INFO_STREAM(LOGGER,
"Setup time: " << (log_time_end - log_time_start).seconds());
99 auto time_start = node_->now();
102 rclcpp::WallRate publish_loop_rate(test_parameters_->publish_hz);
103 size_t num_commands = 30;
105 for (
size_t i = 0; i < num_commands && rclcpp::ok(); ++i)
107 auto msg = std::make_unique<control_msgs::msg::JointJog>();
108 msg->header.stamp = node_->now();
109 msg->header.frame_id =
"panda_link3";
110 msg->joint_names.push_back(
"panda_joint1");
111 msg->velocities.push_back(0.1);
112 pub_joint_cmd_->publish(std::move(msg));
113 publish_loop_rate.sleep();
117 auto time_end = node_->now();
118 auto num_received = getNumCommands();
121 auto num_expected = (time_end - time_start).seconds() / servo_parameters_->publish_period;
122 log_time_end = node_->now();
123 RCLCPP_INFO_STREAM(LOGGER,
"Wait publish messages: " << (time_end - time_start).seconds());
125 EXPECT_GT(num_received, 0.5 * num_expected);
126 EXPECT_LT(num_received, 1.5 * num_expected);
131 log_time_start = node_->now();
134 const int sleep_time = 1.5 * 1000 * servo_parameters_->incoming_command_timeout;
135 rclcpp::sleep_for(std::chrono::milliseconds(sleep_time));
136 double joint_position_first = getLatestTrajCommand().points[0].positions[0];
139 rclcpp::sleep_for(std::chrono::milliseconds(sleep_time));
140 double joint_position_later = getLatestTrajCommand().points[0].positions[0];
141 EXPECT_NEAR(joint_position_first, joint_position_later, 0.001);
143 log_time_end = node_->now();
144 RCLCPP_INFO_STREAM(LOGGER,
"Wait stale command: " << (log_time_end - log_time_start).seconds());
149 ASSERT_TRUE(setupStartClient());
152 ASSERT_TRUE(start());
155 auto set_parameters_client =
156 node_->create_client<rcl_interfaces::srv::SetParameters>(test_parameters_->servo_node_name +
"/set_parameters");
158 while (!set_parameters_client->service_is_ready())
162 ASSERT_TRUE(
false) <<
"Interrupted while waiting for the service. Exiting.";
164 RCLCPP_INFO(LOGGER,
"set_parameters_client service not yet available, waiting again...");
165 rclcpp::sleep_for(500ms);
169 auto request = std::make_shared<rcl_interfaces::srv::SetParameters::Request>();
172 request->parameters.push_back(
173 rclcpp::Parameter(
"moveit_servo.robot_link_command_frame",
"panda_link4").to_parameter_msg());
176 request->parameters.push_back(rclcpp::Parameter(
"moveit_servo.not_set_parameter", 1.0).to_parameter_msg());
178 auto set_parameter_response = set_parameters_client->async_send_request(request).get();
181 ASSERT_TRUE(set_parameter_response->results[0].successful) << set_parameter_response->results[0].reason;
184 ASSERT_FALSE(set_parameter_response->results[1].successful)
185 <<
"`not_set_parameter` is not a parameter and should fail to be set";
189 int main(
int argc,
char** argv)
191 rclcpp::init(argc, argv);
192 ::testing::InitGoogleTest(&argc, argv);
194 int ret = RUN_ALL_TESTS();
TEST_F(ServoFixture, DynamicParameterTest)
int main(int argc, char **argv)