Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add export to urdf of joint dynamics: damping and static friction coefficients #1094

Merged
merged 14 commits into from
Sep 1, 2023

Conversation

mfussi66
Copy link
Member

@mfussi66 mfussi66 commented Aug 30, 2023

This PR aims to expand the Joints objects (Fixed, Revolute, Prismatic, IJoint) to support dynamic parameters present in URDF models.
These parameters are damping coefficient (N*s/m for prismatic and N*m*s/rad for revolute) and static friction coefficient (N for prismatic and N*m for revolute) .
The parameters can be imported from a urdf file or exported into one.

cc @traversaro @Nicogene

@traversaro
Copy link
Member

Thanks a lot for this work! I want to comment a bit in depth in the PR, but before of that, it seems that there are a few memory-related error catched by the valgrind tests:

2023-08-30T14:20:08.1447826Z Model loaded from /__w/idyntree/idyntree/src/tests/data/iCubGenova02.urdf
2023-08-30T14:20:08.1448051Z ==19584== Conditional jump or move depends on uninitialised value(s)
2023-08-30T14:20:08.1448791Z ==19584==    at 0x487273D: iDynTree::exportJoint(iDynTree::IJoint const*, iDynTree::Link const*, iDynTree::Link const*, iDynTree::Model const&, _xmlNode*) (in /__w/idyntree/idyntree/build/lib/libidyntree-modelio.so)
2023-08-30T14:20:08.1449626Z ==19584==    by 0x48744DB: iDynTree::URDFStringFromModel(iDynTree::Model const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, iDynTree::ModelExporterOptions) (in /__w/idyntree/idyntree/build/lib/libidyntree-modelio.so)
2023-08-30T14:20:08.1450534Z ==19584==    by 0x486E0A0: iDynTree::ModelExporter::exportModelToString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) (in /__w/idyntree/idyntree/build/lib/libidyntree-modelio.so)
2023-08-30T14:20:08.1450972Z ==19584==    by 0x10ED75: checkImportExportURDF(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) (in /__w/idyntree/idyntree/build/bin/ModelExporterUnitTest)
2023-08-30T14:20:08.1451213Z ==19584==    by 0x10D586: main (in /__w/idyntree/idyntree/build/bin/ModelExporterUnitTest)
2023-08-30T14:20:08.1451308Z ==19584== 
2023-08-30T14:20:08.1451521Z ==19584== Conditional jump or move depends on uninitialised value(s)
2023-08-30T14:20:08.1452209Z ==19584==    at 0x4872765: iDynTree::exportJoint(iDynTree::IJoint const*, iDynTree::Link const*, iDynTree::Link const*, iDynTree::Model const&, _xmlNode*) (in /__w/idyntree/idyntree/build/lib/libidyntree-modelio.so)
2023-08-30T14:20:08.1453029Z ==19584==    by 0x48744DB: iDynTree::URDFStringFromModel(iDynTree::Model const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, iDynTree::ModelExporterOptions) (in /__w/idyntree/idyntree/build/lib/libidyntree-modelio.so)
2023-08-30T14:20:08.1454068Z ==19584==    by 0x486E0A0: iDynTree::ModelExporter::exportModelToString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) (in /__w/idyntree/idyntree/build/lib/libidyntree-modelio.so)
2023-08-30T14:20:08.1454490Z ==19584==    by 0x10ED75: checkImportExportURDF(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) (in /__w/idyntree/idyntree/build/bin/ModelExporterUnitTest)
2023-08-30T14:20:08.1454731Z ==19584==    by 0x10D586: main (in /__w/idyntree/idyntree/build/bin/ModelExporterUnitTest)
2023-08-30T14:20:08.1454824Z ==19584== 
2023-08-30T14:20:08.1455040Z ==19584== Conditional jump or move depends on uninitialised value(s)
2023-08-30T14:20:08.1455475Z ==19584==    at 0x488DFCD: idyntree_private_fpconv_dtoa (in /__w/idyntree/idyntree/build/lib/libidyntree-modelio.so)
2023-08-30T14:20:08.1456267Z ==19584==    by 0x487277A: iDynTree::exportJoint(iDynTree::IJoint const*, iDynTree::Link const*, iDynTree::Link const*, iDynTree::Model const&, _xmlNode*) (in /__w/idyntree/idyntree/build/lib/libidyntree-modelio.so)
2023-08-30T14:20:08.1457096Z ==19584==    by 0x48744DB: iDynTree::URDFStringFromModel(iDynTree::Model const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, iDynTree::ModelExporterOptions) (in /__w/idyntree/idyntree/build/lib/libidyntree-modelio.so)
2023-08-30T14:20:08.1458097Z ==19584==    by 0x486E0A0: iDynTree::ModelExporter::exportModelToString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) (in /__w/idyntree/idyntree/build/lib/libidyntree-modelio.so)
2023-08-30T14:20:08.1458639Z ==19584==    by 0x10ED75: checkImportExportURDF(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) (in /__w/idyntree/idyntree/build/bin/ModelExporterUnitTest)
2023-08-30T14:20:08.1458886Z ==19584==    by 0x10D586: main (in /__w/idyntree/idyntree/build/bin/ModelExporterUnitTest)
2023-08-30T14:20:08.1458988Z ==19584== 
2023-08-30T14:20:08.1459204Z ==19584== Conditional jump or move depends on uninitialised value(s)
2023-08-30T14:20:08.1459647Z ==19584==    at 0x488DFEE: idyntree_private_fpconv_dtoa (in /__w/idyntree/idyntree/build/lib/libidyntree-modelio.so)
2023-08-30T14:20:08.1460339Z ==19584==    by 0x487277A: iDynTree::exportJoint(iDynTree::IJoint const*, iDynTree::Link const*, iDynTree::Link const*, iDynTree::Model const&, _xmlNode*) (in /__w/idyntree/idyntree/build/lib/libidyntree-modelio.so)
2023-08-30T14:20:08.1461178Z ==19584==    by 0x48744DB: iDynTree::URDFStringFromModel(iDynTree::Model const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, iDynTree::ModelExporterOptions) (in /__w/idyntree/idyntree/build/lib/libidyntree-modelio.so)
2023-08-30T14:20:08.1462086Z ==19584==    by 0x486E0A0: iDynTree::ModelExporter::exportModelToString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) (in /__w/idyntree/idyntree/build/lib/libidyntree-modelio.so)
2023-08-30T14:20:08.1462512Z ==19584==    by 0x10ED75: checkImportExportURDF(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) (in /__w/idyntree/idyntree/build/bin/ModelExporterUnitTest)
2023-08-30T14:20:08.1462755Z ==19584==    by 0x10D586: main (in /__w/idyntree/idyntree/build/bin/ModelExporterUnitTest)

