@@ -838,98 +838,53 @@ std::vector<HardwareInfo> parse_control_resources_from_urdf(const std::string &
838
838
for (auto i = 0u ; i < hw_info.joints .size (); ++i)
839
839
{
840
840
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)
845
843
{
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" );
874
845
}
875
- else
846
+ if (!urdf_joint-> mimic && joint. is_mimic == MimicAttribute:: TRUE )
876
847
{
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 )
883
854
{
884
855
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." );
886
859
}
887
- if (urdf_joint-> mimic && joint. is_mimic != MimicAttribute:: FALSE )
860
+ auto find_joint = [&hw_info]( const std::string & name )
888
861
{
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 ())
890
866
{
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" );
895
868
}
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);
925
878
}
879
+
926
880
if (urdf_joint->type == urdf::Joint::FIXED)
927
881
{
928
882
throw std::runtime_error (
929
883
" Joint '" + joint.name +
930
884
" ' is of type 'fixed'. "
931
885
" Fixed joints do not make sense in ros2_control." );
932
886
}
887
+
933
888
joint_limits::JointLimits limits;
934
889
getJointLimits (urdf_joint, limits);
935
890
// Take the most restricted one. Also valid for continuous-joint type only
0 commit comments