@@ -101,13 +101,13 @@ hardware_interface::CallbackReturn RRBotSystemPositionOnlyHardware::on_configure
101101 // END: This part here is for exemplary purposes - Please do not copy to your production code
102102
103103 // reset values always when configuring hardware
104- for (uint i = 0 ; i < joint_pos_states_. size (); i++ )
104+ for (const auto & descr : joint_states_descr_ )
105105 {
106- joint_pos_states_[i] = 0.0 ;
106+ joint_state_set_value (descr, 0.0 ) ;
107107 }
108- for (uint i = 0 ; i < joint_pos_commands_. size (); i++ )
108+ for (const auto & descr : joint_commands_descr_ )
109109 {
110- joint_pos_commands_[i] = 0.0 ;
110+ joint_command_set_value (descr, 0.0 ) ;
111111 }
112112 RCLCPP_INFO (rclcpp::get_logger (" RRBotSystemPositionOnlyHardware" ), " Successfully configured!" );
113113
@@ -131,9 +131,9 @@ hardware_interface::CallbackReturn RRBotSystemPositionOnlyHardware::on_activate(
131131 // END: This part here is for exemplary purposes - Please do not copy to your production code
132132
133133 // command and state should be equal when starting
134- for (uint i = 0 ; i < joint_pos_states_. size (); i++ )
134+ for (const auto & descr : joint_states_descr_ )
135135 {
136- joint_pos_commands_[i] = joint_pos_states_[i] ;
136+ joint_command_set_value (descr, joint_state_get_value (descr)) ;
137137 }
138138
139139 RCLCPP_INFO (rclcpp::get_logger (" RRBotSystemPositionOnlyHardware" ), " Successfully activated!" );
@@ -168,14 +168,15 @@ hardware_interface::return_type RRBotSystemPositionOnlyHardware::read(
168168 // BEGIN: This part here is for exemplary purposes - Please do not copy to your production code
169169 RCLCPP_INFO (rclcpp::get_logger (" RRBotSystemPositionOnlyHardware" ), " Reading..." );
170170
171- for (uint i = 0 ; i < joint_pos_states_. size (); i++ )
171+ for (const auto & descr : joint_states_descr_ )
172172 {
173+ auto new_value = joint_state_get_value (descr) +
174+ (joint_command_get_value (descr) - joint_state_get_value (descr)) / hw_slowdown_;
175+ joint_state_set_value (descr, new_value);
173176 // Simulate RRBot's movement
174- joint_pos_states_[i] =
175- joint_pos_states_[i] + (joint_pos_commands_[i] - joint_pos_states_[i]) / hw_slowdown_;
176- RCLCPP_INFO (
177- rclcpp::get_logger (" RRBotSystemPositionOnlyHardware" ), " Got state %.5f for joint %d!" ,
178- joint_pos_states_[i], i);
177+ RCLCPP_INFO_STREAM (
178+ rclcpp::get_logger (" RRBotSystemPositionOnlyHardware" ),
179+ " Got state " << joint_state_get_value (descr) << " for joint: " << descr.get_name () << " !" );
179180 }
180181 RCLCPP_INFO (rclcpp::get_logger (" RRBotSystemPositionOnlyHardware" ), " Joints successfully read!" );
181182 // END: This part here is for exemplary purposes - Please do not copy to your production code
@@ -189,12 +190,12 @@ hardware_interface::return_type RRBotSystemPositionOnlyHardware::write(
189190 // BEGIN: This part here is for exemplary purposes - Please do not copy to your production code
190191 RCLCPP_INFO (rclcpp::get_logger (" RRBotSystemPositionOnlyHardware" ), " Writing..." );
191192
192- for (uint i = 0 ; i < joint_pos_commands_. size (); i++ )
193+ for (const auto & descr : joint_commands_descr_ )
193194 {
194195 // Simulate sending commands to the hardware
195- RCLCPP_INFO (
196- rclcpp::get_logger (" RRBotSystemPositionOnlyHardware" ), " Got command %.5f for joint %d! " ,
197- joint_pos_commands_[i], i );
196+ RCLCPP_INFO_STREAM (
197+ rclcpp::get_logger (" RRBotSystemPositionOnlyHardware" ),
198+ " Got command " << joint_command_get_value (descr) << " for joint: " << descr. get_name () << " ! " );
198199 }
199200 RCLCPP_INFO (
200201 rclcpp::get_logger (" RRBotSystemPositionOnlyHardware" ), " Joints successfully written!" );
0 commit comments