Skip to content

Commit b19f71e

Browse files
committed
Intermediate commit
1 parent b7eaf35 commit b19f71e

File tree

2 files changed

+47
-13
lines changed

2 files changed

+47
-13
lines changed

ur_controllers/include/ur_controllers/tool_contact_controller.hpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@
4343

4444
#include <controller_interface/chainable_controller_interface.hpp>
4545
#include "std_msgs/msg/bool.hpp"
46+
#include <rclcpp_action/server.hpp>
47+
#include <rclcpp_action/create_server.hpp>
48+
#include <rclcpp/rclcpp.hpp>
49+
#include <rclcpp_action/server_goal_handle.hpp>
4650

51+
#include <ur_msgs/action/tool_contact.hpp>
4752
#include "tool_contact_controller_parameters.hpp"
4853

4954
namespace ur_controllers
@@ -125,6 +130,15 @@ class ToolContactController : public controller_interface::ChainableControllerIn
125130
const rclcpp::Duration& period) override;
126131

127132
private:
133+
rclcpp_action::GoalResponse goal_received_callback(const rclcpp_action::GoalUUID& /*uuid*/,
134+
std::shared_ptr<const ur_msgs::action::ToolContact::Goal> goal);
135+
136+
void
137+
goal_accepted_callback(std::shared_ptr<rclcpp_action::ServerGoalHandle<ur_msgs::action::ToolContact>> goal_handle);
138+
139+
rclcpp_action::CancelResponse goal_cancelled_callback(
140+
const std::shared_ptr<rclcpp_action::ServerGoalHandle<ur_msgs::action::ToolContact>> goal_handle);
141+
128142
double tool_contact_enable;
129143
double tool_contact_active;
130144

@@ -137,7 +151,7 @@ class ToolContactController : public controller_interface::ChainableControllerIn
137151
std::optional<std::reference_wrapper<hardware_interface::LoanedCommandInterface>> enable_command_interface_;
138152
std::optional<std::reference_wrapper<hardware_interface::LoanedCommandInterface>> reference_interface_;
139153

140-
rclcpp::Subscription<std_msgs::msg::Bool>::SharedPtr tool_contact_enable_sub_;
154+
rclcpp_action::Server<ur_msgs::action::ToolContact>::SharedPtr tool_contact_action_server_;
141155

142156
std::shared_ptr<tool_contact_controller::ParamListener> tool_contact_param_listener_;
143157
tool_contact_controller::Params tool_contact_params_;

ur_controllers/src/tool_contact_controller.cpp

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,22 @@ controller_interface::InterfaceConfiguration ToolContactController::state_interf
8585

8686
controller_interface::CallbackReturn ToolContactController::on_activate(const rclcpp_lifecycle::State& previous_state)
8787
{
88-
tool_contact_enable_sub_ = get_node()->create_subscription<std_msgs::msg::Bool>(
89-
"~/enable_tool_contact", 10,
90-
std::bind(&ToolContactController::tool_contact_sub_callback, this, std::placeholders::_1));
88+
tool_contact_action_server_ = rclcpp_action::create_server<ur_msgs::action::ToolContact>(
89+
get_node(), std::string(get_node()->get_name()) + "/enable_tool_contact",
90+
std::bind(&ToolContactController::goal_received_callback, this, std::placeholders::_1, std::placeholders::_2),
91+
std::bind(&ToolContactController::goal_cancelled_callback, this, std::placeholders::_1),
92+
std::bind(&ToolContactController::goal_accepted_callback, this, std::placeholders::_1));
9193

9294
/*Figure out how to get reference interface by name*/
93-
// const std::string interface_name = tool_contact_params_.tf_prefix + get_node()->get_name() + "tool_contact/enable";
94-
// auto it = std::find_if(reference_interfaces_.begin(), reference_interfaces_.end(),
95+
// const std::string interface_name = tool_contact_params_.tf_prefix + get_node()->get_name() +
96+
// "tool_contact/enable"; auto it = std::find_if(reference_interfaces_.begin(), reference_interfaces_.end(),
9597
// [&](auto& interface) { return (interface.get_name() == interface_name); });
9698
// if (it != reference_interfaces_.end()) {
9799
// reference_interface_ = *it;
98100
// reference_interface_->get().set_value(0.0);
99101
// } else {
100-
// RCLCPP_ERROR(get_node()->get_logger(), "Did not find '%s' in command interfaces.", interface_name.c_str());
101-
// return controller_interface::CallbackReturn::ERROR;
102+
// RCLCPP_ERROR(get_node()->get_logger(), "Did not find '%s' in command interfaces.",
103+
// interface_name.c_str()); return controller_interface::CallbackReturn::ERROR;
102104
// }
103105
reference_interfaces_[0] = 0.0;
104106
{
@@ -131,7 +133,7 @@ controller_interface::CallbackReturn ToolContactController::on_activate(const rc
131133

132134
controller_interface::CallbackReturn ToolContactController::on_deactivate(const rclcpp_lifecycle::State& previous_state)
133135
{
134-
tool_contact_enable_sub_.reset();
136+
tool_contact_action_server_.reset();
135137

136138
return controller_interface::CallbackReturn::SUCCESS;
137139
}
@@ -174,17 +176,35 @@ std::vector<hardware_interface::StateInterface> ToolContactController::on_export
174176
bool ToolContactController::on_set_chained_mode(bool chained_mode)
175177
{
176178
if (chained_mode) {
177-
tool_contact_enable_sub_.reset();
179+
tool_contact_action_server_.reset();
178180
} else {
179-
tool_contact_enable_sub_ = get_node()->create_subscription<std_msgs::msg::Bool>(
180-
"~/enable_tool_contact", 10,
181-
std::bind(&ToolContactController::tool_contact_sub_callback, this, std::placeholders::_1));
181+
// tool_contact_action_server_ = get_node()->create_subscription<std_msgs::msg::Bool>(
182+
// "~/enable_tool_contact", 10,
183+
// std::bind(&ToolContactController::tool_contact_sub_callback, this, std::placeholders::_1));
182184
}
183185
change_requested_ = false;
184186
tool_contact_active_ = false;
185187
return true;
186188
}
187189

190+
rclcpp_action::GoalResponse ToolContactController::goal_received_callback(
191+
const rclcpp_action::GoalUUID& /*uuid*/, std::shared_ptr<const ur_msgs::action::ToolContact::Goal> goal)
192+
{
193+
return rclcpp_action::GoalResponse::ACCEPT_AND_EXECUTE;
194+
}
195+
196+
void ToolContactController::goal_accepted_callback(
197+
std::shared_ptr<rclcpp_action::ServerGoalHandle<ur_msgs::action::ToolContact>> goal_handle)
198+
{
199+
return;
200+
}
201+
202+
rclcpp_action::CancelResponse ToolContactController::goal_cancelled_callback(
203+
const std::shared_ptr<rclcpp_action::ServerGoalHandle<ur_msgs::action::ToolContact>> goal_handle)
204+
{
205+
return rclcpp_action::CancelResponse::ACCEPT;
206+
}
207+
188208
controller_interface::return_type
189209
ToolContactController::update_reference_from_subscribers(const rclcpp::Time& time, const rclcpp::Duration& period)
190210
{

0 commit comments

Comments
 (0)