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

Mimic constraint feature #431

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5080bed
Skeletal code for SetMimicJointFeature
adityapande-1995 Sep 29, 2022
6584c4c
Added implementation, test to be written
adityapande-1995 Sep 29, 2022
0cf04bd
Skeletal test case
adityapande-1995 Sep 30, 2022
e862d37
Added world file
adityapande-1995 Sep 30, 2022
89baee9
Added basic test
adityapande-1995 Sep 30, 2022
845c076
Linter fix
adityapande-1995 Sep 30, 2022
ab64ba4
Fix tests
adityapande-1995 Oct 4, 2022
efe14ff
Delete unnecessary spaces
adityapande-1995 Oct 4, 2022
44848b7
Added test for prismatic joint
adityapande-1995 Oct 4, 2022
1bb3239
Prismatic world
adityapande-1995 Oct 4, 2022
5f53cb7
Added test for universal joint
adityapande-1995 Oct 6, 2022
4ce9d72
Merge branch 'gz-physics6' into aditya/mimic_constraint
adityapande-1995 Oct 11, 2022
1317a6d
Added tests between different joint types
adityapande-1995 Oct 11, 2022
943740c
Added reference to offset
adityapande-1995 Oct 11, 2022
87e8de3
Linter
adityapande-1995 Oct 12, 2022
4dd1b21
Added checks for DOFs and joint name
adityapande-1995 Oct 12, 2022
3e123fb
Merge branch 'gz-physics6' into aditya/mimic_constraint
adityapande-1995 Nov 15, 2022
4f19f38
Added a test to check vioaltion of consv of energy
adityapande-1995 Nov 16, 2022
e6b6b6e
Merge branch 'gz-physics6' into aditya/mimic_constraint
adityapande-1995 Nov 30, 2022
c845bfb
Merge branch 'gz-physics6' into aditya/mimic_constraint
adityapande-1995 Dec 12, 2022
1a3d345
Merge branch 'gz-physics6' into aditya/mimic_constraint
adityapande-1995 Dec 20, 2022
1fbeed2
Merge branch 'gz-physics6' into aditya/mimic_constraint
scpeters Apr 29, 2023
5d3ec50
Merge branch 'gz-physics6' into aditya/mimic_constraint
adityapande-1995 May 9, 2023
6a0294b
Change parent/child to leader/follower, added axis arg to SetMimicCon…
adityapande-1995 May 10, 2023
0b4f490
Changed mimicJoint to joint, minor typo correction
adityapande-1995 May 10, 2023
484abc4
Merge branch 'gz-physics6' into aditya/mimic_constraint
adityapande-1995 Jul 11, 2023
6878701
Fix spelling
scpeters Jul 12, 2023
d7f552f
SetJointMimicConstraint: add dof argument
scpeters Jul 12, 2023
a7e4513
Use const ref
scpeters Jul 13, 2023
df5fd98
Merge branch 'gz-physics6' into aditya/mimic_constraint
azeey Aug 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions dartsim/src/JointFeatures.cc
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,56 @@ Wrench3d JointFeatures::GetJointTransmittedWrenchInJointFrame(
wrenchOut.force = transmittedWrenchInJoint.tail<3>();
return wrenchOut;
}

/////////////////////////////////////////////////
void JointFeatures::SetJointMimicConstraint(
const Identity &_id,
const std::string _joint,
const std::string,
const double _multiplier,
const double _offset,
const double _reference)
{
auto joint = this->ReferenceInterface<JointInfo>(_id)->joint;
auto jointMimic = joint->getSkeleton()->getJoint(_joint);

// Take extra care that the value is valid. A nan can cause the DART
// constraint solver to fail, which will in turn either cause a crash or
// collisions to fail
if (std::isnan(_multiplier))
{
gzerr << "Invalid value found in multiplier [" << _multiplier
<< "] for joint [" << joint->getName()
<< "]. The command will be ignored\n";
return;
}
if (std::isnan(_offset))
{
gzerr << "Invalid value found in offset [" << _offset
<< "] for joint [" << joint->getName()
<< "]. The command will be ignored\n";
return;
}
// Check if the joint tries to mimic itself.
if (joint == jointMimic)
{
gzerr << "Leader and follower joints for the mimic constraint"
<< " should not be the same. The constraint will be ignored"
<< std::endl;
}
// Check for degrees of freedom.
if (joint->getNumDofs() != jointMimic->getNumDofs())
{
gzerr << "Mimic constraint pair of joints should have the same"
<< " degress of freedom. The constraint will be ignored"
<< std::endl;
}

joint->setActuatorType(dart::dynamics::Joint::MIMIC);
joint->setMimicJoint(jointMimic, _multiplier,
_offset - _multiplier * _reference);
}

}
}
}
13 changes: 12 additions & 1 deletion dartsim/src/JointFeatures.hh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ struct JointFeatureList : FeatureList<
SetJointPositionLimitsFeature,
SetJointVelocityLimitsFeature,
SetJointEffortLimitsFeature,
GetJointTransmittedWrench
GetJointTransmittedWrench,

