Skip to content

Commit d3e91d9

Browse files
committed
Do not wait after last attempt to establish a connection
1 parent 97ad825 commit d3e91d9

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

src/comm/tcp_socket.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,25 +109,24 @@ bool TCPSocket::setup(const std::string& host, const int port, const size_t max_
109109

110110
freeaddrinfo(result);
111111

112-
if (max_num_tries > 0)
112+
if (!connected)
113113
{
114-
if (connect_counter++ >= max_num_tries)
114+
state_ = SocketState::Invalid;
115+
if (++connect_counter >= max_num_tries && max_num_tries > 0)
115116
{
116117
URCL_LOG_ERROR("Failed to establish connection for %s:%d after %d tries", host.c_str(), port, max_num_tries);
117-
state_ = SocketState::Invalid;
118118
return false;
119119
}
120-
}
121-
122-
if (!connected)
123-
{
124-
state_ = SocketState::Invalid;
125-
std::stringstream ss;
126-
ss << "Failed to connect to robot on IP " << host_name
127-
<< ". Please check that the robot is booted and reachable on " << host_name << ". Retrying in "
128-
<< std::chrono::duration_cast<std::chrono::duration<float>>(reconnection_time_resolved).count() << " seconds";
129-
URCL_LOG_ERROR("%s", ss.str().c_str());
130-
std::this_thread::sleep_for(reconnection_time_resolved);
120+
else
121+
{
122+
std::stringstream ss;
123+
ss << "Failed to connect to robot on IP " << host_name << ":" << port
124+
<< ". Please check that the robot is booted and reachable on " << host_name << ". Retrying in "
125+
<< std::chrono::duration_cast<std::chrono::duration<float>>(reconnection_time_resolved).count()
126+
<< " seconds.";
127+
URCL_LOG_ERROR("%s", ss.str().c_str());
128+
std::this_thread::sleep_for(reconnection_time_resolved);
129+
}
131130
}
132131
}
133132
setupOptions();

src/rtde/rtde_client.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828

2929
#include "ur_client_library/rtde/rtde_client.h"
3030
#include "ur_client_library/exceptions.h"
31+
#include "ur_client_library/log.h"
3132
#include <algorithm>
33+
#include <chrono>
3234

3335
namespace urcl
3436
{
@@ -88,9 +90,11 @@ bool RTDEClient::init(const size_t max_num_tries, const std::chrono::millisecond
8890
if (client_state_ == ClientState::INITIALIZED)
8991
return true;
9092

91-
URCL_LOG_ERROR("Failed to initialize RTDE client, retrying in 10 seconds");
92-
std::this_thread::sleep_for(std::chrono::seconds(10));
93-
attempts++;
93+
if (++attempts < MAX_INITIALIZE_ATTEMPTS)
94+
{
95+
URCL_LOG_ERROR("Failed to initialize RTDE client, retrying in 10 seconds");
96+
std::this_thread::sleep_for(std::chrono::seconds(10));
97+
}
9498
}
9599
std::stringstream ss;
96100
ss << "Failed to initialize RTDE client after " << MAX_INITIALIZE_ATTEMPTS << " attempts";
@@ -241,7 +245,7 @@ void RTDEClient::queryURControlVersion()
241245
else
242246
{
243247
std::stringstream ss;
244-
ss << "Did not receive protocol negotiation answer from robot. Message received instead: " << std::endl
248+
ss << "Did not receive URControl version from robot. Message received instead: " << std::endl
245249
<< package->toString() << ". Retrying...";
246250
num_retries++;
247251
URCL_LOG_WARN("%s", ss.str().c_str());

0 commit comments

Comments
 (0)