Skip to content

Commit 29cf716

Browse files
Felix Exnerfmauch
authored andcommitted
RTDE handshake verification
Throw an exception if the RTDE handshake could not be established correctly.
1 parent 0baaa19 commit 29cf716

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

ur_robot_driver/include/ur_robot_driver/rtde/rtde_client.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,15 @@ class RTDEClient
147147
void queryURControlVersion();
148148
void setupOutputs(const uint16_t protocol_version);
149149
void setupInputs();
150+
/*!
151+
* \brief Splits a variable_types string as reported from the robot into single variable type
152+
* strings
153+
*
154+
* \param variable_types String as reported from the robot
155+
*
156+
* \returns A vector of variable variable_names
157+
*/
158+
std::vector<std::string> splitVariableTypes(const std::string& variable_types) const;
150159
};
151160

152161
} // namespace rtde_interface

ur_robot_driver/src/rtde/rtde_client.cpp

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,25 @@ void RTDEClient::setupOutputs(const uint16_t protocol_version)
142142
if (!stream_.write(buffer, size, written))
143143
throw UrException("Could not send RTDE output recipe to robot.");
144144
if (!pipeline_.getLatestProduct(package, std::chrono::milliseconds(1000)))
145+
{
145146
throw UrException("Did not receive confirmation on RTDE output recipe.");
147+
}
148+
149+
rtde_interface::ControlPackageSetupOutputs* tmp_output =
150+
dynamic_cast<rtde_interface::ControlPackageSetupOutputs*>(package.get());
151+
152+
std::vector<std::string> variable_types = splitVariableTypes(tmp_output->variable_types_);
153+
assert(output_recipe_.size() == variable_types.size());
154+
for (std::size_t i = 0; i < variable_types.size(); ++i)
155+
{
156+
LOG_DEBUG("%s confirmed as datatype: %s", output_recipe_[i].c_str(), variable_types[i].c_str());
157+
if (variable_types[i] == "NOT_FOUND")
158+
{
159+
std::string message = "Variable '" + output_recipe_[i] +
160+
"' not recognized by the robot. Probably your output recipe contains errors";
161+
throw UrException(message);
162+
}
163+
}
146164
}
147165

148166
void RTDEClient::setupInputs()
@@ -163,6 +181,26 @@ void RTDEClient::setupInputs()
163181
throw UrException("Could not setup RTDE inputs.");
164182
}
165183

184+
std::vector<std::string> variable_types = splitVariableTypes(tmp_input->variable_types_);
185+
assert(input_recipe_.size() == variable_types.size());
186+
for (std::size_t i = 0; i < variable_types.size(); ++i)
187+
{
188+
LOG_DEBUG("%s confirmed as datatype: %s", input_recipe_[i].c_str(), variable_types[i].c_str());
189+
if (variable_types[i] == "NOT_FOUND")
190+
{
191+
std::string message =
192+
"Variable '" + input_recipe_[i] + "' not recognized by the robot. Probably your input recipe contains errors";
193+
throw UrException(message);
194+
}
195+
else if (variable_types[i] == "IN_USE")
196+
{
197+
std::string message = "Variable '" + input_recipe_[i] +
198+
"' is currently controlled by another RTDE client. The input recipe can't be used as "
199+
"configured";
200+
throw UrException(message);
201+
}
202+
}
203+
166204
writer_.init(tmp_input->input_recipe_id_);
167205
}
168206

@@ -177,7 +215,8 @@ bool RTDEClient::start()
177215
if (!stream_.write(buffer, size, written))
178216
throw UrException("Sending RTDE start command failed!");
179217
if (!pipeline_.getLatestProduct(package, std::chrono::milliseconds(1000)))
180-
throw UrException("Could not get response to RTDE communication start request from robot. This should not happen!");
218+
throw UrException("Could not get response to RTDE communication start request from robot. This should not "
219+
"happen!");
181220
rtde_interface::ControlPackageStart* tmp = dynamic_cast<rtde_interface::ControlPackageStart*>(package.get());
182221
return tmp->accepted_;
183222
}
@@ -217,5 +256,17 @@ RTDEWriter& RTDEClient::getWriter()
217256
{
218257
return writer_;
219258
}
259+
260+
std::vector<std::string> RTDEClient::splitVariableTypes(const std::string& variable_types) const
261+
{
262+
std::vector<std::string> result;
263+
std::stringstream ss(variable_types);
264+
std::string substr = "";
265+
while (getline(ss, substr, ','))
266+
{
267+
result.push_back(substr);
268+
}
269+
return result;
270+
}
220271
} // namespace rtde_interface
221272
} // namespace ur_driver

0 commit comments

Comments
 (0)