|
28 | 28 |
|
29 | 29 | #include "ur_client_library/rtde/rtde_client.h" |
30 | 30 | #include "ur_client_library/exceptions.h" |
| 31 | +#include "ur_client_library/log.h" |
31 | 32 | #include <algorithm> |
| 33 | +#include <chrono> |
32 | 34 |
|
33 | 35 | namespace urcl |
34 | 36 | { |
@@ -74,26 +76,34 @@ RTDEClient::~RTDEClient() |
74 | 76 | disconnect(); |
75 | 77 | } |
76 | 78 |
|
77 | | -bool RTDEClient::init(const size_t max_num_tries, const std::chrono::milliseconds reconnection_time) |
| 79 | +bool RTDEClient::init(const size_t max_connection_attempts, const std::chrono::milliseconds reconnection_timeout, |
| 80 | + const size_t max_initialization_attempts, const std::chrono::milliseconds initialization_timeout) |
78 | 81 | { |
| 82 | + if (max_initialization_attempts <= 0) |
| 83 | + { |
| 84 | + throw UrException("The number of initialization attempts has to be greater than 0."); |
| 85 | + } |
| 86 | + |
79 | 87 | if (client_state_ > ClientState::UNINITIALIZED) |
80 | 88 | { |
81 | 89 | return true; |
82 | 90 | } |
83 | 91 |
|
84 | 92 | unsigned int attempts = 0; |
85 | | - while (attempts < MAX_INITIALIZE_ATTEMPTS) |
| 93 | + while (attempts < max_initialization_attempts) |
86 | 94 | { |
87 | | - setupCommunication(max_num_tries, reconnection_time); |
| 95 | + setupCommunication(max_connection_attempts, reconnection_timeout); |
88 | 96 | if (client_state_ == ClientState::INITIALIZED) |
89 | 97 | return true; |
90 | 98 |
|
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++; |
| 99 | + if (++attempts < max_initialization_attempts) |
| 100 | + { |
| 101 | + URCL_LOG_ERROR("Failed to initialize RTDE client, retrying in %d seconds", initialization_timeout.count() / 1000); |
| 102 | + std::this_thread::sleep_for(initialization_timeout); |
| 103 | + } |
94 | 104 | } |
95 | 105 | std::stringstream ss; |
96 | | - ss << "Failed to initialize RTDE client after " << MAX_INITIALIZE_ATTEMPTS << " attempts"; |
| 106 | + ss << "Failed to initialize RTDE client after " << max_initialization_attempts << " attempts"; |
97 | 107 | throw UrException(ss.str()); |
98 | 108 | } |
99 | 109 |
|
@@ -241,7 +251,7 @@ void RTDEClient::queryURControlVersion() |
241 | 251 | else |
242 | 252 | { |
243 | 253 | std::stringstream ss; |
244 | | - ss << "Did not receive protocol negotiation answer from robot. Message received instead: " << std::endl |
| 254 | + ss << "Did not receive URControl version from robot. Message received instead: " << std::endl |
245 | 255 | << package->toString() << ". Retrying..."; |
246 | 256 | num_retries++; |
247 | 257 | URCL_LOG_WARN("%s", ss.str().c_str()); |
|
0 commit comments