From 34175cb50f60bccf36aff053c5e25240390d2c1a Mon Sep 17 00:00:00 2001 From: urmahp Date: Tue, 29 Aug 2023 08:50:44 +0200 Subject: [PATCH] Added timestamp check and documentation for constructor --- include/ur_client_library/rtde/rtde_client.h | 11 ++ src/rtde/rtde_client.cpp | 2 +- tests/test_rtde_client.cpp | 109 ++++++++++--------- 3 files changed, 70 insertions(+), 52 deletions(-) diff --git a/include/ur_client_library/rtde/rtde_client.h b/include/ur_client_library/rtde/rtde_client.h index 150915bd..10fcedac 100644 --- a/include/ur_client_library/rtde/rtde_client.h +++ b/include/ur_client_library/rtde/rtde_client.h @@ -105,6 +105,17 @@ class RTDEClient */ RTDEClient(std::string robot_ip, comm::INotifier& notifier, const std::string& output_recipe_file, const std::string& input_recipe_file, double target_frequency = 0.0); + + /*! + * \brief Creates a new RTDEClient object, including a used URStream and Pipeline to handle the + * communication with the robot. + * + * \param robot_ip The IP of the robot + * \param notifier The notifier to use in the pipeline + * \param output_recipe Vector containing the output recipe + * \param input_recipe_file Vector containing the input recipe + * \param target_frequency Frequency to run at. Defaults to 0.0 which means maximum frequency. + */ RTDEClient(std::string robot_ip, comm::INotifier& notifier, const std::vector& output_recipe, const std::vector& input_recipe, double target_frequency = 0.0); ~RTDEClient(); diff --git a/src/rtde/rtde_client.cpp b/src/rtde/rtde_client.cpp index 41641610..a3ec0b5a 100644 --- a/src/rtde/rtde_client.cpp +++ b/src/rtde/rtde_client.cpp @@ -52,7 +52,7 @@ RTDEClient::RTDEClient(std::string robot_ip, comm::INotifier& notifier, const st RTDEClient::RTDEClient(std::string robot_ip, comm::INotifier& notifier, const std::vector& output_recipe, const std::vector& input_recipe, double target_frequency) : stream_(robot_ip, UR_RTDE_PORT) - , output_recipe_(output_recipe) + , output_recipe_(ensureTimestampIsPresent(output_recipe)) , input_recipe_(input_recipe) , parser_(output_recipe_) , prod_(stream_, parser_) diff --git a/tests/test_rtde_client.cpp b/tests/test_rtde_client.cpp index 97796c84..80570f8a 100644 --- a/tests/test_rtde_client.cpp +++ b/tests/test_rtde_client.cpp @@ -54,49 +54,49 @@ class RTDEClientTest : public ::testing::Test std::string input_recipe_file_ = "resources/rtde_input_recipe.txt"; comm::INotifier notifier_; std::unique_ptr client_; -}; -std::vector resources_output_recipe = { "timestamp", - "actual_q", - "actual_qd", - "speed_scaling", - "target_speed_fraction", - "runtime_state", - "actual_TCP_force", - "actual_TCP_pose", - "actual_digital_input_bits", - "actual_digital_output_bits", - "standard_analog_input0", - "standard_analog_input1", - "standard_analog_output0", - "standard_analog_output1", - "analog_io_types", - "tool_mode", - "tool_analog_input_types", - "tool_analog_input0", - "tool_analog_input1", - "tool_output_voltage", - "tool_output_current", - "tool_temperature", - "robot_mode", - "safety_mode", - "robot_status_bits", - "safety_status_bits", - "actual_current", - "tcp_offset" }; - -std::vector resources_input_recipe = { "speed_slider_mask", - "speed_slider_fraction", - "standard_digital_output_mask", - "standard_digital_output", - "configurable_digital_output_mask", - "configurable_digital_output", - "tool_digital_output_mask", - "tool_digital_output", - "standard_analog_output_mask", - "standard_analog_output_type", - "standard_analog_output_0", - "standard_analog_output_1" }; + std::vector resources_output_recipe_ = { "timestamp", + "actual_q", + "actual_qd", + "speed_scaling", + "target_speed_fraction", + "runtime_state", + "actual_TCP_force", + "actual_TCP_pose", + "actual_digital_input_bits", + "actual_digital_output_bits", + "standard_analog_input0", + "standard_analog_input1", + "standard_analog_output0", + "standard_analog_output1", + "analog_io_types", + "tool_mode", + "tool_analog_input_types", + "tool_analog_input0", + "tool_analog_input1", + "tool_output_voltage", + "tool_output_current", + "tool_temperature", + "robot_mode", + "safety_mode", + "robot_status_bits", + "safety_status_bits", + "actual_current", + "tcp_offset" }; + + std::vector resources_input_recipe_ = { "speed_slider_mask", + "speed_slider_fraction", + "standard_digital_output_mask", + "standard_digital_output", + "configurable_digital_output_mask", + "configurable_digital_output", + "tool_digital_output_mask", + "tool_digital_output", + "standard_analog_output_mask", + "standard_analog_output_type", + "standard_analog_output_0", + "standard_analog_output_1" }; +}; TEST_F(RTDEClientTest, rtde_handshake) { @@ -246,19 +246,19 @@ TEST_F(RTDEClientTest, output_recipe_file) { std::vector actual_output_recipe = client_->getOutputRecipe(); // Verify that the size is the same - ASSERT_EQ(resources_output_recipe.size(), actual_output_recipe.size()); + ASSERT_EQ(resources_output_recipe_.size(), actual_output_recipe.size()); // Verify that the order and contect is equal - for (unsigned int i = 0; i < resources_output_recipe.size(); ++i) + for (unsigned int i = 0; i < resources_output_recipe_.size(); ++i) { - EXPECT_EQ(resources_output_recipe[i], actual_output_recipe[i]); + EXPECT_EQ(resources_output_recipe_[i], actual_output_recipe[i]); } } TEST_F(RTDEClientTest, recipe_compairson) { // Check that vectorized constructor provides same recipes as from file - auto client = rtde_interface::RTDEClient(ROBOT_IP, notifier_, resources_output_recipe, resources_input_recipe); + auto client = rtde_interface::RTDEClient(ROBOT_IP, notifier_, resources_output_recipe_, resources_input_recipe_); std::vector output_recipe_from_file = client_->getOutputRecipe(); std::vector output_recipe_from_vector = client.getOutputRecipe(); @@ -330,13 +330,20 @@ TEST_F(RTDEClientTest, write_rtde_data) TEST_F(RTDEClientTest, output_recipe_without_timestamp) { - std::string output_recipe = "resources/rtde_output_recipe_without_timestamp.txt"; - client_.reset(new rtde_interface::RTDEClient(ROBOT_IP, notifier_, output_recipe, input_recipe_file_)); + std::string output_recipe_file = "resources/rtde_output_recipe_without_timestamp.txt"; + client_.reset(new rtde_interface::RTDEClient(ROBOT_IP, notifier_, output_recipe_file, input_recipe_file_)); - std::vector actual_output_recipe = client_->getOutputRecipe(); + std::vector actual_output_recipe_from_file = client_->getOutputRecipe(); const std::string timestamp = "timestamp"; - auto it = std::find(actual_output_recipe.begin(), actual_output_recipe.end(), timestamp); - EXPECT_FALSE(it == actual_output_recipe.end()); + auto it = std::find(actual_output_recipe_from_file.begin(), actual_output_recipe_from_file.end(), timestamp); + EXPECT_FALSE(it == actual_output_recipe_from_file.end()); + + // Verify that timestamp is added to the recipe when using the vectorized constructor + std::vector output_recipe = { "actual_q", "actual_qd" }; + auto client = rtde_interface::RTDEClient(ROBOT_IP, notifier_, output_recipe, resources_input_recipe_); + std::vector actual_output_recipe_from_vector = client.getOutputRecipe(); + it = std::find(actual_output_recipe_from_vector.begin(), actual_output_recipe_from_vector.end(), timestamp); + EXPECT_FALSE(it == actual_output_recipe_from_vector.end()); } int main(int argc, char* argv[])