@@ -526,27 +526,53 @@ bool HardwareInterface::prepareSwitch(const std::list<hardware_interface::Contro
526526void HardwareInterface::doSwitch (const std::list<hardware_interface::ControllerInfo>& start_list,
527527 const std::list<hardware_interface::ControllerInfo>& stop_list)
528528{
529- position_controller_running_ = false ;
530- velocity_controller_running_ = false ;
531- for (auto & controller_it : start_list)
529+ for (auto & controller_it : stop_list)
532530 {
533531 for (auto & resource_it : controller_it.claimed_resources )
534532 {
535- if (resource_it.hardware_interface == " ur_controllers::ScaledPositionJointInterface" )
536- {
537- position_controller_running_ = true ;
538- }
539- if (resource_it.hardware_interface == " hardware_interface::PositionJointInterface" )
540- {
541- position_controller_running_ = true ;
542- }
543- if (resource_it.hardware_interface == " ur_controllers::ScaledVelocityJointInterface" )
533+ if (checkControllerClaims (resource_it.resources ))
544534 {
545- velocity_controller_running_ = true ;
535+ if (resource_it.hardware_interface == " ur_controllers::ScaledPositionJointInterface" )
536+ {
537+ position_controller_running_ = false ;
538+ }
539+ if (resource_it.hardware_interface == " hardware_interface::PositionJointInterface" )
540+ {
541+ position_controller_running_ = false ;
542+ }
543+ if (resource_it.hardware_interface == " ur_controllers::ScaledVelocityJointInterface" )
544+ {
545+ velocity_controller_running_ = false ;
546+ }
547+ if (resource_it.hardware_interface == " hardware_interface::VelocityJointInterface" )
548+ {
549+ velocity_controller_running_ = false ;
550+ }
546551 }
547- if (resource_it.hardware_interface == " hardware_interface::VelocityJointInterface" )
552+ }
553+ }
554+ for (auto & controller_it : start_list)
555+ {
556+ for (auto & resource_it : controller_it.claimed_resources )
557+ {
558+ if (checkControllerClaims (resource_it.resources ))
548559 {
549- velocity_controller_running_ = true ;
560+ if (resource_it.hardware_interface == " ur_controllers::ScaledPositionJointInterface" )
561+ {
562+ position_controller_running_ = true ;
563+ }
564+ if (resource_it.hardware_interface == " hardware_interface::PositionJointInterface" )
565+ {
566+ position_controller_running_ = true ;
567+ }
568+ if (resource_it.hardware_interface == " ur_controllers::ScaledVelocityJointInterface" )
569+ {
570+ velocity_controller_running_ = true ;
571+ }
572+ if (resource_it.hardware_interface == " hardware_interface::VelocityJointInterface" )
573+ {
574+ velocity_controller_running_ = true ;
575+ }
550576 }
551577 }
552578 }
@@ -830,6 +856,21 @@ void HardwareInterface::publishRobotAndSafetyMode()
830856 }
831857 }
832858}
859+
860+ bool HardwareInterface::checkControllerClaims (const std::set<std::string>& claimed_resources)
861+ {
862+ for (const std::string& it : joint_names_)
863+ {
864+ for (const std::string& jt : claimed_resources)
865+ {
866+ if (it == jt)
867+ {
868+ return true ;
869+ }
870+ }
871+ }
872+ return false ;
873+ }
833874} // namespace ur_driver
834875
835876PLUGINLIB_EXPORT_CLASS (ur_driver::HardwareInterface, hardware_interface::RobotHW)
0 commit comments