Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/rtde/rtde_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,27 @@ bool RTDEClient::init(const size_t max_connection_attempts, const std::chrono::m
}

unsigned int attempts = 0;
std::stringstream ss;
while (attempts < max_initialization_attempts)
{
setupCommunication(max_connection_attempts, reconnection_timeout);
try
{
setupCommunication(max_connection_attempts, reconnection_timeout);
}
catch (const UrException& exc)
{
ss << exc.what() << std::endl;
}
if (client_state_ == ClientState::INITIALIZED)
{
return true;

}
if (++attempts < max_initialization_attempts)
{
URCL_LOG_ERROR("Failed to initialize RTDE client, retrying in %d seconds", initialization_timeout.count() / 1000);
std::this_thread::sleep_for(initialization_timeout);
}
}
std::stringstream ss;
ss << "Failed to initialize RTDE client after " << max_initialization_attempts << " attempts";
throw UrException(ss.str());
}
Expand Down Expand Up @@ -709,4 +717,4 @@ std::vector<std::string> RTDEClient::splitVariableTypes(const std::string& varia
return result;
}
} // namespace rtde_interface
} // namespace urcl
} // namespace urcl
7 changes: 4 additions & 3 deletions tests/test_rtde_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,14 @@ TEST_F(RTDEClientTest, connect_non_running_robot)
client_.reset(
new rtde_interface::RTDEClient("192.168.56.123", notifier_, resources_output_recipe_, resources_input_recipe_));
auto start = std::chrono::system_clock::now();
EXPECT_THROW(client_->init(2, std::chrono::milliseconds(500)), UrException);
EXPECT_THROW(client_->init(2, std::chrono::milliseconds(500), 1), UrException);
auto end = std::chrono::system_clock::now();
auto elapsed = end - start;
// This is only a rough estimate, obviously.
// Since this isn't done on the loopback device, trying to open a socket on a non-existing address
// takes considerably longer.
EXPECT_LT(elapsed, 2 * comm::TCPSocket::DEFAULT_RECONNECTION_TIME);
EXPECT_LT(std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count(),
2 * comm::TCPSocket::DEFAULT_RECONNECTION_TIME.count());
}

TEST_F(RTDEClientTest, check_all_rtde_output_variables_exist)
Expand Down Expand Up @@ -426,4 +427,4 @@ int main(int argc, char* argv[])
}

return RUN_ALL_TESTS();
}
}
Loading