@@ -40,8 +40,6 @@ hardware_interface::CallbackReturn RRBotSystemPositionOnlyHardware::on_init(
4040 hw_stop_sec_ = stod (info_.hardware_parameters [" example_param_hw_stop_duration_sec" ]);
4141 hw_slowdown_ = stod (info_.hardware_parameters [" example_param_hw_slowdown" ]);
4242 // END: This part here is for exemplary purposes - Please do not copy to your production code
43- hw_states_.resize (info_.joints .size (), std::numeric_limits<double >::quiet_NaN ());
44- hw_commands_.resize (info_.joints .size (), std::numeric_limits<double >::quiet_NaN ());
4543
4644 for (const hardware_interface::ComponentInfo & joint : info_.joints )
4745 {
@@ -103,41 +101,17 @@ hardware_interface::CallbackReturn RRBotSystemPositionOnlyHardware::on_configure
103101 // END: This part here is for exemplary purposes - Please do not copy to your production code
104102
105103 // reset values always when configuring hardware
106- for (uint i = 0 ; i < hw_states_ .size (); i++)
104+ for (uint i = 0 ; i < joint_pos_states_ .size (); i++)
107105 {
108- hw_states_[i] = 0 ;
109- hw_commands_[i] = 0 ;
106+ joint_pos_states_[i] = 0.0 ;
110107 }
111-
112- RCLCPP_INFO (rclcpp::get_logger (" RRBotSystemPositionOnlyHardware" ), " Successfully configured!" );
113-
114- return hardware_interface::CallbackReturn::SUCCESS;
115- }
116-
117- std::vector<hardware_interface::StateInterface>
118- RRBotSystemPositionOnlyHardware::export_state_interfaces ()
119- {
120- std::vector<hardware_interface::StateInterface> state_interfaces;
121- for (uint i = 0 ; i < info_.joints .size (); i++)
108+ for (uint i = 0 ; i < joint_pos_commands_.size (); i++)
122109 {
123- state_interfaces.emplace_back (hardware_interface::StateInterface (
124- info_.joints [i].name , hardware_interface::HW_IF_POSITION, &hw_states_[i]));
125- }
126-
127- return state_interfaces;
128- }
129-
130- std::vector<hardware_interface::CommandInterface>
131- RRBotSystemPositionOnlyHardware::export_command_interfaces ()
132- {
133- std::vector<hardware_interface::CommandInterface> command_interfaces;
134- for (uint i = 0 ; i < info_.joints .size (); i++)
135- {
136- command_interfaces.emplace_back (hardware_interface::CommandInterface (
137- info_.joints [i].name , hardware_interface::HW_IF_POSITION, &hw_commands_[i]));
110+ joint_pos_commands_[i] = 0.0 ;
138111 }
112+ RCLCPP_INFO (rclcpp::get_logger (" RRBotSystemPositionOnlyHardware" ), " Successfully configured!" );
139113
140- return command_interfaces ;
114+ return hardware_interface::CallbackReturn::SUCCESS ;
141115}
142116
143117hardware_interface::CallbackReturn RRBotSystemPositionOnlyHardware::on_activate (
@@ -157,9 +131,9 @@ hardware_interface::CallbackReturn RRBotSystemPositionOnlyHardware::on_activate(
157131 // END: This part here is for exemplary purposes - Please do not copy to your production code
158132
159133 // command and state should be equal when starting
160- for (uint i = 0 ; i < hw_states_ .size (); i++)
134+ for (uint i = 0 ; i < joint_pos_states_ .size (); i++)
161135 {
162- hw_commands_ [i] = hw_states_ [i];
136+ joint_pos_commands_ [i] = joint_pos_states_ [i];
163137 }
164138
165139 RCLCPP_INFO (rclcpp::get_logger (" RRBotSystemPositionOnlyHardware" ), " Successfully activated!" );
@@ -194,13 +168,14 @@ hardware_interface::return_type RRBotSystemPositionOnlyHardware::read(
194168 // BEGIN: This part here is for exemplary purposes - Please do not copy to your production code
195169 RCLCPP_INFO (rclcpp::get_logger (" RRBotSystemPositionOnlyHardware" ), " Reading..." );
196170
197- for (uint i = 0 ; i < hw_states_ .size (); i++)
171+ for (uint i = 0 ; i < joint_pos_states_ .size (); i++)
198172 {
199173 // Simulate RRBot's movement
200- hw_states_[i] = hw_states_[i] + (hw_commands_[i] - hw_states_[i]) / hw_slowdown_;
174+ joint_pos_states_[i] =
175+ joint_pos_states_[i] + (joint_pos_commands_[i] - joint_pos_states_[i]) / hw_slowdown_;
201176 RCLCPP_INFO (
202177 rclcpp::get_logger (" RRBotSystemPositionOnlyHardware" ), " Got state %.5f for joint %d!" ,
203- hw_states_ [i], i);
178+ joint_pos_states_ [i], i);
204179 }
205180 RCLCPP_INFO (rclcpp::get_logger (" RRBotSystemPositionOnlyHardware" ), " Joints successfully read!" );
206181 // END: This part here is for exemplary purposes - Please do not copy to your production code
@@ -214,12 +189,12 @@ hardware_interface::return_type RRBotSystemPositionOnlyHardware::write(
214189 // BEGIN: This part here is for exemplary purposes - Please do not copy to your production code
215190 RCLCPP_INFO (rclcpp::get_logger (" RRBotSystemPositionOnlyHardware" ), " Writing..." );
216191
217- for (uint i = 0 ; i < hw_commands_ .size (); i++)
192+ for (uint i = 0 ; i < joint_pos_commands_ .size (); i++)
218193 {
219194 // Simulate sending commands to the hardware
220195 RCLCPP_INFO (
221196 rclcpp::get_logger (" RRBotSystemPositionOnlyHardware" ), " Got command %.5f for joint %d!" ,
222- hw_commands_ [i], i);
197+ joint_pos_commands_ [i], i);
223198 }
224199 RCLCPP_INFO (
225200 rclcpp::get_logger (" RRBotSystemPositionOnlyHardware" ), " Joints successfully written!" );
0 commit comments