@@ -97,7 +97,6 @@ CallbackReturn TopicBasedSystem::on_init(const hardware_interface::HardwareInfo&
9797 }
9898 }
9999 }
100- ready_to_send_cmds_ = true ;
101100
102101 // Search for mimic joints
103102 for (auto i = 0u ; i < info_.joints .size (); ++i)
@@ -160,11 +159,6 @@ CallbackReturn TopicBasedSystem::on_init(const hardware_interface::HardwareInfo&
160159 {
161160 sum_wrapped_joint_states_ = true ;
162161 }
163- if (get_hardware_parameter (" use_initial_states_as_initial_commands" , " false" ) == " true" )
164- {
165- initial_states_as_initial_cmd_ = true ;
166- ready_to_send_cmds_ = false ;
167- }
168162 if (get_hardware_parameter (" wait_for_reaching_initial_values" , " false" ) == " false" )
169163 {
170164 initial_cmd_reached_ = true ;
@@ -257,18 +251,6 @@ hardware_interface::return_type TopicBasedSystem::read(const rclcpp::Time& /*tim
257251 }
258252 }
259253
260- if (!ready_to_send_cmds_ && initial_states_as_initial_cmd_)
261- {
262- for (std::size_t i = 0 ; i < joint_states_.size (); ++i)
263- {
264- for (std::size_t j = 0 ; j < joint_states_[i].size (); ++j)
265- {
266- joint_commands_[i][j] = joint_states_[i][j];
267- }
268- }
269- ready_to_send_cmds_ = true ;
270- }
271-
272254 return hardware_interface::return_type::OK;
273255}
274256
@@ -289,17 +271,12 @@ bool TopicBasedSystem::getInterface(const std::string& name, const std::string&
289271
290272hardware_interface::return_type TopicBasedSystem::write (const rclcpp::Time& /* time*/ , const rclcpp::Duration& /* period*/ )
291273{
292- if (!ready_to_send_cmds_)
293- {
294- return hardware_interface::return_type::ERROR;
295- }
296-
297274 std::vector<std::vector<double >> target_joint_commands;
298275 if (initial_cmd_reached_ == false )
299276 {
300- double abs_sum = std::accumulate (joint_commands_[POSITION_INTERFACE_INDEX].begin (), joint_commands_[POSITION_INTERFACE_INDEX]. end (), 0 , []( double sum, double val) {
301- return sum + std::abs (val);
302- });
277+ double abs_sum = std::accumulate (joint_commands_[POSITION_INTERFACE_INDEX].begin (),
278+ joint_commands_[POSITION_INTERFACE_INDEX]. end (), 0 ,
279+ []( double sum, double val) { return sum + std::abs (val); });
303280 if (abs_sum >= trigger_joint_command_threshold_)
304281 {
305282 initial_cmd_reached_ = true ;
@@ -321,7 +298,7 @@ hardware_interface::return_type TopicBasedSystem::write(const rclcpp::Time& /*ti
321298 [](const auto d1, const auto d2) { return std::abs (d1) + std::abs (d2); }, std::minus<double >{});
322299
323300 bool exist_velocity_command = false ;
324- static bool exist_velocity_command_old = false ; // Use old state to publish zero velocities
301+ static bool exist_velocity_command_old = false ; // Use old state to publish zero velocities
325302 for (std::size_t i = 0 ; i < info_.joints .size (); ++i)
326303 {
327304 if (fabs (target_joint_commands[VELOCITY_INTERFACE_INDEX][i]) > trigger_joint_command_threshold_)
@@ -330,11 +307,12 @@ hardware_interface::return_type TopicBasedSystem::write(const rclcpp::Time& /*ti
330307 }
331308 }
332309
333- if (diff <= trigger_joint_command_threshold_ && (exist_velocity_command == false && exist_velocity_command_old == false ))
310+ if (diff <= trigger_joint_command_threshold_ &&
311+ (exist_velocity_command == false && exist_velocity_command_old == false ))
334312 {
335313 return hardware_interface::return_type::OK;
336314 }
337-
315+
338316 exist_velocity_command_old = exist_velocity_command;
339317
340318 // For Position Joint
@@ -365,7 +343,7 @@ hardware_interface::return_type TopicBasedSystem::write(const rclcpp::Time& /*ti
365343 if (joint_state.name [index] == mimic_joint.mimicked_joint_name )
366344 {
367345 joint_state.name .push_back (mimic_joint.joint_name );
368- joint_state.position .push_back (mimic_joint.multiplier * joint_state.position [index]);
346+ joint_state.position .push_back (mimic_joint.multiplier * joint_state.position [index]);
369347 }
370348 }
371349 }
@@ -377,7 +355,7 @@ hardware_interface::return_type TopicBasedSystem::write(const rclcpp::Time& /*ti
377355 topic_based_joint_commands_publisher_->publish (joint_state);
378356 }
379357 }
380-
358+
381359 // For Velocity Joint
382360 {
383361 sensor_msgs::msg::JointState joint_state;
@@ -406,7 +384,7 @@ hardware_interface::return_type TopicBasedSystem::write(const rclcpp::Time& /*ti
406384 if (joint_state.name [index] == mimic_joint.mimicked_joint_name )
407385 {
408386 joint_state.name .push_back (mimic_joint.joint_name );
409- joint_state.velocity .push_back (mimic_joint.multiplier * joint_state.velocity [index]);
387+ joint_state.velocity .push_back (mimic_joint.multiplier * joint_state.velocity [index]);
410388 }
411389 }
412390 }
@@ -418,7 +396,7 @@ hardware_interface::return_type TopicBasedSystem::write(const rclcpp::Time& /*ti
418396 topic_based_joint_commands_publisher_->publish (joint_state);
419397 }
420398 }
421-
399+
422400 // For Effort Joint
423401 {
424402 sensor_msgs::msg::JointState joint_state;
@@ -447,7 +425,7 @@ hardware_interface::return_type TopicBasedSystem::write(const rclcpp::Time& /*ti
447425 if (joint_state.name [index] == mimic_joint.mimicked_joint_name )
448426 {
449427 joint_state.name .push_back (mimic_joint.joint_name );
450- joint_state.effort .push_back (mimic_joint.multiplier * joint_state.effort [index]);
428+ joint_state.effort .push_back (mimic_joint.multiplier * joint_state.effort [index]);
451429 }
452430 }
453431 }
0 commit comments