Skip to content

Commit 659ddeb

Browse files
committed
Added integration tests for instruction executor
1 parent 8b1af75 commit 659ddeb

File tree

6 files changed

+328
-35
lines changed

6 files changed

+328
-35
lines changed

examples/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ project(ur_driver_examples)
77
# # Check C++11 support / enable global pedantic and Wall
88
# #
99
include(DefineCXX17CompilerFlag)
10-
#DEFINE_CXX_17_COMPILER_FLAG(CXX17_FLAG)
11-
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic")
12-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20")
10+
DEFINE_CXX_17_COMPILER_FLAG(CXX17_FLAG)
11+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic")
1312

1413
add_executable(driver_example
1514
full_driver.cpp)

include/ur_client_library/control/motion_primitives.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ enum class MotionType : uint8_t
4646
MOVEP = 2,
4747
MOVEC = 3,
4848
SPLINE = 51,
49+
UNKNOWN = 255
4950
};
5051
struct MotionPrimitive
5152
{
@@ -91,4 +92,4 @@ struct MoveLPrimitive : public MotionPrimitive
9192
};
9293
} // namespace control
9394
} // namespace urcl
94-
#endif // UR_CLIENT_LIBRARY_MOTION_PRIMITIVES_H_INCLUDED
95+
#endif // UR_CLIENT_LIBRARY_MOTION_PRIMITIVES_H_INCLUDED

include/ur_client_library/ur/instruction_executor.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class InstructionExecutor
5656
*
5757
* \param motion_sequence The sequence of motion primitives to execute
5858
*/
59-
void executeMotion(const std::vector<std::shared_ptr<control::MotionPrimitive>>& motion_sequence);
59+
bool executeMotion(const std::vector<std::shared_ptr<control::MotionPrimitive>>& motion_sequence);
6060

