@@ -97,6 +97,12 @@ controller_interface::InterfaceConfiguration GPIOController::command_interface_c
9797 config.names .emplace_back (tf_prefix + " hand_back_control/hand_back_control_cmd" );
9898 config.names .emplace_back (tf_prefix + " hand_back_control/hand_back_control_async_success" );
9999
100+ // Start or stop tool contact functionality
101+ config.names .emplace_back (tf_prefix + " start_tool_contact/start_tool_contact_cmd" );
102+ config.names .emplace_back (tf_prefix + " start_tool_contact/start_tool_contact_async_success" );
103+ config.names .emplace_back (tf_prefix + " end_tool_contact/end_tool_contact_cmd" );
104+ config.names .emplace_back (tf_prefix + " end_tool_contact/end_tool_contact_async_success" );
105+
100106 return config;
101107}
102108
@@ -312,6 +318,14 @@ ur_controllers::GPIOController::on_activate(const rclcpp_lifecycle::State& /*pre
312318 tare_sensor_srv_ = get_node ()->create_service <std_srvs::srv::Trigger>(
313319 " ~/zero_ftsensor" ,
314320 std::bind (&GPIOController::zeroFTSensor, this , std::placeholders::_1, std::placeholders::_2));
321+
322+ start_tool_contact_srv_ = get_node ()->create_service <std_srvs::srv::Trigger>(
323+ " ~/start_tool_contact" ,
324+ std::bind (&GPIOController::startToolContact, this , std::placeholders::_1, std::placeholders::_2));
325+
326+ end_tool_contact_srv_ = get_node ()->create_service <std_srvs::srv::Trigger>(
327+ " ~/end_tool_contact" ,
328+ std::bind (&GPIOController::endToolContact, this , std::placeholders::_1, std::placeholders::_2));
315329 } catch (...) {
316330 return LifecycleNodeInterface::CallbackReturn::ERROR;
317331 }
@@ -520,6 +534,59 @@ bool GPIOController::zeroFTSensor(std_srvs::srv::Trigger::Request::SharedPtr /*r
520534 return true ;
521535}
522536
537+ bool GPIOController::startToolContact (std_srvs::srv::Trigger::Request::SharedPtr /* req*/ ,
538+ std_srvs::srv::Trigger::Response::SharedPtr resp)
539+ {
540+ // reset success flag
541+ command_interfaces_[CommandInterfaces::START_TOOL_CONTACT_ASYNC_SUCCESS].set_value (ASYNC_WAITING);
542+
543+ // call the service in the hardware
544+ command_interfaces_[CommandInterfaces::START_TOOL_CONTACT_CMD].set_value (1.0 );
545+
546+ if (!waitForAsyncCommand (
547+ [&]() { return command_interfaces_[CommandInterfaces::START_TOOL_CONTACT_ASYNC_SUCCESS].get_value (); })) {
548+ RCLCPP_WARN (get_node ()->get_logger (), " Could not verify that tool contact was started." );
549+ }
550+
551+ resp->success =
552+ static_cast <bool >(command_interfaces_[CommandInterfaces::START_TOOL_CONTACT_ASYNC_SUCCESS].get_value ());
553+
554+ if (resp->success ) {
555+ RCLCPP_INFO (get_node ()->get_logger (), " Successfully started tool contact" );
556+ } else {
557+ RCLCPP_ERROR (get_node ()->get_logger (), " Could not start tool contact" );
558+ return false ;
559+ }
560+
561+ return true ;
562+ }
563+
564+ bool GPIOController::endToolContact (std_srvs::srv::Trigger::Request::SharedPtr /* req*/ ,
565+ std_srvs::srv::Trigger::Response::SharedPtr resp)
566+ {
567+ // reset success flag
568+ command_interfaces_[CommandInterfaces::END_TOOL_CONTACT_ASYNC_SUCCESS].set_value (ASYNC_WAITING);
569+
570+ // call the service in the hardware
571+ command_interfaces_[CommandInterfaces::END_TOOL_CONTACT_CMD].set_value (1.0 );
572+
573+ if (!waitForAsyncCommand (
574+ [&]() { return command_interfaces_[CommandInterfaces::END_TOOL_CONTACT_ASYNC_SUCCESS].get_value (); })) {
575+ RCLCPP_WARN (get_node ()->get_logger (), " Could not verify that tool contact was stopped." );
576+ }
577+
578+ resp->success = static_cast <bool >(command_interfaces_[CommandInterfaces::END_TOOL_CONTACT_ASYNC_SUCCESS].get_value ());
579+
580+ if (resp->success ) {
581+ RCLCPP_INFO (get_node ()->get_logger (), " Successfully stopped tool contact" );
582+ } else {
583+ RCLCPP_ERROR (get_node ()->get_logger (), " Could not stop tool contact" );
584+ return false ;
585+ }
586+
587+ return true ;
588+ }
589+
523590void GPIOController::initMsgs ()
524591{
525592 io_msg_.digital_in_states .resize (standard_digital_output_cmd_.size ());
0 commit comments