Skip to content

Commit 0baaa19

Browse files
Felix Exnerfmauch
authored andcommitted
Fixes controller switches to only act if necessary
all control communication was set to false when a switch was called. This is not correct, as we might e.g. only start a reading controller such as the FTS measurements. Second, controllers were never checked for matching joints in this HW interface which is problematic in combined-hw cases.
1 parent 90bab85 commit 0baaa19

File tree

2 files changed

+64
-15
lines changed

2 files changed

+64
-15
lines changed

ur_robot_driver/include/ur_robot_driver/ros/hardware_interface.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@ class HardwareInterface : public hardware_interface::RobotHW
196196
std::unique_ptr<UrDriver> ur_driver_;
197197
std::unique_ptr<DashboardClientROS> dashboard_client_;
198198

199+
/*!
200+
* \brief Checks whether a resource list contains joints from this hardware interface
201+
*
202+
* True is returned as soon as one joint name from claimed_resources matches a joint from this
203+
* hardware interface.
204+
*/
205+
bool checkControllerClaims(const std::set<std::string>& claimed_resources);
206+
199207
ros::ServiceServer deactivate_srv_;
200208
ros::ServiceServer tare_sensor_srv_;
201209

ur_robot_driver/src/ros/hardware_interface.cpp

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -526,27 +526,53 @@ bool HardwareInterface::prepareSwitch(const std::list<hardware_interface::Contro
526526
void 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

835876
PLUGINLIB_EXPORT_CLASS(ur_driver::HardwareInterface, hardware_interface::RobotHW)

0 commit comments

Comments
 (0)