|
29 | 29 | // -- END LICENSE BLOCK ------------------------------------------------ |
30 | 30 |
|
31 | 31 | #include <gtest/gtest.h> |
| 32 | +#include <algorithm> |
32 | 33 | #include <iostream> |
| 34 | +#include <regex> |
33 | 35 | #include <thread> |
34 | 36 | #include "ur_client_library/ur/instruction_executor.h" |
35 | 37 | #include "ur_client_library/control/motion_primitives.h" |
@@ -70,6 +72,16 @@ class InstructionExecutorTest : public ::testing::Test |
70 | 72 | ASSERT_TRUE(g_my_robot->waitForProgramRunning()); |
71 | 73 | } |
72 | 74 | } |
| 75 | + void TearDown() |
| 76 | + { |
| 77 | + g_my_robot->ur_driver_->stopControl(); |
| 78 | + g_my_robot->waitForProgramNotRunning(1000); |
| 79 | + } |
| 80 | + |
| 81 | + static void TearDownTestSuite() |
| 82 | + { |
| 83 | + g_my_robot.reset(); |
| 84 | + } |
73 | 85 | }; |
74 | 86 |
|
75 | 87 | TEST_F(InstructionExecutorTest, execute_motion_sequence_success) |
@@ -225,6 +237,49 @@ TEST_F(InstructionExecutorTest, canceling_without_running_trajectory_returns_fal |
225 | 237 | ASSERT_FALSE(executor_->cancelMotion()); |
226 | 238 | } |
227 | 239 |
|
| 240 | +TEST(InstructionExecutorTestStandalone, canceling_without_receiving_answer_returns_false) |
| 241 | +{ |
| 242 | + std::ifstream in_file(SCRIPT_FILE); |
| 243 | + std::ofstream out_file; |
| 244 | + const std::string test_script_file = "test_script.urscript"; |
| 245 | + out_file.open(test_script_file); |
| 246 | + |
| 247 | + std::string line; |
| 248 | + std::regex delete_me("socket_send_int\\(TRAJECTORY_RESULT_CANCELED,\\s*\"trajectory_socket\"\\)"); |
| 249 | + while (std::getline(in_file, line)) |
| 250 | + { |
| 251 | + std::smatch delete_match; |
| 252 | + if (!std::regex_search(line, delete_match, delete_me)) |
| 253 | + { |
| 254 | + out_file << line << std::endl; |
| 255 | + } |
| 256 | + } |
| 257 | + out_file.close(); |
| 258 | + auto my_robot = std::make_unique<ExampleRobotWrapper>(ROBOT_IP, OUTPUT_RECIPE, INPUT_RECIPE, g_HEADLESS, |
| 259 | + "external_control.urp", test_script_file); |
| 260 | + auto executor = std::make_unique<InstructionExecutor>(my_robot->ur_driver_); |
| 261 | + my_robot->clearProtectiveStop(); |
| 262 | + // Make sure script is running on the robot |
| 263 | + if (!my_robot->waitForProgramRunning()) |
| 264 | + { |
| 265 | + my_robot->resendRobotProgram(); |
| 266 | + ASSERT_TRUE(my_robot->waitForProgramRunning()); |
| 267 | + } |
| 268 | + ASSERT_TRUE(executor->moveJ({ -1.59, -1.72, -2.2, -0.8, 1.6, 0.2 }, 2.0, 2.0)); |
| 269 | + std::thread move_thread([&executor]() { executor->moveJ({ -1.57, -1.6, 1.6, -0.7, 0.7, 2.7 }, 0.1, 0.1); }); |
| 270 | + bool is_trajectory_running = false; |
| 271 | + std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now(); |
| 272 | + while (!is_trajectory_running || std::chrono::steady_clock::now() > start + std::chrono::seconds(5)) |
| 273 | + { |
| 274 | + is_trajectory_running = executor->isTrajectoryRunning(); |
| 275 | + std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
| 276 | + } |
| 277 | + ASSERT_TRUE(executor->isTrajectoryRunning()); |
| 278 | + ASSERT_FALSE(executor->cancelMotion()); |
| 279 | + move_thread.join(); |
| 280 | + std::remove(test_script_file.c_str()); |
| 281 | +} |
| 282 | + |
228 | 283 | TEST_F(InstructionExecutorTest, canceling_with_running_trajectory_succeeds) |
229 | 284 | { |
230 | 285 | ASSERT_TRUE(executor_->moveJ({ -1.59, -1.72, -2.2, -0.8, 1.6, 0.2 }, 2.0, 2.0)); |
|
0 commit comments