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
3839using namespace urcl ;
3940
4041const std::string SCRIPT_FILE = " ../resources/external_control.urscript" ;
4142const std::string OUTPUT_RECIPE = " resources/rtde_output_recipe.txt" ;
4243const 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" ;
4381const std::string CALIBRATION_CHECKSUM = " calib_12788084448423163542" ;
4482std::string g_ROBOT_IP = " 192.168.56.101" ;
4583bool g_HEADLESS = true ;
@@ -310,6 +348,78 @@ 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, initialization_from_vectors)
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 = INPUT_RECIPE_VECTOR;
369+ config.output_recipe = OUTPUT_RECIPE_VECTOR;
370+ config.headless_mode = g_HEADLESS;
371+ config.script_file = SCRIPT_FILE;
372+
373+ EXPECT_NO_THROW (UrDriver ur_driver (config));
374+ }
375+
376+ TEST (UrDriverInitTest, non_existing_output_recipe_file_throws_exception)
377+ {
378+ UrDriverConfiguration config;
379+ config.socket_reconnect_attempts = 1 ;
380+ config.socket_reconnection_timeout = std::chrono::milliseconds (200 );
381+ config.robot_ip = g_ROBOT_IP; // That IP address should not exist on the test network
382+ config.input_recipe_file = INPUT_RECIPE;
383+ config.output_recipe_file = " " ;
384+ config.headless_mode = g_HEADLESS;
385+
386+ EXPECT_THROW (UrDriver ur_driver (config), UrException);
387+ }
388+
389+ TEST (UrDriverInitTest, non_existing_input_recipe_file_does_not_throw_exception)
390+ {
391+ UrDriverConfiguration config;
392+ config.socket_reconnect_attempts = 1 ;
393+ config.socket_reconnection_timeout = std::chrono::milliseconds (200 );
394+ config.robot_ip = g_ROBOT_IP; // That IP address should not exist on the test network
395+ config.output_recipe_file = OUTPUT_RECIPE;
396+ config.headless_mode = g_HEADLESS;
397+ config.script_file = SCRIPT_FILE;
398+
399+ EXPECT_NO_THROW (UrDriver ur_driver (config));
400+ }
401+
402+ TEST (UrDriverInitTest, both_recipe_file_and_vector_select_vector)
403+ {
404+ UrDriverConfiguration config;
405+ config.socket_reconnect_attempts = 1 ;
406+ config.socket_reconnection_timeout = std::chrono::milliseconds (200 );
407+ config.robot_ip = g_ROBOT_IP; // That IP address should not exist on the test network
408+ config.input_recipe_file = INPUT_RECIPE;
409+ config.output_recipe_file = OUTPUT_RECIPE;
410+ config.input_recipe = INPUT_RECIPE_VECTOR;
411+ config.output_recipe = OUTPUT_RECIPE_VECTOR;
412+ config.headless_mode = g_HEADLESS;
413+ config.script_file = SCRIPT_FILE;
414+
415+ auto driver = UrDriver (config);
416+ auto output_recipe = driver.getRTDEOutputRecipe ();
417+ EXPECT_TRUE (std::find (output_recipe.begin (), output_recipe.end (), OUTPUT_RECIPE_VECTOR_EXCLUDED_VALUE) ==
418+ output_recipe.end ());
419+ auto input_recipe = driver.getRTDEInputRecipe ();
420+ EXPECT_TRUE (std::find (input_recipe.begin (), input_recipe.end (), INPUT_RECIPE_VECTOR_EXCLUDED_VALUE) ==
421+ input_recipe.end ());
422+ }
313423// TODO we should add more tests for the UrDriver class.
314424
315425int main (int argc, char * argv[])
@@ -332,4 +442,4 @@ int main(int argc, char* argv[])
332442 }
333443
334444 return RUN_ALL_TESTS ();
335- }
445+ }
0 commit comments