Skip to content

Commit f04443f

Browse files
Remove mimic parameter from ros2_control tag (#1553)
1 parent 4d60885 commit f04443f

File tree

3 files changed

+30
-145
lines changed

3 files changed

+30
-145
lines changed

hardware_interface/src/component_parser.cpp

Lines changed: 30 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -838,98 +838,53 @@ std::vector<HardwareInfo> parse_control_resources_from_urdf(const std::string &
838838
for (auto i = 0u; i < hw_info.joints.size(); ++i)
839839
{
840840
const auto & joint = hw_info.joints.at(i);
841-
842-
// Search for mimic joints defined in ros2_control tag (deprecated)
843-
// TODO(christophfroehlich) delete deprecated config with ROS-J
844-
if (joint.parameters.find("mimic") != joint.parameters.cend())
841+
auto urdf_joint = model.getJoint(joint.name);
842+
if (!urdf_joint)
845843
{
846-
std::cerr << "Warning: Mimic joints defined in ros2_control tag are deprecated. "
847-
<< "Please define mimic joints in URDF." << std::endl;
848-
const auto mimicked_joint_it = std::find_if(
849-
hw_info.joints.begin(), hw_info.joints.end(),
850-
[&mimicked_joint =
851-
joint.parameters.at("mimic")](const hardware_interface::ComponentInfo & joint_info)
852-
{ return joint_info.name == mimicked_joint; });
853-
if (mimicked_joint_it == hw_info.joints.cend())
854-
{
855-
throw std::runtime_error(
856-
"Mimicked joint '" + joint.parameters.at("mimic") + "' not found");
857-
}
858-
hardware_interface::MimicJoint mimic_joint;
859-
mimic_joint.joint_index = i;
860-
mimic_joint.multiplier = 1.0;
861-
mimic_joint.offset = 0.0;
862-
mimic_joint.mimicked_joint_index = std::distance(hw_info.joints.begin(), mimicked_joint_it);
863-
auto param_it = joint.parameters.find("multiplier");
864-
if (param_it != joint.parameters.end())
865-
{
866-
mimic_joint.multiplier = hardware_interface::stod(joint.parameters.at("multiplier"));
867-
}
868-
param_it = joint.parameters.find("offset");
869-
if (param_it != joint.parameters.end())
870-
{
871-
mimic_joint.offset = hardware_interface::stod(joint.parameters.at("offset"));
872-
}
873-
hw_info.mimic_joints.push_back(mimic_joint);
844+
throw std::runtime_error("Joint '" + joint.name + "' not found in URDF");
874845
}
875-
else
846+
if (!urdf_joint->mimic && joint.is_mimic == MimicAttribute::TRUE)
876847
{
877-
auto urdf_joint = model.getJoint(joint.name);
878-
if (!urdf_joint)
879-
{
880-
throw std::runtime_error("Joint '" + joint.name + "' not found in URDF");
881-
}
882-
if (!urdf_joint->mimic && joint.is_mimic == MimicAttribute::TRUE)
848+
throw std::runtime_error(
849+
"Joint '" + joint.name + "' has no mimic information in the URDF.");
850+
}
851+
if (urdf_joint->mimic && joint.is_mimic != MimicAttribute::FALSE)
852+
{
853+
if (joint.command_interfaces.size() > 0)
883854
{
884855
throw std::runtime_error(
885-
"Joint '" + joint.name + "' has no mimic information in the URDF.");
856+
"Joint '" + joint.name +
857+
"' has mimic attribute not set to false: Activated mimic joints cannot have command "
858+
"interfaces.");
886859
}
887-
if (urdf_joint->mimic && joint.is_mimic != MimicAttribute::FALSE)
860+
auto find_joint = [&hw_info](const std::string & name)
888861
{
889-
if (joint.command_interfaces.size() > 0)
862+
auto it = std::find_if(
863+
hw_info.joints.begin(), hw_info.joints.end(),
864+
[&name](const auto & j) { return j.name == name; });
865+
if (it == hw_info.joints.end())
890866
{
891-
throw std::runtime_error(
892-
"Joint '" + joint.name +
893-
"' has mimic attribute not set to false: Activated mimic joints cannot have command "
894-
"interfaces.");
867+
throw std::runtime_error("Mimic joint '" + name + "' not found in <ros2_control> tag");
895868
}
896-
auto find_joint = [&hw_info](const std::string & name)
897-
{
898-
auto it = std::find_if(
899-
hw_info.joints.begin(), hw_info.joints.end(),
900-
[&name](const auto & j) { return j.name == name; });
901-
if (it == hw_info.joints.end())
902-
{
903-
throw std::runtime_error(
904-
"Mimic joint '" + name + "' not found in <ros2_control> tag");
905-
}
906-
return std::distance(hw_info.joints.begin(), it);
907-
};
908-
909-
MimicJoint mimic_joint;
910-
mimic_joint.joint_index = i;
911-
mimic_joint.mimicked_joint_index = find_joint(urdf_joint->mimic->joint_name);
912-
mimic_joint.multiplier = urdf_joint->mimic->multiplier;
913-
mimic_joint.offset = urdf_joint->mimic->offset;
914-
hw_info.mimic_joints.push_back(mimic_joint);
915-
}
916-
}
917-
// TODO(christophfroehlich) remove this code if deprecated mimic attribute - branch
918-
// from above is removed (double check here, but throws already above if not found in URDF)
919-
auto urdf_joint = model.getJoint(joint.name);
920-
if (!urdf_joint)
921-
{
922-
std::cerr << "Joint: '" + joint.name + "' not found in URDF. Skipping limits parsing!"
923-
<< std::endl;
924-
continue;
869+
return std::distance(hw_info.joints.begin(), it);
870+
};
871+
872+
MimicJoint mimic_joint;
873+
mimic_joint.joint_index = i;
874+
mimic_joint.mimicked_joint_index = find_joint(urdf_joint->mimic->joint_name);
875+
mimic_joint.multiplier = urdf_joint->mimic->multiplier;
876+
mimic_joint.offset = urdf_joint->mimic->offset;
877+
hw_info.mimic_joints.push_back(mimic_joint);
925878
}
879+
926880
if (urdf_joint->type == urdf::Joint::FIXED)
927881
{
928882
throw std::runtime_error(
929883
"Joint '" + joint.name +
930884
"' is of type 'fixed'. "
931885
"Fixed joints do not make sense in ros2_control.");
932886
}
887+
933888
joint_limits::JointLimits limits;
934889
getJointLimits(urdf_joint, limits);
935890
// Take the most restricted one. Also valid for continuous-joint type only

hardware_interface/test/test_component_parser.cpp

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,35 +1341,6 @@ TEST_F(TestComponentParser, gripper_no_mimic_valid_config)
13411341
EXPECT_EQ(hw_info[0].mimic_joints[0].joint_index, 1);
13421342
}
13431343

