@@ -35,9 +35,10 @@ namespace urcl
3535namespace rtde_interface
3636{
3737RTDEClient::RTDEClient (std::string robot_ip, comm::INotifier& notifier, const std::string& output_recipe_file,
38- const std::string& input_recipe_file, double target_frequency)
38+ const std::string& input_recipe_file, bool ignore_unavailable_outputs, double target_frequency)
3939 : stream_(robot_ip, UR_RTDE_PORT)
4040 , output_recipe_(ensureTimestampIsPresent(readRecipe(output_recipe_file)))
41+ , ignore_unavailable_outputs_(ignore_unavailable_outputs)
4142 , input_recipe_(readRecipe(input_recipe_file))
4243 , parser_(output_recipe_)
4344 , prod_(std::make_unique<comm::URProducer<RTDEPackage>>(stream_, parser_))
@@ -51,9 +52,11 @@ RTDEClient::RTDEClient(std::string robot_ip, comm::INotifier& notifier, const st
5152}
5253
5354RTDEClient::RTDEClient (std::string robot_ip, comm::INotifier& notifier, const std::vector<std::string>& output_recipe,
54- const std::vector<std::string>& input_recipe, double target_frequency)
55+ const std::vector<std::string>& input_recipe, bool ignore_unavailable_outputs,
56+ double target_frequency)
5557 : stream_(robot_ip, UR_RTDE_PORT)
5658 , output_recipe_(ensureTimestampIsPresent(output_recipe))
59+ , ignore_unavailable_outputs_(ignore_unavailable_outputs)
5760 , input_recipe_(input_recipe)
5861 , parser_(output_recipe_)
5962 , prod_(std::make_unique<comm::URProducer<RTDEPackage>>(stream_, parser_))
@@ -251,11 +254,12 @@ void RTDEClient::queryURControlVersion()
251254 throw UrException (ss.str ());
252255}
253256
254- void RTDEClient::resetOutputRecipe (const std::vector<std::string> new_recipe) {
257+ void RTDEClient::resetOutputRecipe (const std::vector<std::string> new_recipe)
258+ {
255259 prod_->teardownProducer ();
256260 disconnect ();
257261
258- output_recipe_.assign (new_recipe.begin (), new_recipe.end ());
262+ output_recipe_.assign (new_recipe.begin (), new_recipe.end ());
259263 parser_ = RTDEParser (output_recipe_);
260264 prod_ = std::make_unique<comm::URProducer<RTDEPackage>>(stream_, parser_);
261265 pipeline_ = std::make_unique<comm::Pipeline<RTDEPackage>>(*prod_, PIPELINE_NAME, notifier_, true );
@@ -308,33 +312,52 @@ void RTDEClient::setupOutputs(const uint16_t protocol_version)
308312 {
309313 std::vector<std::string> variable_types = splitVariableTypes (tmp_output->variable_types_ );
310314 std::vector<std::string> available_variables;
315+ std::vector<std::string> unavailable_variables;
311316 assert (output_recipe_.size () == variable_types.size ());
312317 for (std::size_t i = 0 ; i < variable_types.size (); ++i)
313318 {
314319 const std::string variable_name = output_recipe_[i];
315320 URCL_LOG_DEBUG (" %s confirmed as datatype: %s" , variable_name.c_str (), variable_types[i].c_str ());
316-
321+
317322 if (variable_types[i] == " NOT_FOUND" )
318323 {
319- const std::string message = " Variable '" + variable_name + " ' not recognized by the robot. "
320- " Either your output recipe contains errors or the urcontrol version "
321- " does not support it. It will be removed from the output recipe." ;
322- URCL_LOG_WARN (" %s" , message.c_str ());
323- }
324- else
324+ unavailable_variables.push_back (variable_name);
325+ }
326+ else
325327 {
326328 available_variables.push_back (variable_name);
327329 }
328330 }
329331
330- if (available_variables.size () == output_recipe_.size ()) {
332+ if (!unavailable_variables.empty ())
333+ {
334+ 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 "
339+ " or the urcontrol version does not support "
340+ " them." ;
341+
342+ if (ignore_unavailable_outputs_)
343+ {
344+ error_message << " They will be removed from the output recipe." ;
345+ URCL_LOG_WARN (" %s" , error_message.str ().c_str ());
346+
347+ // Some variables are not available so retry setting up the communication with a stripped-down output recipe
348+ resetOutputRecipe (available_variables);
349+ }
350+ else
351+ {
352+ URCL_LOG_ERROR (" %s" , error_message.str ().c_str ());
353+ throw UrException (error_message.str ());
354+ }
355+ }
356+ else
357+ {
331358 // All variables are accounted for in the RTDE package
332359 return ;
333360 }
334-
335- // Some variables are not available so retry setting up the communication with a stripped-down output recipe
336- resetOutputRecipe (available_variables);
337- return ;
338361 }
339362 else
340363 {
0 commit comments