Skip to content

Commit b17a72c

Browse files
committed
Tool contact controller works when used with an action. Chaining is still untested.
I have not done anything with starting and stopping the controller yet.
1 parent b19f71e commit b17a72c

File tree

7 files changed

+315
-163
lines changed

7 files changed

+315
-163
lines changed

ur_controllers/include/ur_controllers/gpio_controller.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ enum CommandInterfaces
8181
HAND_BACK_CONTROL_CMD = 33,
8282
HAND_BACK_CONTROL_ASYNC_SUCCESS = 34,
8383
ANALOG_OUTPUTS_DOMAIN = 35,
84-
START_TOOL_CONTACT_CMD = 36,
85-
START_TOOL_CONTACT_ASYNC_SUCCESS = 37,
86-
END_TOOL_CONTACT_CMD = 38,
87-
END_TOOL_CONTACT_ASYNC_SUCCESS = 39,
8884
};
8985

9086
enum StateInterfaces

ur_controllers/include/ur_controllers/tool_contact_controller.hpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,18 @@
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

132138
private:
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

ur_controllers/src/gpio_controller.cpp

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -565,60 +565,6 @@ bool GPIOController::zeroFTSensor(std_srvs::srv::Trigger::Request::SharedPtr /*r
565565
return true;
566566
}
567567

568-
// bool GPIOController::startToolContact(std_srvs::srv::Trigger::Request::SharedPtr /*req*/,
569-
// std_srvs::srv::Trigger::Response::SharedPtr resp)
570-
// {
571-
// // reset success flag
572-
// command_interfaces_[CommandInterfaces::START_TOOL_CONTACT_ASYNC_SUCCESS].set_value(ASYNC_WAITING);
573-
574-
// // call the service in the hardware
575-
// command_interfaces_[CommandInterfaces::START_TOOL_CONTACT_CMD].set_value(1.0);
576-
577-
// if (!waitForAsyncCommand(
578-
// [&]() { return command_interfaces_[CommandInterfaces::START_TOOL_CONTACT_ASYNC_SUCCESS].get_value(); })) {
579-
// RCLCPP_WARN(get_node()->get_logger(), "Could not verify that tool contact was started.");
580-
// }
581-
582-
// resp->success =
583-
// static_cast<bool>(command_interfaces_[CommandInterfaces::START_TOOL_CONTACT_ASYNC_SUCCESS].get_value());
584-
585-
// if (resp->success) {
586-
// RCLCPP_INFO(get_node()->get_logger(), "Successfully started tool contact");
587-
// } else {
588-
// RCLCPP_ERROR(get_node()->get_logger(), "Could not start tool contact");
589-
// return false;
590-
// }
591-
592-
// return true;
593-
// }
594-
595-
// bool GPIOController::endToolContact(std_srvs::srv::Trigger::Request::SharedPtr /*req*/,
596-
// std_srvs::srv::Trigger::Response::SharedPtr resp)
597-
// {
598-
// // reset success flag
599-
// command_interfaces_[CommandInterfaces::END_TOOL_CONTACT_ASYNC_SUCCESS].set_value(ASYNC_WAITING);
600-
601-
// // call the service in the hardware
602-
// command_interfaces_[CommandInterfaces::END_TOOL_CONTACT_CMD].set_value(1.0);
603-
604-
// if (!waitForAsyncCommand(
605-
// [&]() { return command_interfaces_[CommandInterfaces::END_TOOL_CONTACT_ASYNC_SUCCESS].get_value(); })) {
606-
// RCLCPP_WARN(get_node()->get_logger(), "Could not verify that tool contact was stopped.");
607-
// }
608-
609-
// resp->success =
610-
// static_cast<bool>(command_interfaces_[CommandInterfaces::END_TOOL_CONTACT_ASYNC_SUCCESS].get_value());
611-
612-
// if (resp->success) {
613-
// RCLCPP_INFO(get_node()->get_logger(), "Successfully stopped tool contact");
614-
// } else {
615-
// RCLCPP_ERROR(get_node()->get_logger(), "Could not stop tool contact");
616-
// return false;
617-
// }
618-
619-
// return true;
620-
// }
621-
622568
void GPIOController::initMsgs()
623569
{
624570
io_msg_.digital_in_states.resize(standard_digital_output_cmd_.size());

0 commit comments

Comments
 (0)