1344-
// TODO(christophfroehlich) delete deprecated config test
1345-
TEST_F(TestComponentParser, gripper_mimic_deprecated_valid_config)
1346-
{
1347-
const auto urdf_to_test =
1348-
std::string(ros2_control_test_assets::gripper_urdf_head) +
1349-
std::string(ros2_control_test_assets::gripper_hardware_resources_mimic_deprecated) +
1350-
std::string(ros2_control_test_assets::urdf_tail);
1351-
std::vector<hardware_interface::HardwareInfo> hw_info;
1352-
ASSERT_NO_THROW(hw_info = parse_control_resources_from_urdf(urdf_to_test));
1353-
ASSERT_THAT(hw_info, SizeIs(1));
1354-
ASSERT_THAT(hw_info[0].mimic_joints, SizeIs(1));
1355-
EXPECT_DOUBLE_EQ(hw_info[0].mimic_joints[0].multiplier, 2.0);
1356-
EXPECT_DOUBLE_EQ(hw_info[0].mimic_joints[0].offset, 1.0);
1357-
EXPECT_EQ(hw_info[0].mimic_joints[0].mimicked_joint_index, 0);
1358-
EXPECT_EQ(hw_info[0].mimic_joints[0].joint_index, 1);
1359-
}
1360-
1361-
TEST_F(TestComponentParser, gripper_mimic_deprecated_unknown_joint_throws_error)
1362-
{
1363-
const auto urdf_to_test =
1364-
std::string(ros2_control_test_assets::gripper_urdf_head) +
1365-
std::string(
1366-
ros2_control_test_assets::gripper_hardware_resources_mimic_deprecated_unknown_joint) +
1367-
std::string(ros2_control_test_assets::urdf_tail);
1368-
std::vector<hardware_interface::HardwareInfo> hw_info;
1369-
ASSERT_THROW(parse_control_resources_from_urdf(urdf_to_test), std::runtime_error);
1370-
}
1371-
// end delete deprecated config test
1372-
13731344
TEST_F(TestComponentParser, gripper_mimic_with_unknown_joint_throws_error)
13741345
{
13751346
const auto urdf_to_test =

ros2_control_test_assets/include/ros2_control_test_assets/descriptions.hpp

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,47 +1664,6 @@ const auto gripper_hardware_resources_mimic_true_no_command_if =
16641664
</ros2_control>
16651665
)";
16661666

1667-
// TODO(christophfroehlich) delete deprecated config test
1668-
const auto gripper_hardware_resources_mimic_deprecated =
1669-
R"(
1670-
<ros2_control name="TestGripper" type="system">
1671-
<joint name="right_finger_joint">
1672-
<command_interface name="effort"/>
1673-
<state_interface name="position"/>
1674-
<state_interface name="velocity"/>
1675-
<state_interface name="effort"/>
1676-
</joint>
1677-
<joint name="left_finger_joint">
1678-
<param name="mimic">right_finger_joint</param>
1679-
<param name="multiplier">2</param>
1680-
<param name="offset">1</param>
1681-
<command_interface name="position"/>
1682-
<state_interface name="position"/>
1683-
<state_interface name="velocity"/>
1684-
</joint>
1685-
</ros2_control>
1686-
)";
1687-
1688-
const auto gripper_hardware_resources_mimic_deprecated_unknown_joint =
1689-
R"(
1690-
<ros2_control name="TestGripper" type="system">
1691-
<joint name="right_finger_joint">
1692-
<command_interface name="effort"/>
1693-
<state_interface name="position"/>
1694-
<state_interface name="velocity"/>
1695-
<state_interface name="effort"/>
1696-
</joint>
1697-
<joint name="left_finger_joint">
1698-
<param name="mimic">middle_finger_joint</param>
1699-
<param name="multiplier">1</param>
1700-
<command_interface name="position"/>
1701-
<state_interface name="position"/>
1702-
<state_interface name="velocity"/>
1703-
</joint>
1704-
</ros2_control>
1705-
)";
1706-
// end delete deprecated config test
1707-
17081667
const auto gripper_hardware_resources_mimic_true_command_if =
17091668
R"(
17101669
<ros2_control name="TestGripper" type="system">

0 commit comments

Comments
 (0)