Skip to content

Commit ad96a0a

Browse files
author
Pablo David Aranda Rodriguez
committed
Added getter input recipe for Driver. Added init tests for UrDriver
1 parent e11e60b commit ad96a0a

4 files changed

Lines changed: 107 additions & 0 deletions

File tree

include/ur_client_library/rtde/rtde_client.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,16 @@ class RTDEClient
222222
return output_recipe_;
223223
}
224224

225+
/*!
226+
* \brief Getter for the RTDE input recipe.
227+
*
228+
* \returns The input recipe
229+
*/
230+
std::vector<std::string> getInputRecipe()
231+
{
232+
return input_recipe_;
233+
}
234+
225235
// Reads output or input recipe from a file
226236
static std::vector<std::string> readRecipe(const std::string& recipe_file);
227237

include/ur_client_library/ur/ur_driver.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,13 @@ class UrDriver
839839
*/
840840
std::vector<std::string> getRTDEOutputRecipe();
841841

842+
/*!
843+
* \brief Getter for the RTDE input recipe used in the RTDE client.
844+
*
845+
* \returns The used RTDE input recipe
846+
*/
847+
std::vector<std::string> getRTDEInputRecipe();
848+
842849
/*!
843850
* \brief Set the Keepalive count. This will set the number of allowed timeout reads on the robot.
844851
*

src/ur/ur_driver.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,11 @@ std::vector<std::string> UrDriver::getRTDEOutputRecipe()
632632
return rtde_client_->getOutputRecipe();
633633
}
634634

635+
std::vector<std::string> UrDriver::getRTDEInputRecipe()
636+
{
637+
return rtde_client_->getInputRecipe();
638+
}
639+
635640
void UrDriver::setKeepaliveCount(const uint32_t count)
636641
{
637642
URCL_LOG_WARN("DEPRECATION NOTICE: Setting the keepalive count has been deprecated. Instead use the "

tests/test_ur_driver.cpp

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,51 @@
3333
#include <ur_client_library/ur/dashboard_client.h>
3434
#include <ur_client_library/ur/ur_driver.h>
3535
#include <ur_client_library/example_robot_wrapper.h>
36+
#include <algorithm>
3637
#include "test_utils.h"
3738

3839
using namespace urcl;
3940

4041
const std::string SCRIPT_FILE = "../resources/external_control.urscript";
4142
const std::string OUTPUT_RECIPE = "resources/rtde_output_recipe.txt";
4243
const std::string INPUT_RECIPE = "resources/rtde_input_recipe.txt";
44+
const std::vector<std::string> OUTPUT_RECIPE_VECTOR = { "timestamp",
45+
"actual_qd",
46+
"speed_scaling",
47+
"target_speed_fraction",
48+
"runtime_state",
49+
"actual_TCP_force",
50+
"actual_TCP_pose",
51+
"actual_digital_input_bits",
52+
"actual_digital_output_bits",
53+
"standard_analog_input0",
54+
"standard_analog_input1",
55+
"standard_analog_output0",
56+
"standard_analog_output1",
57+
"analog_io_types",
58+
"tool_mode",
59+
"tool_analog_input_types",
60+
"tool_analog_input0",
61+
"tool_analog_input1",
62+
"tool_output_voltage",
63+
"tool_output_current",
64+
"tool_temperature",
65+
"robot_mode",
66+
"safety_mode",
67+
"robot_status_bits",
68+
"safety_status_bits",
69+
"actual_current",
70+
"tcp_offset" };
71+
const std::vector<std::string> INPUT_RECIPE_VECTOR = {
72+
"speed_slider_mask", "standard_digital_output_mask",
73+
"standard_digital_output", "configurable_digital_output_mask",
74+
"configurable_digital_output", "tool_digital_output_mask",
75+
"tool_digital_output", "standard_analog_output_mask",
76+
"standard_analog_output_type", "standard_analog_output_0",
77+
"standard_analog_output_1"
78+
};
79+
const std::string OUTPUT_RECIPE_VECTOR_EXCLUDED_VALUE = "actual_q";
80+
const std::string INPUT_RECIPE_VECTOR_EXCLUDED_VALUE = "speed_slider_fraction";
4381
const std::string CALIBRATION_CHECKSUM = "calib_12788084448423163542";
4482
std::string g_ROBOT_IP = "192.168.56.101";
4583
bool g_HEADLESS = true;
@@ -310,6 +348,53 @@ TEST(UrDriverInitTest, setting_connection_limits_works_correctly)
310348
EXPECT_THROW(UrDriver ur_driver(config), UrException);
311349
}
312350

351+
TEST(UrDriverInitTest, no_recipe_throws_error)
352+
{
353+
UrDriverConfiguration config;
354+
config.socket_reconnect_attempts = 1;
355+
config.socket_reconnection_timeout = std::chrono::milliseconds(200);
356+
config.robot_ip = g_ROBOT_IP; // That IP address should not exist on the test network
357+
config.headless_mode = g_HEADLESS;
358+
359+
EXPECT_THROW(UrDriver ur_driver(config), UrException);
360+
}
361+
362+
TEST(UrDriverInitTest, non_existing_recipe_file_throws_exception)
363+
{
364+
UrDriverConfiguration config;
365+
config.socket_reconnect_attempts = 1;
366+
config.socket_reconnection_timeout = std::chrono::milliseconds(200);
367+
config.robot_ip = g_ROBOT_IP; // That IP address should not exist on the test network
368+
config.input_recipe_file = " ";
369+
config.output_recipe_file = OUTPUT_RECIPE;
370+
config.headless_mode = g_HEADLESS;
371+
372+
EXPECT_THROW(UrDriver ur_driver(config), UrException);
373+
374+
config.input_recipe_file = INPUT_RECIPE;
375+
config.output_recipe_file = " ";
376+
}
377+
378+
TEST(UrDriverInitTest, both_recipe_file_and_vector_select_file)
379+
{
380+
UrDriverConfiguration config;
381+
config.socket_reconnect_attempts = 1;
382+
config.socket_reconnection_timeout = std::chrono::milliseconds(200);
383+
config.robot_ip = g_ROBOT_IP; // That IP address should not exist on the test network
384+
config.input_recipe_file = INPUT_RECIPE;
385+
config.output_recipe_file = OUTPUT_RECIPE;
386+
config.input_recipe = INPUT_RECIPE_VECTOR;
387+
config.output_recipe = OUTPUT_RECIPE_VECTOR;
388+
config.headless_mode = g_HEADLESS;
389+
390+
auto driver = UrDriver(config);
391+
auto output_recipe = driver.getRTDEOutputRecipe();
392+
EXPECT_TRUE(std::find(output_recipe.begin(), output_recipe.end(), OUTPUT_RECIPE_VECTOR_EXCLUDED_VALUE) !=
393+
output_recipe.end());
394+
auto input_recipe = driver.getRTDEInputRecipe();
395+
EXPECT_TRUE(std::find(input_recipe.begin(), input_recipe.end(), INPUT_RECIPE_VECTOR_EXCLUDED_VALUE) !=
396+
output_recipe.end());
397+
}
313398
// TODO we should add more tests for the UrDriver class.
314399

315400
int main(int argc, char* argv[])

0 commit comments

Comments
 (0)