Skip to content

Commit 316b1b3

Browse files
authored
RTDEClient: pause and stop in destructor only if running (#257)
Otherwise we produce an error when destructing an initialized, but non-started client.
1 parent d348df3 commit 316b1b3

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/rtde/rtde_client.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ void RTDEClient::queryURControlVersion()
256256

257257
void RTDEClient::resetOutputRecipe(const std::vector<std::string> new_recipe)
258258
{
259-
prod_->teardownProducer();
260259
disconnect();
261260

262261
output_recipe_.assign(new_recipe.begin(), new_recipe.end());
@@ -332,10 +331,11 @@ void RTDEClient::setupOutputs(const uint16_t protocol_version)
332331
if (!unavailable_variables.empty())
333332
{
334333
std::stringstream error_message;
335-
error_message << "The following variables are not recognized by the robot: ";
336-
std::for_each(unavailable_variables.begin(), unavailable_variables.end(),
337-
[&error_message](const std::string& variable_name) { error_message << variable_name << " "; });
338-
error_message << ". Either your output recipe contains errors "
334+
error_message << "The following variables are not recognized by the robot:";
335+
std::for_each(
336+
unavailable_variables.begin(), unavailable_variables.end(),
337+
[&error_message](const std::string& variable_name) { error_message << "\n - '" << variable_name << "'"; });
338+
error_message << "\nEither your output recipe contains errors "
339339
"or the urcontrol version does not support "
340340
"them.";
341341

@@ -346,6 +346,7 @@ void RTDEClient::setupOutputs(const uint16_t protocol_version)
346346

347347
// Some variables are not available so retry setting up the communication with a stripped-down output recipe
348348
resetOutputRecipe(available_variables);
349+
return;
349350
}
350351
else
351352
{
@@ -445,10 +446,16 @@ void RTDEClient::setupInputs()
445446
void RTDEClient::disconnect()
446447
{
447448
// If communication is started it should be paused before disconnecting
448-
if (client_state_ > ClientState::UNINITIALIZED)
449+
if (client_state_ == ClientState::RUNNING)
450+
{
451+
pause();
452+
}
453+
if (client_state_ >= ClientState::INITIALIZING)
449454
{
450-
sendPause();
451455
pipeline_->stop();
456+
}
457+
if (client_state_ > ClientState::UNINITIALIZED)
458+
{
452459
stream_.disconnect();
453460
}
454461
client_state_ = ClientState::UNINITIALIZED;

tests/test_rtde_client.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ TEST_F(RTDEClientTest, check_all_rtde_output_variables_exist)
380380
client_.reset(new rtde_interface::RTDEClient(g_ROBOT_IP, notifier_, exhaustive_output_recipe_file_,
381381
input_recipe_file_, 0.0, true));
382382

383-
EXPECT_NO_THROW(client_->init());
383+
EXPECT_TRUE(client_->init());
384384
client_->start();
385385

386386
// Test that we can receive and parse the timestamp from the received package to prove the setup was successful

0 commit comments

Comments
 (0)