Skip to content

Commit 947c30f

Browse files
committed
Add version check and fix formatting
1 parent 2224514 commit 947c30f

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

ur_controllers/include/ur_controllers/tool_contact_controller.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
#define UR_CONTROLLERS__TOOL_CONTACT_CONTROLLER_HPP_
4343

4444
#include <chrono>
45+
#include <vector>
46+
#include <memory>
4547

4648
#include <controller_interface/chainable_controller_interface.hpp>
4749
#include "std_msgs/msg/bool.hpp"
@@ -165,6 +167,7 @@ class ToolContactController : public controller_interface::ChainableControllerIn
165167
double old_reference_val = 0.0;
166168

167169
std::optional<std::reference_wrapper<hardware_interface::LoanedStateInterface>> tool_contact_result_interface_;
170+
std::optional<std::reference_wrapper<hardware_interface::LoanedStateInterface>> tool_contact_version_interface_;
168171
std::optional<std::reference_wrapper<hardware_interface::LoanedCommandInterface>> tool_contact_status_interface_;
169172
std::optional<std::reference_wrapper<hardware_interface::LoanedCommandInterface>> reference_interface_;
170173

@@ -183,4 +186,4 @@ class ToolContactController : public controller_interface::ChainableControllerIn
183186
};
184187
} // namespace ur_controllers
185188

186-
#endif
189+
#endif // UR_CONTROLLERS__TOOL_CONTACT_CONTROLLER_HPP_

ur_controllers/src/tool_contact_controller.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
#include <rclcpp/logging.hpp>
4545
#include "std_msgs/msg/bool.hpp"
4646
#include <lifecycle_msgs/msg/state.hpp>
47-
#include <iostream>
4847

4948
namespace ur_controllers
5049
{
@@ -89,6 +88,7 @@ controller_interface::InterfaceConfiguration ToolContactController::state_interf
8988

9089
const std::string tf_prefix = tool_contact_params_.tf_prefix;
9190
config.names.push_back(tf_prefix + "tool_contact/tool_contact_result");
91+
config.names.push_back(tf_prefix + "get_robot_software_version/get_version_major");
9292
return config;
9393
}
9494

@@ -140,6 +140,27 @@ ToolContactController::on_activate(const rclcpp_lifecycle::State& /* previous_st
140140
return controller_interface::CallbackReturn::ERROR;
141141
}
142142
}
143+
{
144+
const std::string interface_name = tool_contact_params_.tf_prefix + "get_robot_software_version/get_version_major";
145+
auto it = std::find_if(state_interfaces_.begin(), state_interfaces_.end(),
146+
[&](auto& interface) { return (interface.get_name() == interface_name); });
147+
if (it != state_interfaces_.end()) {
148+
tool_contact_version_interface_ = *it;
149+
if (!tool_contact_result_interface_->get().get_value()) {
150+
RCLCPP_ERROR(get_node()->get_logger(),
151+
"Failed to read '%s' state interface, aborting activation of controller.", interface_name.c_str());
152+
return controller_interface::CallbackReturn::ERROR;
153+
}
154+
} else {
155+
RCLCPP_ERROR(get_node()->get_logger(), "Did not find '%s' in state interfaces.", interface_name.c_str());
156+
return controller_interface::CallbackReturn::ERROR;
157+
}
158+
}
159+
if (tool_contact_version_interface_->get().get_value() < 5) {
160+
RCLCPP_ERROR(get_node()->get_logger(), "This feature is not supported on CB3 robots, controller will not be "
161+
"started.");
162+
return controller_interface::CallbackReturn::ERROR;
163+
}
143164

144165
return controller_interface::CallbackReturn::SUCCESS;
145166
}
@@ -420,4 +441,4 @@ controller_interface::return_type ToolContactController::update_and_write_comman
420441

421442
#include "pluginlib/class_list_macros.hpp"
422443

423-
PLUGINLIB_EXPORT_CLASS(ur_controllers::ToolContactController, controller_interface::ChainableControllerInterface)
444+
PLUGINLIB_EXPORT_CLASS(ur_controllers::ToolContactController, controller_interface::ChainableControllerInterface)

0 commit comments

Comments
 (0)