Skip to content

Commit

Permalink
Adds test of new vectorized constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
Dag-Are Trydal authored and urrsk committed Aug 1, 2023
1 parent 6272e34 commit b5c4bd1
Showing 1 changed file with 77 additions and 49 deletions.
126 changes: 77 additions & 49 deletions tests/test_rtde_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class RTDEClientTest : public ::testing::Test
protected:
void SetUp()
{
client_.reset(new rtde_interface::RTDEClient(ROBOT_IP, notifier_, output_recipe_, input_recipe_));
client_.reset(new rtde_interface::RTDEClient(ROBOT_IP, notifier_, output_recipe_file_, input_recipe_file_));
}

void TearDown()
Expand All @@ -50,51 +50,95 @@ class RTDEClientTest : public ::testing::Test
std::this_thread::sleep_for(std::chrono::seconds(1));
}

std::string output_recipe_ = "resources/rtde_output_recipe.txt";
std::string input_recipe_ = "resources/rtde_input_recipe.txt";
std::string output_recipe_file_ = "resources/rtde_output_recipe.txt";
std::string input_recipe_file_ = "resources/rtde_input_recipe.txt";
comm::INotifier notifier_;
std::unique_ptr<rtde_interface::RTDEClient> client_;
};

std::vector<std::string> 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<std::string> 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)
{
EXPECT_TRUE(client_->init());
}

TEST_F(RTDEClientTest, no_recipe)
{
std::string output_recipe = "";
std::string input_recipe = "";
EXPECT_THROW(client_.reset(new rtde_interface::RTDEClient(ROBOT_IP, notifier_, output_recipe, input_recipe)),
UrException);
std::string output_recipe_file = "";
std::string input_recipe_file = "";
EXPECT_THROW(
client_.reset(new rtde_interface::RTDEClient(ROBOT_IP, notifier_, output_recipe_file, input_recipe_file)),
UrException);

// Only input recipe is unconfigured
EXPECT_THROW(client_.reset(new rtde_interface::RTDEClient(ROBOT_IP, notifier_, output_recipe_, input_recipe)),
UrException);
EXPECT_THROW(
client_.reset(new rtde_interface::RTDEClient(ROBOT_IP, notifier_, output_recipe_file_, input_recipe_file)),
UrException);
}

TEST_F(RTDEClientTest, empty_recipe)
TEST_F(RTDEClientTest, empty_recipe_file)
{
std::string output_recipe = "resources/empty.txt";
std::string input_recipe = "resources/empty.txt";
client_.reset(new rtde_interface::RTDEClient(ROBOT_IP, notifier_, output_recipe, input_recipe));
std::string output_recipe_file = "resources/empty.txt";
std::string input_recipe_file = "resources/empty.txt";
client_.reset(new rtde_interface::RTDEClient(ROBOT_IP, notifier_, output_recipe_file, input_recipe_file));

EXPECT_THROW(client_->init(), UrException);

// Only input recipe is empty
client_.reset(new rtde_interface::RTDEClient(ROBOT_IP, notifier_, output_recipe_, input_recipe));
client_.reset(new rtde_interface::RTDEClient(ROBOT_IP, notifier_, output_recipe_file_, input_recipe_file));

EXPECT_THROW(client_->init(), UrException);
}

TEST_F(RTDEClientTest, invalid_target_frequency)
{
// Setting target frequency below 0 or above 500, should throw an exception
client_.reset(new rtde_interface::RTDEClient(ROBOT_IP, notifier_, output_recipe_, input_recipe_, -1.0));
client_.reset(new rtde_interface::RTDEClient(ROBOT_IP, notifier_, output_recipe_file_, input_recipe_file_, -1.0));

EXPECT_THROW(client_->init(), UrException);

client_.reset(new rtde_interface::RTDEClient(ROBOT_IP, notifier_, output_recipe_, input_recipe_, 1000));
client_.reset(new rtde_interface::RTDEClient(ROBOT_IP, notifier_, output_recipe_file_, input_recipe_file_, 1000));

EXPECT_THROW(client_->init(), UrException);
}
Expand All @@ -113,7 +157,7 @@ TEST_F(RTDEClientTest, unconfigured_target_frequency)

TEST_F(RTDEClientTest, set_target_frequency)
{
client_.reset(new rtde_interface::RTDEClient(ROBOT_IP, notifier_, output_recipe_, input_recipe_, 1));
client_.reset(new rtde_interface::RTDEClient(ROBOT_IP, notifier_, output_recipe_file_, input_recipe_file_, 1));
client_->init();

// Maximum frequency should still be equal to the robot's maximum frequency
Expand Down Expand Up @@ -198,41 +242,25 @@ TEST_F(RTDEClientTest, pause_client)
EXPECT_TRUE(client_->pause());
}

TEST_F(RTDEClientTest, output_recipe)
TEST_F(RTDEClientTest, output_recipe_file)
{
std::vector<std::string> expected_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<std::string> actual_output_recipe = client_->getOutputRecipe();
for (unsigned int i = 0; i < expected_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]);
}
}

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);

std::vector<std::string> output_recipe_from_file = client_->getOutputRecipe();
std::vector<std::string> output_recipe_from_vector = client.getOutputRecipe();
for (unsigned int i = 0; i < output_recipe_from_file.size(); ++i)
{
EXPECT_EQ(expected_output_recipe[i], actual_output_recipe[i]);
EXPECT_EQ(output_recipe_from_file[i], output_recipe_from_vector[i]);
}
}

Expand Down

0 comments on commit b5c4bd1

Please sign in to comment.