Skip to content

Commit 0d1fb3b

Browse files
committed
Publish feedback and handle cancel correctly
1 parent d173581 commit 0d1fb3b

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

ur_controllers/include/ur_controllers/tool_contact_controller.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ class ToolContactController : public controller_interface::ControllerInterface
8888
using RealtimeGoalHandlePtr = std::shared_ptr<RealtimeGoalHandle>;
8989
using RealtimeGoalHandleBuffer = realtime_tools::RealtimeBuffer<RealtimeGoalHandlePtr>;
9090

91-
RealtimeGoalHandleBuffer rt_active_goal_; ///< Currently active action goal, if any.
92-
rclcpp::TimerBase::SharedPtr goal_handle_timer_; ///< Timer to frequently check on the running goal
91+
RealtimeGoalHandleBuffer rt_active_goal_; ///< Currently active action goal, if any.
92+
ur_msgs::action::ToolContact::Feedback::SharedPtr feedback_; ///< preallocated feedback
93+
rclcpp::TimerBase::SharedPtr goal_handle_timer_; ///< Timer to frequently check on the running goal
9394

9495
// non-rt function that will be called with action_monitor_period to monitor the rt action
9596
rclcpp::Duration action_monitor_period_ = rclcpp::Duration::from_seconds(0.05);

ur_controllers/src/tool_contact_controller.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ controller_interface::CallbackReturn ToolContactController::on_init()
5353
{
5454
tool_contact_param_listener_ = std::make_shared<tool_contact_controller::ParamListener>(get_node());
5555
tool_contact_params_ = tool_contact_param_listener_->get_params();
56+
feedback_ = std::make_shared<ur_msgs::action::ToolContact::Feedback>();
5657
return controller_interface::CallbackReturn::SUCCESS;
5758
}
5859

@@ -258,7 +259,7 @@ rclcpp_action::CancelResponse ToolContactController::goal_canceled_callback(
258259
// Mark the current goal as canceled
259260
auto result = std::make_shared<ur_msgs::action::ToolContact::Result>();
260261
active_goal->setCanceled(result);
261-
rt_active_goal_.writeFromNonRT(RealtimeGoalHandlePtr());
262+
should_reset_goal = true;
262263
tool_contact_abort_ = true;
263264
tool_contact_enable_ = false;
264265
}
@@ -341,10 +342,12 @@ controller_interface::return_type ToolContactController::update(const rclcpp::Ti
341342

342343
case static_cast<int>(TOOL_CONTACT_SUCCESS_END):
343344
{
344-
RCLCPP_INFO(get_node()->get_logger(), "Tool contact disabled successfully.");
345-
tool_contact_active_ = false;
345+
if (tool_contact_active_) {
346+
RCLCPP_INFO(get_node()->get_logger(), "Tool contact disabled successfully.");
347+
tool_contact_active_ = false;
346348

347-
write_success &= tool_contact_set_state_interface_->get().set_value(TOOL_CONTACT_STANDBY);
349+
write_success &= tool_contact_set_state_interface_->get().set_value(TOOL_CONTACT_STANDBY);
350+
}
348351
} break;
349352

350353
case static_cast<int>(TOOL_CONTACT_FAILURE_END):
@@ -365,6 +368,9 @@ controller_interface::return_type ToolContactController::update(const rclcpp::Ti
365368
default:
366369
break;
367370
}
371+
if (active_goal) {
372+
active_goal->setFeedback(feedback_);
373+
}
368374

369375
if (!write_success) {
370376
RCLCPP_FATAL(get_node()->get_logger(), "Controller failed to update or read command/state interface.");

0 commit comments

Comments
 (0)