Skip to content

Commit

Permalink
Updated test to reflect changes to primary client
Browse files Browse the repository at this point in the history
  • Loading branch information
urmarp committed Jan 6, 2023
1 parent 438eb84 commit 3cd736a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
7 changes: 7 additions & 0 deletions include/ur_client_library/primary/primary_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ class PrimaryClient
*/
bool isInRemoteControl();

/*!
* \brief Starts the checkRemoteLocalControl thread.
*
* Starts the thread checking for remote or local control
*/
void startCheckRemoteControlThread();

/*!
* \brief Returns latest AdditionalInfo message
*
Expand Down
23 changes: 19 additions & 4 deletions src/primary/primary_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,20 @@ PrimaryClient::PrimaryClient(const std::string& robot_ip, const std::string& cal
"for details.");
}

// Check robot version
e_series_ = getVersionMessage()->major_version_ > 3;
if (e_series_)
rc_thread_ = std::thread(&PrimaryClient::checkRemoteLocalControl, this);
try
{
// Check if robot is e-series or not
e_series_ = getVersionMessage()->major_version_ > 3;
if (e_series_)
startCheckRemoteControlThread();
}
catch (const UrException& e)
{
URCL_LOG_WARN(e.what());
URCL_LOG_WARN("This message is only relevant if the robot is an e-series:\nThe thread checking if the robot is in "
"remote control or not has not been started. It needs to be started manually by calling the "
"startCheckRemoteControlThread() function");
}
}

PrimaryClient::~PrimaryClient()
Expand Down Expand Up @@ -171,6 +181,11 @@ void PrimaryClient::stop()
stream_->disconnect();
}

void PrimaryClient::startCheckRemoteControlThread()
{
rc_thread_ = std::thread(&PrimaryClient::checkRemoteLocalControl, this);
}

bool PrimaryClient::isInRemoteControl()
{
return in_remote_control_;
Expand Down
14 changes: 8 additions & 6 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,18 @@ if (INTEGRATION_TESTS)
target_link_libraries(dashboard_client_tests PRIVATE ur_client_library::urcl ${GTEST_LIBRARIES})
gtest_add_tests(TARGET dashboard_client_tests
)

add_executable(primary_client_tests test_primary_client.cpp)
target_compile_options(primary_client_tests PRIVATE ${CXX17_FLAG})
target_include_directories(primary_client_tests PRIVATE ${GTEST_INCLUDE_DIRS})
target_link_libraries(primary_client_tests PRIVATE ur_client_library::urcl ${GTEST_LIBRARIES})
gtest_add_tests(TARGET primary_client_tests
)
else()
message(STATUS "Skipping integration tests.")
endif()

add_executable(primary_client_tests test_primary_client.cpp)
target_compile_options(primary_client_tests PRIVATE ${CXX17_FLAG})
target_include_directories(primary_client_tests PRIVATE ${GTEST_INCLUDE_DIRS})
target_link_libraries(primary_client_tests PRIVATE ur_client_library::urcl ${GTEST_LIBRARIES})
gtest_add_tests(TARGET primary_client_tests
)


add_executable(primary_parser_tests test_primary_parser.cpp)
target_compile_options(primary_parser_tests PRIVATE ${CXX17_FLAG})
Expand Down
5 changes: 5 additions & 0 deletions tests/test_primary_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ TEST_F(PrimaryClientTest, check_remote_control)
client_.reset(new primary_interface::PrimaryClient(ROBOT_IP, ""));
std::this_thread::sleep_for(std::chrono::milliseconds(1000)); // Let connections set up

if (!client_->e_series_)
{
client_->startCheckRemoteControlThread();
}

// Disconnect from URSim servers and connect to fake servers
client_->pipeline_->stop();
client_->stream_->disconnect();
Expand Down

0 comments on commit 3cd736a

Please sign in to comment.