@@ -90,7 +90,7 @@ SafetyPositionController::on_configure( const rclcpp_lifecycle::State & )
9090
9191 const size_t n = params_.joints .size ();
9292 reference_interfaces_.assign ( n, std::numeric_limits<double >::quiet_NaN () );
93- state_interface_index_ .assign ( n, -1 );
93+ joint_index_ .assign ( n, -1 );
9494 cmd_positions_.assign ( n, std::numeric_limits<double >::quiet_NaN () );
9595 current_positions_.assign ( n, std::numeric_limits<double >::quiet_NaN () );
9696
@@ -109,7 +109,7 @@ SafetyPositionController::on_activate( const rclcpp_lifecycle::State & )
109109
110110 on_hold_ = false ;
111111
112- if ( !gather_interface_indices () ) {
112+ if ( !gather_joint_indices () ) {
113113 RCLCPP_ERROR ( get_node ()->get_logger (),
114114 " Failed to gather state interface indices for joints." );
115115 return controller_interface::CallbackReturn::ERROR;
@@ -257,8 +257,7 @@ SafetyPositionController::update_and_write_commands( const rclcpp::Time &, const
257257bool SafetyPositionController::read_current_positions ()
258258{
259259 for ( size_t i = 0 ; i < params_.joints .size (); ++i ) {
260- const auto &opt =
261- state_interfaces_[static_cast <size_t >( state_interface_index_[i] )].get_optional ();
260+ const auto &opt = state_interfaces_[static_cast <size_t >( joint_index_[i] )].get_optional ();
262261 if ( opt.has_value () ) {
263262 current_positions_[i] = opt.value ();
264263 } else {
@@ -441,27 +440,26 @@ bool SafetyPositionController::parse_urdf_and_fill_joint_info( const std::string
441440 return true ;
442441}
443442
444- bool SafetyPositionController::gather_interface_indices ()
443+ bool SafetyPositionController::gather_joint_indices ()
445444{
446445 bool success = true ;
447446 for ( size_t i = 0 ; i < params_.joints .size (); ++i ) {
448- state_interface_index_[i] = -1 ;
449- for ( size_t s = 0 ; s < state_interfaces_.size (); ++s ) {
450- auto name = state_interfaces_[s].get_name ();
451- auto interface_name = state_interfaces_[s].get_interface_name ();
452- if ( state_interfaces_[s].get_name () == params_.joints [i] + " /position" &&
453- state_interfaces_[s].get_interface_name () == " position" ) {
454- state_interface_index_[i] = static_cast <int >( s );
447+ const auto &jn = params_.joints [i];
448+ for ( size_t s = 0 ; s < all_joint_names_.size (); ++s ) {
449+ const auto &candidate = all_joint_names_[s];
450+ if ( candidate == jn ) {
451+ joint_index_[i] = static_cast <int >( s );
455452 break ;
456453 }
457454 }
458- if ( state_interface_index_ [i] < 0 )
459- RCLCPP_WARN ( get_node ()->get_logger (), " No state interface 'position' found for joint '%s'." ,
455+ if ( joint_index_ [i] < 0 )
456+ RCLCPP_WARN ( get_node ()->get_logger (), " Error in joint indexing '%s'." ,
460457 params_.joints [i].c_str () );
461- success &= ( state_interface_index_ [i] >= 0 );
458+ success &= ( joint_index_ [i] >= 0 );
462459 }
463460 return success;
464461}
462+
465463bool SafetyPositionController::wait_for_srdf ()
466464{
467465 // wait for the semantic description message to be received
0 commit comments