Can you check them? To get more informative errors, you can compile locally in Debug model and so you will get the line numbers related to this.

@@ -59,7 +59,13 @@ class iDynTree::JointElement : public iDynTree::XMLElement {
double velocity;
};

struct DyamicParams {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
struct DyamicParams {
struct JointDynamicParams {

Two changes:

  • Fix typo
  • Be more precise on which type of "Dynamics" is, as iDynTree is a "dynamics" library "dynamics" is quite an overloaded term.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the name!

@traversaro
Copy link
Member

@mfussi66 sorry, I broke your branch with the commit mfussi66@8dfc3f9, but for some reason I couldn't easy create a PR out of it. However, it implements (in the interface) what we discuss, if you could modify the rest of the PR to be aligned it would be great, thanks!

@traversaro
Copy link
Member

This is still not ready for review, but probably @francesco-romano may be interested in this.

info.joint->setStaticFriction(0, m_dynamic_params->staticFriction);
} else if (m_jointType == "revolute" || m_jointType == "prismatic") {
std::string errStr = "Joint " + m_jointName + " misses the dynamics tag.";
reportWarning("JointElement", "", errStr.c_str());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dynamics element is optional in the URDF spec (see http://wiki.ros.org/urdf/XML/joint#Elements), so I guess we should not print a warning if it is not present in the URDF?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I removed the warning.

@@ -405,7 +405,19 @@ bool exportJoint(IJointConstPtr joint, LinkConstPtr parentLink, LinkConstPtr chi
xmlNewProp(limit_xml, BAD_CAST "velocity", BAD_CAST bufStr.c_str());
}

// TODO(traversaro) : handle friction
if (joint->getJointDynamicsType() != NoJointDynamics && joint->getNrOfDOFs() == 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (joint->getJointDynamicsType() != NoJointDynamics && joint->getNrOfDOFs() == 1)
if (joint->getJointDynamicsType() == URDFJointDynamics && joint->getNrOfDOFs() == 1)

(Just to be safe in case a new joint dynamics type that does not use damping or static friction is added).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

@@ -59,14 +61,14 @@ class iDynTree::JointElement : public iDynTree::XMLElement {
double velocity;
};

struct DyamicParams {
uint8_t jointDynamicsType;
struct JointDyamicsParams {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
struct JointDyamicsParams {
struct JointDynamicsParams {

@mfussi66
Copy link
Member Author

mfussi66 commented Sep 1, 2023

Seems like there are errors related to fortran libraries:

Matlab tests:

{�Error using iDynTree.Position (line 10)
Invalid MEX-file '/home/runner/work/idyntree/idyntree/build/lib/iDynTreeMEX.mexa64': /usr/local/MATLAB/R2020b/bin/glnxa64/../../sys/os/glnxa64/libgfortran.so.5: version
`GFORTRAN_10' not found (required by /usr/share/miniconda3/envs/test/lib/./libspral.so)

Debian tests:

2023-08-31T15:04:08.5475268Z gmake[2]: *** No rule to make target '/usr/lib/gcc/x86_64-linux-gnu/12/libgfortran.so', needed by 'bin/iKinConsistencyTest'.  Stop.

Are they an issue for this PR?

@traversaro
Copy link
Member

Seems like there are errors related to fortran libraries:

Matlab tests:

{�Error using iDynTree.Position (line 10)
Invalid MEX-file '/home/runner/work/idyntree/idyntree/build/lib/iDynTreeMEX.mexa64': /usr/local/MATLAB/R2020b/bin/glnxa64/../../sys/os/glnxa64/libgfortran.so.5: version
`GFORTRAN_10' not found (required by /usr/share/miniconda3/envs/test/lib/./libspral.so)

Debian tests:

2023-08-31T15:04:08.5475268Z gmake[2]: *** No rule to make target '/usr/lib/gcc/x86_64-linux-gnu/12/libgfortran.so', needed by 'bin/iKinConsistencyTest'.  Stop.

Are they an issue for this PR?

No, please ignore, thanks.

@@ -221,6 +221,7 @@ void testFramesNotInTraversal() {

int main()
{
// IDYNTREE_TESTS_URDFS_NR
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// IDYNTREE_TESTS_URDFS_NR
// IDYNTREE_TESTS_URDFS_NR

leftover?

Co-authored-by: Silvio Traversaro <silvio@traversaro.it>
@traversaro
Copy link
Member

Thanks @mfussi66 !

@traversaro traversaro merged commit 3509d48 into robotology:devel Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants