Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTDEClient: pause and stop in destructor only if running #257

Merged
merged 2 commits into from
Feb 6, 2025
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
21 changes: 14 additions & 7 deletions src/rtde/rtde_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ void RTDEClient::queryURControlVersion()

void RTDEClient::resetOutputRecipe(const std::vector<std::string> new_recipe)
{
prod_->teardownProducer();
disconnect();

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

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

// Some variables are not available so retry setting up the communication with a stripped-down output recipe
resetOutputRecipe(available_variables);
return;
}
else
{
Expand Down Expand Up @@ -445,10 +446,16 @@ void RTDEClient::setupInputs()
void RTDEClient::disconnect()
{
// If communication is started it should be paused before disconnecting
if (client_state_ > ClientState::UNINITIALIZED)
if (client_state_ == ClientState::RUNNING)
{
pause();
}
if (client_state_ >= ClientState::INITIALIZING)
{
sendPause();
pipeline_->stop();
}
if (client_state_ > ClientState::UNINITIALIZED)
{
stream_.disconnect();
}
client_state_ = ClientState::UNINITIALIZED;
Expand Down
2 changes: 1 addition & 1 deletion tests/test_rtde_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ TEST_F(RTDEClientTest, check_all_rtde_output_variables_exist)
client_.reset(new rtde_interface::RTDEClient(g_ROBOT_IP, notifier_, exhaustive_output_recipe_file_,
input_recipe_file_, 0.0, true));

EXPECT_NO_THROW(client_->init());
EXPECT_TRUE(client_->init());
client_->start();

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