6161
/**
6262
* \brief Move the robot to a joint target.
@@ -96,9 +96,10 @@ class InstructionExecutor
9696
void trajDoneCallback(const urcl::control::TrajectoryResult& result);
9797
void trajDisconnectCallback(const int filedescriptor);
9898
std::shared_ptr<urcl::UrDriver> driver_;
99-
bool trajectory_done_ = false;
100-
urcl::control::TrajectoryResult result_;
99+
std::atomic<bool> trajectory_running_ = false;
100+
std::mutex trajectory_result_mutex_;
101+
urcl::control::TrajectoryResult trajectory_result_;
101102
};
102103
} // namespace urcl
103104

104-
#endif // UR_CLIENT_LIBRARY_INSTRUCTION_EXECUTOR_H_INCLUDED
105+
#endif // UR_CLIENT_LIBRARY_INSTRUCTION_EXECUTOR_H_INCLUDED

src/ur/instruction_executor.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,30 @@
3131
#include "ur_client_library/ur/instruction_executor.h"
3232
void urcl::InstructionExecutor::trajDoneCallback(const urcl::control::TrajectoryResult& result)
3333
{
34-
result_ = result;
35-
trajectory_done_ = true;
34+
std::unique_lock<std::mutex> lock(trajectory_result_mutex_);
35+
trajectory_result_ = result;
36+
trajectory_running_ = false;
3637
}
3738
void urcl::InstructionExecutor::trajDisconnectCallback(const int filedescriptor)
3839
{
3940
URCL_LOG_INFO("Trajectory disconnect");
40-
result_ = urcl::control::TrajectoryResult::TRAJECTORY_RESULT_FAILURE;
41-
trajectory_done_ = true;
41+
std::unique_lock<std::mutex> lock(trajectory_result_mutex_);
42+
if (trajectory_running_)
43+
{
44+
trajectory_result_ = urcl::control::TrajectoryResult::TRAJECTORY_RESULT_FAILURE;
45+
trajectory_running_ = false;
46+
}
4247
}
43-
void urcl::InstructionExecutor::executeMotion(
48+
bool urcl::InstructionExecutor::executeMotion(
4449
const std::vector<std::shared_ptr<control::MotionPrimitive>>& motion_sequence)
4550
{
46-
trajectory_done_ = false;
4751
if (!driver_->writeTrajectoryControlMessage(urcl::control::TrajectoryControlMessage::TRAJECTORY_START,
4852
motion_sequence.size()))
4953
{
5054
URCL_LOG_ERROR("Cannot send trajectory control command. No client connected?");
51-
return;
52-
;
55+
std::unique_lock<std::mutex> lock(trajectory_result_mutex_);
56+
trajectory_result_ = urcl::control::TrajectoryResult::TRAJECTORY_RESULT_FAILURE;
57+
return false;
5358
}
5459

5560
for (const auto& primitive : motion_sequence)
@@ -69,43 +74,38 @@ void urcl::InstructionExecutor::executeMotion(
6974
urcl::vector6d_t pose_vec = { movel_primitive->target_pose.x, movel_primitive->target_pose.y,
7075
movel_primitive->target_pose.z, movel_primitive->target_pose.rx,
7176
movel_primitive->target_pose.ry, movel_primitive->target_pose.rz };
72-
if (!driver_->writeTrajectoryPoint(pose_vec, primitive->acceleration, primitive->velocity, true,
73-
primitive->duration.count(), primitive->blend_radius))
74-
{
75-
URCL_LOG_ERROR("Cannot send trajectory control command. No client connected?");
76-
return;
77-
}
77+
driver_->writeTrajectoryPoint(pose_vec, primitive->acceleration, primitive->velocity, true,
78+
primitive->duration.count(), primitive->blend_radius);
7879
break;
7980
}
8081
default:
8182
URCL_LOG_ERROR("Unsupported motion type");
82-
return;
83+
std::unique_lock<std::mutex> lock(trajectory_result_mutex_);
84+
trajectory_result_ = urcl::control::TrajectoryResult::TRAJECTORY_RESULT_FAILURE;
85+
return false;
8386
}
8487
}
88+
trajectory_running_ = true;
8589

86-
while (!trajectory_done_)
90+
while (trajectory_running_)
8791
{
8892
std::this_thread::sleep_for(std::chrono::milliseconds(100));
89-
if (!driver_->writeTrajectoryControlMessage(urcl::control::TrajectoryControlMessage::TRAJECTORY_NOOP))
90-
{
91-
URCL_LOG_ERROR("Cannot send trajectory control command. No client connected?");
92-
return;
93-
;
94-
}
93+
driver_->writeTrajectoryControlMessage(urcl::control::TrajectoryControlMessage::TRAJECTORY_NOOP);
9594
}
96-
URCL_LOG_INFO("Trajectory done with result %d", result_);
95+
URCL_LOG_INFO("Trajectory done with result %d", trajectory_result_);
96+
return true;
9797
}
9898
bool urcl::InstructionExecutor::moveJ(const urcl::vector6d_t& target, const double acceleration, const double velocity,
9999
const double time, const double blend_radius)
100100
{
101101
executeMotion({ std::make_shared<control::MoveJPrimitive>(
102102
target, blend_radius, std::chrono::milliseconds(static_cast<int>(time * 1000)), acceleration, velocity) });
103-
return result_ == urcl::control::TrajectoryResult::TRAJECTORY_RESULT_SUCCESS;
103+
return trajectory_result_ == urcl::control::TrajectoryResult::TRAJECTORY_RESULT_SUCCESS;
104104
}
105105
bool urcl::InstructionExecutor::moveL(const urcl::Pose& target, const double acceleration, const double velocity,
106106
const double time, const double blend_radius)
107107
{
108108
executeMotion({ std::make_shared<control::MoveLPrimitive>(
109109
target, blend_radius, std::chrono::milliseconds(static_cast<int>(time * 1000)), acceleration, velocity) });
110-
return result_ == urcl::control::TrajectoryResult::TRAJECTORY_RESULT_SUCCESS;
111-
}
110+
return trajectory_result_ == urcl::control::TrajectoryResult::TRAJECTORY_RESULT_SUCCESS;
111+
}

tests/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ if (INTEGRATION_TESTS)
6060
gtest_add_tests(TARGET ur_driver_tests
6161
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
6262
)
63+
64+
add_executable(instruction_executor_test test_instruction_executor.cpp)
65+
target_include_directories(instruction_executor_test PRIVATE ${GTEST_INCLUDE_DIRS})
66+
target_link_libraries(instruction_executor_test PRIVATE ur_client_library::urcl ${GTEST_LIBRARIES})
67+
gtest_add_tests(TARGET instruction_executor_test
68+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
69+
)
6370
else()
6471
message(STATUS "Skipping integration tests.")
6572
endif()
@@ -231,4 +238,4 @@ target_compile_options(control_mode_tests PRIVATE ${CXX17_FLAG})
231238
target_include_directories(control_mode_tests PRIVATE ${GTEST_INCLUDE_DIRS})
232239
target_link_libraries(control_mode_tests PRIVATE ur_client_library::urcl ${GTEST_LIBRARIES})
233240
gtest_add_tests(TARGET control_mode_tests
234-
)
241+
)

0 commit comments

Comments
 (0)