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
Merged
1 change: 1 addition & 0 deletions src/model/src/RevoluteJoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ RevoluteJoint::RevoluteJoint():
this->resetAxisBuffers();
this->resetBuffers(0);
this->disablePosLimits();
this->resetJointDynamics();
}

RevoluteJoint::RevoluteJoint(const LinkIndex _link1, const LinkIndex _link2,
Expand Down
8 changes: 5 additions & 3 deletions src/model_io/codecs/include/private/JointElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#include <iDynTree/XMLElement.h>

#include <iDynTree/Model/IJoint.h>

#include <iDynTree/Core/Axis.h>
#include <iDynTree/Core/Transform.h>

Expand Down Expand Up @@ -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 {

JointDynamicsType jointDynamicsType;
double damping;
double staticFriction;
};

std::shared_ptr<Limits> m_limits;
std::shared_ptr<DyamicParams> m_dynamic_params;
std::shared_ptr<JointDyamicsParams> m_dynamic_params;

public:
explicit JointElement(
Expand Down
39 changes: 20 additions & 19 deletions src/model_io/codecs/src/JointElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <iDynTree/XMLAttribute.h>
#include <iDynTree/XMLParser.h>

#include <iDynTree/Model/IJoint.h>
#include <iDynTree/Model/FixedJoint.h>
#include <iDynTree/Model/PrismaticJoint.h>
#include <iDynTree/Model/RevoluteJoint.h>
Expand Down Expand Up @@ -134,31 +133,33 @@ namespace iDynTree {
return std::shared_ptr<XMLElement>(element);

} else if (name == "dynamics") {
m_dynamic_params = std::make_shared<DyamicParams>();
m_dynamic_params = std::make_shared<JointDyamicsParams>();
m_dynamic_params->jointDynamicsType = URDFJointDynamics;
m_dynamic_params->damping = .0;
m_dynamic_params->staticFriction = .0;

// TODO: check how the defaults/required works
XMLElement* element = new XMLElement(getParserState(), name);
element->setAttributeCallback([this](const std::unordered_map<std::string, std::shared_ptr<XMLAttribute>>& attributes) {
auto found = attributes.find("damping");
if (found != attributes.end()) {
double value = 0;
if (stringToDoubleWithClassicLocale(found->second->value(), value)) {
m_dynamic_params->damping = value;
element->setAttributeCallback(
[this](const std::unordered_map<std::string, std::shared_ptr<XMLAttribute>>& attributes) {
auto found = attributes.find("damping");
if (found != attributes.end()) {
double value = 0;
if (stringToDoubleWithClassicLocale(found->second->value(), value)) {
m_dynamic_params->damping = value;
}
}
}
found = attributes.find("friction");
if (found != attributes.end()) {
double value = 0;
if (stringToDoubleWithClassicLocale(found->second->value(), value)) {
m_dynamic_params->staticFriction = value;
found = attributes.find("friction");
if (found != attributes.end()) {
double value = 0;
if (stringToDoubleWithClassicLocale(found->second->value(), value)) {
m_dynamic_params->staticFriction = value;
}
}
}
return true;
});
return std::shared_ptr<XMLElement>(element);
return true;
}
);
return std::shared_ptr<XMLElement>(element);
}
return std::make_shared<XMLElement>(getParserState(), name);
}
Expand Down Expand Up @@ -208,7 +209,7 @@ namespace iDynTree {
info.joint->setDamping(0, m_dynamic_params->damping);
info.joint->setStaticFriction(0, m_dynamic_params->staticFriction);
}

if (!map->insert(std::unordered_map<std::string, JointElement::JointInfo>::value_type(m_jointName, info)).second) {
std::string errStr = "Duplicate joint " + m_jointName + " found.";
reportError("JointElement", "", errStr.c_str());
Expand Down
1 change: 0 additions & 1 deletion src/model_io/codecs/src/URDFModelExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ bool exportJoint(IJointConstPtr joint, LinkConstPtr parentLink, LinkConstPtr chi

if (joint->getJointDynamicsType() == URDFJointDynamics && joint->getNrOfDOFs() == 1)
{

xmlNodePtr dynamics_xml = xmlNewChild(joint_xml, NULL, BAD_CAST "dynamics", NULL);
std::string bufStr;
double damping = 0.0, static_friction = 0.0;
Expand Down
1 change: 1 addition & 0 deletions src/model_io/codecs/tests/ModelExporterUnitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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?

for(unsigned int mdl = 0; mdl < IDYNTREE_TESTS_URDFS_NR; mdl++ )
{
if (std::string(IDYNTREE_TESTS_URDFS[mdl]) == "bigman.urdf")
Expand Down