Skip to content

Commit db6c6e6

Browse files
Introduce hand back control service (#528) (#670)
Add hand back control service to enable return of urcap and mixed ROS/Teach Pendant programming Co-authored-by: Felix Exner (fexner) <[email protected]> (cherry picked from commit e27cb90) Co-authored-by: livanov93 <[email protected]>
1 parent ea32b6e commit db6c6e6

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

ur_controllers/include/ur_controllers/gpio_controller.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ enum CommandInterfaces
7676
PAYLOAD_ASYNC_SUCCESS = 30,
7777
ZERO_FTSENSOR_CMD = 31,
7878
ZERO_FTSENSOR_ASYNC_SUCCESS = 32,
79+
HAND_BACK_CONTROL_CMD = 33,
80+
HAND_BACK_CONTROL_ASYNC_SUCCESS = 34,
7981
};
8082

8183
enum StateInterfaces
@@ -125,6 +127,9 @@ class GPIOController : public controller_interface::ControllerInterface
125127
bool resendRobotProgram(std_srvs::srv::Trigger::Request::SharedPtr req,
126128
std_srvs::srv::Trigger::Response::SharedPtr resp);
127129

130+
bool handBackControl(std_srvs::srv::Trigger::Request::SharedPtr req,
131+
std_srvs::srv::Trigger::Response::SharedPtr resp);
132+
128133
bool setPayload(const ur_msgs::srv::SetPayload::Request::SharedPtr req,
129134
ur_msgs::srv::SetPayload::Response::SharedPtr resp);
130135

@@ -152,6 +157,7 @@ class GPIOController : public controller_interface::ControllerInterface
152157

153158
// services
154159
rclcpp::Service<std_srvs::srv::Trigger>::SharedPtr resend_robot_program_srv_;
160+
rclcpp::Service<std_srvs::srv::Trigger>::SharedPtr hand_back_control_srv_;
155161
rclcpp::Service<ur_msgs::srv::SetSpeedSliderFraction>::SharedPtr set_speed_slider_srv_;
156162
rclcpp::Service<ur_msgs::srv::SetIO>::SharedPtr set_io_srv_;
157163
rclcpp::Service<ur_msgs::srv::SetPayload>::SharedPtr set_payload_srv_;

ur_controllers/src/gpio_controller.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ controller_interface::InterfaceConfiguration GPIOController::command_interface_c
8484
config.names.emplace_back("zero_ftsensor/zero_ftsensor_cmd");
8585
config.names.emplace_back("zero_ftsensor/zero_ftsensor_async_success");
8686

87+
// hand back control --> make UR-program return
88+
config.names.emplace_back("hand_back_control/hand_back_control_cmd");
89+
config.names.emplace_back("hand_back_control/hand_back_control_async_success");
90+
8791
return config;
8892
}
8993

