Skip to content

Commit 472d750

Browse files
committed
Update ft state controller with ros2_control changes.
1 parent 7443465 commit 472d750

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

ur_controllers/include/ur_controllers/force_torque_sensor_controller.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
#include <vector>
1212

1313
#include <controller_interface/controller_interface.hpp>
14-
#include "rclcpp_lifecycle/lifecycle_publisher.hpp"
15-
#include "rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp"
1614

1715
#include <geometry_msgs/msg/wrench_stamped.hpp>
1816

@@ -35,13 +33,15 @@ class ForceTorqueStateController : public controller_interface::ControllerInterf
3533

3634
CallbackReturn on_deactivate(const rclcpp_lifecycle::State& previous_state) override;
3735

36+
controller_interface::return_type init(const std::string &controller_name) override;
37+
3838
protected:
3939
bool init_sensor_data();
4040
void init_sensor_state_msg();
4141

4242
// we store the name of values per axis - compatible interfaces
4343
std::vector<std::string> axis_val_names_;
44-
std::shared_ptr<rclcpp_lifecycle::LifecyclePublisher<geometry_msgs::msg::WrenchStamped>> wrench_state_publisher_;
44+
std::shared_ptr<rclcpp::Publisher<geometry_msgs::msg::WrenchStamped>> wrench_state_publisher_;
4545
geometry_msgs::msg::WrenchStamped wrench_state_msg_;
4646
};
4747
} // namespace ur_controllers

ur_controllers/src/force_torque_sensor_controller.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,23 @@
66

77
namespace ur_controllers
88
{
9+
910
ForceTorqueStateController::ForceTorqueStateController() : controller_interface::ControllerInterface()
1011
{
1112
}
1213

13-
controller_interface::InterfaceConfiguration ForceTorqueStateController::command_interface_configuration() const
14+
controller_interface::return_type ForceTorqueStateController::init(const std::string &controller_name) {
15+
16+
auto ret = ControllerInterface::init(controller_name);
17+
if (ret != controller_interface::return_type::SUCCESS) {
18+
return ret;
19+
}
20+
21+
return controller_interface::return_type::SUCCESS;
22+
23+
}
24+
25+
controller_interface::InterfaceConfiguration ForceTorqueStateController::command_interface_configuration() const
1426
{
1527
controller_interface::InterfaceConfiguration config;
1628
config.type = controller_interface::interface_configuration_type::NONE;
@@ -76,12 +88,6 @@ controller_interface::return_type ur_controllers::ForceTorqueStateController::up
7688
}
7789
}
7890

79-
if (!wrench_state_publisher_->is_activated())
80-
{
81-
RCUTILS_LOG_WARN_ONCE_NAMED("publisher", "wrench state publisher is not activated");
82-
return controller_interface::return_type::ERROR;
83-
}
84-
8591
// TODO set frame_id as parameter --> it includes tf listener within controller
8692
wrench_state_msg_.header.stamp = get_node()->get_clock()->now();
8793
wrench_state_msg_.header.frame_id = "tool0";
@@ -122,16 +128,12 @@ ForceTorqueStateController::on_activate(const rclcpp_lifecycle::State& /*previou
122128

123129
init_sensor_state_msg();
124130

125-
wrench_state_publisher_->on_activate();
126-
127131
return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::SUCCESS;
128132
}
129133

130134
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn
131135
ForceTorqueStateController::on_deactivate(const rclcpp_lifecycle::State& /*previous_state*/)
132136
{
133-
wrench_state_publisher_->on_deactivate();
134-
135137
return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::SUCCESS;
136138
}
137139

0 commit comments

Comments
 (0)