SetMimicConstraintFeature
> { };

class JointFeatures :
Expand Down Expand Up @@ -203,6 +205,15 @@ class JointFeatures :
// ----- Transmitted wrench -----
public: Wrench3d GetJointTransmittedWrenchInJointFrame(
const Identity &_id) const override;

// ----- Mimic joint constraint -----
public: void SetJointMimicConstraint(
const Identity &_id,
const std::string _joint,
const std::string _axis,
const double _multiplier,
const double _offset,
const double _reference) override;
};

}
Expand Down
42 changes: 42 additions & 0 deletions include/gz/physics/Joint.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <gz/physics/FrameSemantics.hh>
#include <gz/physics/Geometry.hh>

#include <string>

namespace gz
{
namespace physics
Expand Down Expand Up @@ -584,6 +586,46 @@ namespace gz
};
};

/////////////////////////////////////////////////
/// \brief This feature sets the mimic constraint for this Joint.
class GZ_PHYSICS_VISIBLE SetMimicConstraintFeature
: public virtual Feature
{
/// \brief The Joint API for setting the mimic joint constraint.
/// \param[in] _joint
/// name of the joint to be mimicked, i.e. the leader joint.
/// \param[in] _multiplier
/// The multiplier to be applied to poistion of leader joint.
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
/// The multiplier to be applied to poistion of leader joint.
/// The multiplier to be applied to position of leader joint.

Copy link
Member

Choose a reason for hiding this comment

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

/// \param[in] _offset
/// The offset to be applied to position of leader joint after
/// the multiplier is applied.
public: template <typename PolicyT, typename FeaturesT>
class Joint : public virtual Feature::Joint<PolicyT, FeaturesT>
{
public: using Scalar = typename PolicyT::Scalar;

public: void SetMimicConstraint(
Copy link
Member

Choose a reason for hiding this comment

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

we should add a std::size_t _dof argument (similar to the GetBasicJointState APIs) to specify the follower joint axis

Copy link
Member

Choose a reason for hiding this comment

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

const std::string _joint,
const std::string _axis,
Copy link
Member

Choose a reason for hiding this comment

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

use const references for _joint and _axis

Copy link
Member

Choose a reason for hiding this comment

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

Scalar _multiplier,
Scalar _offset,
Scalar _reference);
};

/// \private The implementation API for setting the mimic constraint.
public: template <typename PolicyT>
class Implementation : public virtual Feature::Implementation<PolicyT>
{
public: using Scalar = typename PolicyT::Scalar;

// See Joint::MimicConstraint above
public: virtual void SetJointMimicConstraint(
const Identity &_id,
const std::string _joint,
const std::string _axis,
Scalar _multiplier, Scalar _offset, Scalar _reference) = 0;
};
};
}
}

Expand Down
15 changes: 15 additions & 0 deletions include/gz/physics/detail/Joint.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <gz/physics/Joint.hh>
#include "gz/physics/detail/FrameSemantics.hh"

#include <string>

namespace gz
{
namespace physics
Expand Down Expand Up @@ -214,6 +216,19 @@ namespace gz
->SetJointMaxEffort(this->identity, _dof, _value);
}

/////////////////////////////////////////////////
template <typename PolicyT, typename FeaturesT>
void SetMimicConstraintFeature::Joint<PolicyT, FeaturesT>::
SetMimicConstraint(
const std::string _joint,
const std::string _axis,
Scalar _multiplier, Scalar _offset, Scalar _reference)
{
this->template Interface<SetMimicConstraintFeature>()
->SetJointMimicConstraint(this->identity, _joint,
_axis, _multiplier, _offset, _reference);
}

/////////////////////////////////////////////////
template <typename PolicyT, typename FeaturesT>
void DetachJointFeature::Joint<PolicyT, FeaturesT>::Detach()
Expand Down
1 change: 1 addition & 0 deletions test/common_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set(tests
construct_empty_world
free_joint_features
joint_features
joint_mimic_features
joint_transmitted_wrench_features
kinematic_features
link_features
Expand Down
Loading