4444#include < rclcpp/logging.hpp>
4545#include " std_msgs/msg/bool.hpp"
4646#include < lifecycle_msgs/msg/state.hpp>
47- #include < iostream>
4847
4948namespace 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