@@ -347,9 +347,9 @@ bool GPIOController::setIO(ur_msgs::srv::SetIO::Request::SharedPtr req, ur_msgs:
347347
348348 RCLCPP_INFO (get_node ()->get_logger (), " Setting digital output '%d' to state: '%1.0f'." , req->pin , req->state );
349349
350- while ( command_interfaces_[CommandInterfaces::IO_ASYNC_SUCCESS].get_value () == ASYNC_WAITING ) {
351- // Asynchronous wait until the hardware interface has set the io value
352- std::this_thread::sleep_for ( std::chrono::milliseconds ( 50 ) );
350+ if (! waitForAsyncCommand ([&]() { return command_interfaces_[CommandInterfaces::IO_ASYNC_SUCCESS].get_value (); }) ) {
351+ RCLCPP_WARN ( get_node ()-> get_logger (), " Could not verify that io was set. (This might happen when using the "
352+ " mocked interface) " );
353353 }
354354
355355 resp->success = static_cast <bool >(command_interfaces_[IO_ASYNC_SUCCESS].get_value ());
@@ -361,9 +361,9 @@ bool GPIOController::setIO(ur_msgs::srv::SetIO::Request::SharedPtr req, ur_msgs:
361361
362362 RCLCPP_INFO (get_node ()->get_logger (), " Setting analog output '%d' to state: '%1.0f'." , req->pin , req->state );
363363
364- while ( command_interfaces_[CommandInterfaces::IO_ASYNC_SUCCESS].get_value () == ASYNC_WAITING ) {
365- // Asynchronous wait until the hardware interface has set the io value
366- std::this_thread::sleep_for ( std::chrono::milliseconds ( 50 ) );
364+ if (! waitForAsyncCommand ([&]() { return command_interfaces_[CommandInterfaces::IO_ASYNC_SUCCESS].get_value (); }) ) {
365+ RCLCPP_WARN ( get_node ()-> get_logger (), " Could not verify that io was set. (This might happen when using the "
366+ " mocked interface) " );
367367 }
368368
369369 resp->success = static_cast <bool >(command_interfaces_[CommandInterfaces::IO_ASYNC_SUCCESS].get_value ());
@@ -374,9 +374,9 @@ bool GPIOController::setIO(ur_msgs::srv::SetIO::Request::SharedPtr req, ur_msgs:
374374
375375 RCLCPP_INFO (get_node ()->get_logger (), " Setting tool voltage to: '%1.0f'." , req->state );
376376
377- while ( command_interfaces_[CommandInterfaces::IO_ASYNC_SUCCESS].get_value () == ASYNC_WAITING ) {
378- // Asynchronous wait until the hardware interface has set the io value
379- std::this_thread::sleep_for ( std::chrono::milliseconds ( 50 ) );
377+ if (! waitForAsyncCommand ([&]() { return command_interfaces_[CommandInterfaces::IO_ASYNC_SUCCESS].get_value (); }) ) {
378+ RCLCPP_WARN ( get_node ()-> get_logger (), " Could not verify that io was set. (This might happen when using the "
379+ " mocked interface) " );
380380 }
381381
382382 resp->success = static_cast <bool >(command_interfaces_[CommandInterfaces::IO_ASYNC_SUCCESS].get_value ());
@@ -398,9 +398,11 @@ bool GPIOController::setSpeedSlider(ur_msgs::srv::SetSpeedSliderFraction::Reques
398398 command_interfaces_[CommandInterfaces::TARGET_SPEED_FRACTION_CMD].set_value (
399399 static_cast <double >(req->speed_slider_fraction ));
400400
401- while (command_interfaces_[CommandInterfaces::TARGET_SPEED_FRACTION_ASYNC_SUCCESS].get_value () == ASYNC_WAITING) {
402- // Asynchronouse wait until the hardware interface has set the slider value
403- std::this_thread::sleep_for (std::chrono::milliseconds (50 ));
401+ if (!waitForAsyncCommand ([&]() {
402+ return command_interfaces_[CommandInterfaces::TARGET_SPEED_FRACTION_ASYNC_SUCCESS].get_value ();
403+ })) {
404+ RCLCPP_WARN (get_node ()->get_logger (), " Could not verify that target speed fraction was set. (This might happen "
405+ " when using the mocked interface)" );
404406 }
405407 resp->success =
406408 static_cast <bool >(command_interfaces_[CommandInterfaces::TARGET_SPEED_FRACTION_ASYNC_SUCCESS].get_value ());
@@ -421,9 +423,10 @@ bool GPIOController::resendRobotProgram(std_srvs::srv::Trigger::Request::SharedP
421423 // call the service in the hardware
422424 command_interfaces_[CommandInterfaces::RESEND_ROBOT_PROGRAM_CMD].set_value (1.0 );
423425
424- while (command_interfaces_[CommandInterfaces::RESEND_ROBOT_PROGRAM_ASYNC_SUCCESS].get_value () == ASYNC_WAITING) {
425- // Asynchronous wait until the hardware interface has set the slider value
426- std::this_thread::sleep_for (std::chrono::milliseconds (50 ));
426+ if (!waitForAsyncCommand (
427+ [&]() { return command_interfaces_[CommandInterfaces::RESEND_ROBOT_PROGRAM_ASYNC_SUCCESS].get_value (); })) {
428+ RCLCPP_WARN (get_node ()->get_logger (), " Could not verify that program was sent. (This might happen when using the "
429+ " mocked interface)" );
427430 }
428431 resp->success =
429432 static_cast <bool >(command_interfaces_[CommandInterfaces::RESEND_ROBOT_PROGRAM_ASYNC_SUCCESS].get_value ());
@@ -446,9 +449,10 @@ bool GPIOController::handBackControl(std_srvs::srv::Trigger::Request::SharedPtr
446449 // call the service in the hardware
447450 command_interfaces_[CommandInterfaces::HAND_BACK_CONTROL_CMD].set_value (1.0 );
448451
449- while (command_interfaces_[CommandInterfaces::HAND_BACK_CONTROL_ASYNC_SUCCESS].get_value () == ASYNC_WAITING) {
450- // Asynchronous wait until the command has been executed
451- std::this_thread::sleep_for (std::chrono::milliseconds (50 ));
452+ if (!waitForAsyncCommand (
453+ [&]() { return command_interfaces_[CommandInterfaces::HAND_BACK_CONTROL_ASYNC_SUCCESS].get_value (); })) {
454+ RCLCPP_WARN (get_node ()->get_logger (), " Could not verify that hand_back_control was correctly triggered. (This "
455+ " might happen when using the mocked interface)" );
452456 }
453457 resp->success =
454458 static_cast <bool >(command_interfaces_[CommandInterfaces::HAND_BACK_CONTROL_ASYNC_SUCCESS].get_value ());
@@ -474,9 +478,10 @@ bool GPIOController::setPayload(const ur_msgs::srv::SetPayload::Request::SharedP
474478 command_interfaces_[CommandInterfaces::PAYLOAD_COG_Y].set_value (req->center_of_gravity .y );
475479 command_interfaces_[CommandInterfaces::PAYLOAD_COG_Z].set_value (req->center_of_gravity .z );
476480
477- while (command_interfaces_[CommandInterfaces::PAYLOAD_ASYNC_SUCCESS].get_value () == ASYNC_WAITING) {
478- // Asynchronous wait until the hardware interface has set the payload
479- std::this_thread::sleep_for (std::chrono::milliseconds (50 ));
481+ if (!waitForAsyncCommand (
482+ [&]() { return command_interfaces_[CommandInterfaces::PAYLOAD_ASYNC_SUCCESS].get_value (); })) {
483+ RCLCPP_WARN (get_node ()->get_logger (), " Could not verify that payload was set. (This might happen when using the "
484+ " mocked interface)" );
480485 }
481486
482487 resp->success = static_cast <bool >(command_interfaces_[CommandInterfaces::PAYLOAD_ASYNC_SUCCESS].get_value ());
@@ -499,9 +504,10 @@ bool GPIOController::zeroFTSensor(std_srvs::srv::Trigger::Request::SharedPtr /*r
499504 // call the service in the hardware
500505 command_interfaces_[CommandInterfaces::ZERO_FTSENSOR_CMD].set_value (1.0 );
501506
502- while (command_interfaces_[CommandInterfaces::ZERO_FTSENSOR_ASYNC_SUCCESS].get_value () == ASYNC_WAITING) {
503- // Asynchronous wait until the hardware interface has set the slider value
504- std::this_thread::sleep_for (std::chrono::milliseconds (50 ));
507+ if (!waitForAsyncCommand (
508+ [&]() { return command_interfaces_[CommandInterfaces::ZERO_FTSENSOR_ASYNC_SUCCESS].get_value (); })) {
509+ RCLCPP_WARN (get_node ()->get_logger (), " Could not verify that FTS was zeroed. (This might happen when using the "
510+ " mocked interface)" );
505511 }
506512
507513 resp->success = static_cast <bool >(command_interfaces_[CommandInterfaces::ZERO_FTSENSOR_ASYNC_SUCCESS].get_value ());
@@ -524,6 +530,20 @@ void GPIOController::initMsgs()
524530 io_msg_.analog_out_states .resize (2 );
525531}
526532
533+ bool GPIOController::waitForAsyncCommand (std::function<double (void )> get_value)
534+ {
535+ const auto maximum_retries = params_.check_io_successfull_retries ;
536+ int retries = 0 ;
537+ while (get_value () == ASYNC_WAITING) {
538+ std::this_thread::sleep_for (std::chrono::milliseconds (50 ));
539+ retries++;
540+
541+ if (retries > maximum_retries)
542+ return false ;
543+ }
544+ return true ;
545+ }
546+
527547} // namespace ur_controllers
528548
529549#include " pluginlib/class_list_macros.hpp"
0 commit comments