4141#ifndef UR_CONTROLLERS__TOOL_CONTACT_CONTROLLER_HPP_
4242#define UR_CONTROLLERS__TOOL_CONTACT_CONTROLLER_HPP_
4343
44+ #include < chrono>
45+
4446#include < controller_interface/chainable_controller_interface.hpp>
4547#include " std_msgs/msg/bool.hpp"
4648#include < rclcpp_action/server.hpp>
4749#include < rclcpp_action/create_server.hpp>
4850#include < rclcpp/rclcpp.hpp>
4951#include < rclcpp_action/server_goal_handle.hpp>
52+ #include < rclcpp/duration.hpp>
53+
54+ #include < realtime_tools/realtime_buffer.hpp>
55+ #include < realtime_tools/realtime_server_goal_handle.hpp>
5056
5157#include < ur_msgs/action/tool_contact.hpp>
5258#include " tool_contact_controller_parameters.hpp"
@@ -130,6 +136,14 @@ class ToolContactController : public controller_interface::ChainableControllerIn
130136 const rclcpp::Duration& period) override ;
131137
132138private:
139+ using RealtimeGoalHandle = realtime_tools::RealtimeServerGoalHandle<ur_msgs::action::ToolContact>;
140+ using RealtimeGoalHandlePtr = std::shared_ptr<RealtimeGoalHandle>;
141+ using RealtimeGoalHandleBuffer = realtime_tools::RealtimeBuffer<RealtimeGoalHandlePtr>;
142+
143+ RealtimeGoalHandleBuffer rt_active_goal_; // /< Currently active action goal, if any.
144+ rclcpp::TimerBase::SharedPtr goal_handle_timer_; // /< Timer to frequently check on the running goal
145+ rclcpp::Duration action_monitor_period_ = rclcpp::Duration(std::chrono::milliseconds(50 ));
146+
133147 rclcpp_action::GoalResponse goal_received_callback (const rclcpp_action::GoalUUID& /* uuid*/ ,
134148 std::shared_ptr<const ur_msgs::action::ToolContact::Goal> goal);
135149
@@ -139,27 +153,33 @@ class ToolContactController : public controller_interface::ChainableControllerIn
139153 rclcpp_action::CancelResponse goal_cancelled_callback (
140154 const std::shared_ptr<rclcpp_action::ServerGoalHandle<ur_msgs::action::ToolContact>> goal_handle);
141155
156+ void failed_update ();
157+
142158 double tool_contact_enable;
143159 double tool_contact_active;
144160
145161 std::atomic<bool > tool_contact_active_ = false ;
146162 std::atomic<bool > change_requested_ = false ;
163+ std::atomic<bool > logged_once_ = false ;
147164
148165 double old_reference_val = 0.0 ;
149166
150- std::optional<std::reference_wrapper<hardware_interface::LoanedCommandInterface >> async_success_interface_ ;
151- std::optional<std::reference_wrapper<hardware_interface::LoanedCommandInterface>> enable_command_interface_ ;
167+ std::optional<std::reference_wrapper<hardware_interface::LoanedStateInterface >> tool_contact_result_interface_ ;
168+ std::optional<std::reference_wrapper<hardware_interface::LoanedCommandInterface>> tool_contact_status_interface_ ;
152169 std::optional<std::reference_wrapper<hardware_interface::LoanedCommandInterface>> reference_interface_;
153170
154171 rclcpp_action::Server<ur_msgs::action::ToolContact>::SharedPtr tool_contact_action_server_;
155172
156173 std::shared_ptr<tool_contact_controller::ParamListener> tool_contact_param_listener_;
157174 tool_contact_controller::Params tool_contact_params_;
158175
159- void tool_contact_sub_callback (const std_msgs::msg::Bool::SharedPtr msg);
160-
161- static constexpr double ASYNC_WAITING = 2.0 ;
162- static constexpr double ASYNC_STANDBY_ = std::numeric_limits<double >::quiet_NaN();
176+ static constexpr double TOOL_CONTACT_STANDBY = 1.0 ;
177+ static constexpr double TOOL_CONTACT_WAITING_BEGIN = 2.0 ;
178+ static constexpr double TOOL_CONTACT_EXECUTING = 3.0 ;
179+ static constexpr double TOOL_CONTACT_FAILURE_BEGIN = 4.0 ;
180+ static constexpr double TOOL_CONTACT_WAITING_END = 5.0 ;
181+ static constexpr double TOOL_CONTACT_SUCCESS_END = 6.0 ;
182+ static constexpr double TOOL_CONTACT_FAILURE_END = 7.0 ;
163183};
164184} // namespace ur_controllers
165185
0 commit comments