@@ -160,7 +160,7 @@ hardware_interface::CallbackReturn DynamixelHardware::on_init(
160160 RCLCPP_INFO_STREAM (logger_, " Trying to connect to the communication port..." );
161161 break ;
162162 } else {
163- sleep ( 1 );
163+ std::this_thread::sleep_for ( std::chrono::seconds ( 1 ) );
164164 if (i == 9 ) {
165165 RCLCPP_ERROR_STREAM (logger_, " Cannot connect communication port! :(" );
166166 return hardware_interface::CallbackReturn::ERROR;
@@ -186,7 +186,7 @@ hardware_interface::CallbackReturn DynamixelHardware::on_init(
186186 RCLCPP_INFO_STREAM (logger_, " Trying to connect to the communication port..." );
187187 break ;
188188 } else {
189- sleep ( 1 );
189+ std::this_thread::sleep_for ( std::chrono::seconds ( 1 ) );
190190 if (i == 9 ) {
191191 RCLCPP_ERROR_STREAM (logger_, " Cannot connect communication port! :(" );
192192 return hardware_interface::CallbackReturn::ERROR;
@@ -499,7 +499,7 @@ hardware_interface::CallbackReturn DynamixelHardware::start()
499499
500500 // sync commands = states joint
501501 SyncJointCommandWithStates ();
502- usleep ( 500 * 1000 );
502+ std::this_thread::sleep_for ( std::chrono::milliseconds ( 500 ) );
503503
504504 // Enable torque only for Dynamixels that have torque enabled in their parameters
505505 std::vector<uint8_t > torque_enabled_ids;
@@ -516,7 +516,7 @@ hardware_interface::CallbackReturn DynamixelHardware::start()
516516 break ;
517517 }
518518 RCLCPP_ERROR_STREAM (logger_, " Failed to enable torque for Dynamixels, retry..." );
519- usleep ( 100 * 1000 );
519+ std::this_thread::sleep_for ( std::chrono::milliseconds ( 100 ) );
520520 }
521521 }
522522
@@ -703,7 +703,7 @@ bool DynamixelHardware::CommReset()
703703
704704 auto start_time = this ->now ();
705705 while ((this ->now () - start_time) < rclcpp::Duration (3 , 0 )) {
706- usleep ( 200 * 1000 );
706+ std::this_thread::sleep_for ( std::chrono::milliseconds ( 200 ) );
707707 RCLCPP_INFO_STREAM (logger_, " Reset Start" );
708708 bool result = true ;
709709 for (auto id : dxl_id_) {
@@ -712,7 +712,7 @@ bool DynamixelHardware::CommReset()
712712 result = false ;
713713 break ;
714714 }
715- usleep ( 200 * 1000 );
715+ std::this_thread::sleep_for ( std::chrono::milliseconds ( 200 ) );
716716 }
717717 if (!result) {continue ;}
718718 if (!InitControllerItems ()) {continue ;}
@@ -721,13 +721,13 @@ bool DynamixelHardware::CommReset()
721721 if (!InitDxlWriteItems ()) {continue ;}
722722
723723 RCLCPP_INFO_STREAM (logger_, " RESET Success" );
724- usleep ( 1000 * 1000 );
724+ std::this_thread::sleep_for ( std::chrono::seconds ( 1 ) );
725725 start ();
726726 dxl_status_ = DXL_OK;
727727 return true ;
728728 }
729729 RCLCPP_ERROR_STREAM (logger_, " RESET Failure" );
730- usleep ( 1000 * 1000 );
730+ std::this_thread::sleep_for ( std::chrono::seconds ( 1 ) );
731731 start ();
732732 return false ;
733733}
0 commit comments