@@ -278,6 +282,10 @@ ur_controllers::GPIOController::on_activate(const rclcpp_lifecycle::State& /*pre
278282
"~/resend_robot_program",
279283
std::bind(&GPIOController::resendRobotProgram, this, std::placeholders::_1, std::placeholders::_2));
280284

285+
hand_back_control_srv_ = get_node()->create_service<std_srvs::srv::Trigger>(
286+
"~/hand_back_control",
287+
std::bind(&GPIOController::handBackControl, this, std::placeholders::_1, std::placeholders::_2));
288+
281289
set_payload_srv_ = get_node()->create_service<ur_msgs::srv::SetPayload>(
282290
"~/set_payload", std::bind(&GPIOController::setPayload, this, std::placeholders::_1, std::placeholders::_2));
283291

@@ -408,6 +416,31 @@ bool GPIOController::resendRobotProgram(std_srvs::srv::Trigger::Request::SharedP
408416
return true;
409417
}
410418

419+
bool GPIOController::handBackControl(std_srvs::srv::Trigger::Request::SharedPtr /*req*/,
420+
std_srvs::srv::Trigger::Response::SharedPtr resp)
421+
{
422+
// reset success flag
423+
command_interfaces_[CommandInterfaces::HAND_BACK_CONTROL_ASYNC_SUCCESS].set_value(ASYNC_WAITING);
424+
// call the service in the hardware
425+
command_interfaces_[CommandInterfaces::HAND_BACK_CONTROL_CMD].set_value(1.0);
426+
427+
while (command_interfaces_[CommandInterfaces::HAND_BACK_CONTROL_ASYNC_SUCCESS].get_value() == ASYNC_WAITING) {
428+
// Asynchronous wait until the command has been executed
429+
std::this_thread::sleep_for(std::chrono::milliseconds(50));
430+
}
431+
resp->success =
432+
static_cast<bool>(command_interfaces_[CommandInterfaces::HAND_BACK_CONTROL_ASYNC_SUCCESS].get_value());
433+
434+
if (resp->success) {
435+
RCLCPP_INFO(get_node()->get_logger(), "Deactivated control");
436+
} else {
437+
RCLCPP_ERROR(get_node()->get_logger(), "Could not deactivate control");
438+
return false;
439+
}
440+
441+
return true;
442+
}
443+
411444
bool GPIOController::setPayload(const ur_msgs::srv::SetPayload::Request::SharedPtr req,
412445
ur_msgs::srv::SetPayload::Response::SharedPtr resp)
413446
{

ur_robot_driver/include/ur_robot_driver/hardware_interface.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ class URPositionHardwareInterface : public hardware_interface::SystemInterface
182182
double resend_robot_program_async_success_;
183183
double zero_ftsensor_cmd_;
184184
double zero_ftsensor_async_success_;
185+
double hand_back_control_cmd_;
186+
double hand_back_control_async_success_;
185187
bool first_pass_;
186188
bool initialized_;
187189
double system_interface_initialized_;

ur_robot_driver/src/hardware_interface.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,12 @@ std::vector<hardware_interface::CommandInterface> URPositionHardwareInterface::e
244244
command_interfaces.emplace_back(hardware_interface::CommandInterface(
245245
"resend_robot_program", "resend_robot_program_async_success", &resend_robot_program_async_success_));
246246

247+
command_interfaces.emplace_back(
248+
hardware_interface::CommandInterface("hand_back_control", "hand_back_control_cmd", &hand_back_control_cmd_));
249+
250+
command_interfaces.emplace_back(hardware_interface::CommandInterface(
251+
"hand_back_control", "hand_back_control_async_success", &hand_back_control_async_success_));
252+
247253
command_interfaces.emplace_back(hardware_interface::CommandInterface("payload", "mass", &payload_mass_));
248254
command_interfaces.emplace_back(
249255
hardware_interface::CommandInterface("payload", "cog.x", &payload_center_of_gravity_[0]));
@@ -562,6 +568,7 @@ hardware_interface::return_type URPositionHardwareInterface::read(const rclcpp::
562568
target_speed_fraction_cmd_ = NO_NEW_CMD_;
563569
resend_robot_program_cmd_ = NO_NEW_CMD_;
564570
zero_ftsensor_cmd_ = NO_NEW_CMD_;
571+
hand_back_control_cmd_ = NO_NEW_CMD_;
565572
initialized_ = true;
566573
}
567574

@@ -665,6 +672,12 @@ void URPositionHardwareInterface::checkAsyncIO()
665672
resend_robot_program_cmd_ = NO_NEW_CMD_;
666673
}
667674

675+
if (!std::isnan(hand_back_control_cmd_) && ur_driver_ != nullptr) {
676+
robot_program_running_ = false;
677+
hand_back_control_async_success_ = true;
678+
hand_back_control_cmd_ = NO_NEW_CMD_;
679+
}
680+
668681
if (!std::isnan(payload_mass_) && !std::isnan(payload_center_of_gravity_[0]) &&
669682
!std::isnan(payload_center_of_gravity_[1]) && !std::isnan(payload_center_of_gravity_[2]) &&
670683
ur_driver_ != nullptr) {

0 commit comments

Comments
 (0)