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

Extend Support for Mimic Joint #2441

Open
wants to merge 188 commits into
base: devel
Choose a base branch
from
Open

Conversation

MegMll
Copy link
Collaborator

@MegMll MegMll commented Sep 30, 2024

Overview

This PR enhances support for the mimic joint.
Mimic joint refer to a joint which configuration depends on the configuration of another joint (that we named the primary joint). The relation is $q_{mimic} = \alpha * q_{primary} + \beta$ (where $\alpha, \beta$ are defined by the user)

Key Updates:

URDF Parsing:

The mimic tag can now be parsed from urdf, and add the corresponding mimic joint to the model.
A mimic flag has been added to the parser to enable this feature or not (default to false) in order to preserve backward compatibility.

Robot and Joint Model Modifications:

  • The already existing mimic joint type has been update to allow support in more algorithms.
    • The main change being that instead of being templated on the primary joint type, the mimic joint now holds a variant of joint for the primary.
  • The robot and joint nq and nv (resp. idx_q, idx_v) values have now been extended with a nvExtended (resp idx_vExtended) value, holding the dimension of the extended robot/joint tangeant space. (for all classical joint nv==nvExtened but for mimic nv==0 and nvExtended==primary.nvExtended). The suffix vExtended stand for Jacobian as those values are mainly used for computing jacobians rows and columns.

Features of the joint mimic:

Joint

Not all the joints are able to be mimicked. Please see the following list for the joints that can be mimicked:
- Prismatics
- Revolutes
- Helicoidals
Please also note that the mimic joint must be after its primary (i.e. id_mimicking > id_mimicked) in the kinematic tree for it to be created in pinocchio. If that's not the case, the model will not be created.

Algorithms

The following algorithms support the new joint mimic :
- RNEA
- CRBA
- Forward Kinematics
- Jacobians and Frames
- Centroidal Algorithm

Testing & Validation:

  • Added unit tests to validate mimic joint support for all the above algorithms.
  • Verified URDF parsing for different robot models that include mimic joints.

Limitations:

  • Algorithms such as ABA, or any derivatives are not supported and should trigger asserts.
  • Currently, the mimic joint should always be after the primary joint (i.e. id_mimicking > id_mimicked) in the kinematic tree. (assert is triggered if not)

Feedback Needed:

The naming of the new member variable and functions is pretty arbitrary, we are eager to change them to better suit pinocchio naming standards.
Non exhaustively, here are a list of the lesser quality one (that should most probably be renamed) :

  • idx_j/nj : representing the dimension and index in the "extended model"
  • jointCols, jointRows, etc method has been split into jointVelCols and jointJacCols (respectively if they refer to idx_v/nv or idx_j/nj)
  • Similarly jointConfigSelector was splitted into jointConfigFromDofSelector and jointConfigFromNqSelector to meet the need for mimic joint to select config either from the parent joint or don't select anything
  • Similarly jointVelocitySelector was splitted into jointVelocityFromDofSelector and jointConfigFromNqSelector to meet the need for mimic joint to select config either from the parent joint or don't select anything

Special Thanks:

A special thank you to @EtienneAr for his guidance and advice throughout this development process.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

👋 Hi,
This is a reminder message to assign an extra build label to this Pull Request if needed.
By default, this PR will be build with minimal build options (URDF support and Python bindings)
The possible extra labels are:

  • build_collision (build Pinocchio with coal support)
  • build_casadi (build Pinocchio with CasADi support)
  • build_autodiff (build Pinocchio with CppAD support)
  • build_codegen (build Pinocchio with CppADCodeGen support)
  • build_extra (build Pinocchio with extra algorithms)
  • build_mpfr (build Pinocchio with Boost.Multiprecision support)
  • build_sdf (build Pinocchio with SDF parser)
  • build_accelerate (build Pinocchio with APPLE Accelerate framework support)
  • build_all (build Pinocchio with ALL the options stated above)

Thanks.
The Pinocchio development team.

Copy link
Contributor

@jcarpent jcarpent left a comment

Choose a reason for hiding this comment

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

I will provide a detailed review later.

@abussy-aldebaran
Copy link
Contributor

Hi,

I started using mimic joints, so I'm following this PR with interest !
I tested this branch with forward and inverse kinematics (with pseudo-inverses of the Jacobians), and it seems to work fine 👍

How/Where can I report any bug I find ?
I'll try to add MREs as unittests. For instance, I found : abussy-aldebaran@5a8f205

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe you could add typedef for mimic joints ?

typedef JointModelMimicTpl<Scalar, Options, JointCollectionTpl> JointModelMimic;
typedef JointDataMimicTpl<Scalar, Options, JointCollectionTpl> JointDataMimic;

res.setIndexes(id(), idx_q(), idx_v());
m_jmodel_ref.template cast<NewScalar>(), ScalarCast<NewScalar, Scalar>::cast(m_scaling),
ScalarCast<NewScalar, Scalar>::cast(m_offset));
res.setIndexes(id(), idx_q(), idx_v(), idx_j());
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't a setMimicIndices missing ?
See abussy-aldebaran@5a8f205
and abussy-aldebaran@afef317

@MegMll MegMll force-pushed the topic/mimic branch 2 times, most recently from bd466b3 to b90f6e0 Compare December 16, 2024 10:39
@MegMll
Copy link
Collaborator Author

MegMll commented Dec 16, 2024

Hi,

I started using mimic joints, so I'm following this PR with interest ! I tested this branch with forward and inverse kinematics (with pseudo-inverses of the Jacobians), and it seems to work fine 👍

How/Where can I report any bug I find ? I'll try to add MREs as unittests. For instance, I found : abussy-aldebaran@5a8f205

Hi,

Thanks a lot for your interest in this PR, ! In order to simplify the PR and the review process, if you want to add new unittests, please do it directly on this branch.

If you don't feel confortable with this solution, we'll find another way.

As for bugs, please add comments here, and we'll take a look at it.

Thanks again !

@abussy-aldebaran
Copy link
Contributor

In order to simplify the PR and the review process, if you want to add new unittests, please do it directly on this branch.

What do you mean ? Opening a PR in your forked repository ?

@MegMll MegMll force-pushed the topic/mimic branch 2 times, most recently from ea956c8 to 083d240 Compare January 10, 2025 10:04
Comment on lines 48 to 50
geom_data.oMg[i] =
(static_cast<GeometryModel::SE3>(data.oMi[joint_id])
* geom_model.geometryObjects[i].placement);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the static_cast mandatory ? This code build without it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Did you try with CppAd ? I removed all the other cast, and ci with cppAd, does not work

}

for (JointIndex j = 1; int(j) < model.njoints; ++j)
{
if (boost::get<JointModelMimicTpl<Scalar, Options, JointCollectionTpl>>(&model.joints[j]))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why you don't check this joint ?
Add a comment to explains or use the if to jump/change invalid check for mimic.

ColsBlock Ag_cols = jmodel.jointCols(data.Ag);
motionSet::inertiaAction(data.oYcrb[i], J_cols, Ag_cols);
ColsBlock Ag_cols = jmodel.jointVelCols(data.Ag);
motionSet::inertiaAction<ADDTO>(data.oYcrb[i], J_cols, Ag_cols);
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you fix a bug in this pass ?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, the default behavior is not changed

Before this backward pass, Ag is set to zero (line 177 of this file).
The columns of the DoF that does not involve any mimicking, are selected only once in this pass and thus "added to" only once. So for those Dof, the ADDTO act the same as a SETTO.

(But for the mimic DoF this allows for summing the results)

Comment on lines 106 to 109
assert(
(std::is_same<JointModel, JointModelMimicTpl<Scalar, Options, JointCollectionTpl>>::value
== false)
&& "Algorithm not supported for mimic joints");
Copy link
Contributor

Choose a reason for hiding this comment

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

This assert is nice, but how to warn the user in Python binding ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

All the asserts were changed to PINOCCHIO_THROW, so that it works in release mode (and in python)

J_cols.transpose() * data.dFda.middleCols(jmodel.idx_v(), data.nvSubtree[i]);
data.oYcrb[parent] += data.oYcrb[i];

if (ContactMode)
{
jmodel.jointVelocitySelector(data.nle).noalias() =
jmodel.jointVelocityFromNvSelector(data.nle).noalias() =
Copy link
Contributor

Choose a reason for hiding this comment

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

Did we support constrained dynamics ?

include/pinocchio/algorithm/crba.hxx Outdated Show resolved Hide resolved
assert(secondary_id > primary_id && "Mimicking joint id is before the primary.");

size_t ancestor_prim, ancestor_sec;
findCommonAncestor(model, primary_id, secondary_id, ancestor_prim, ancestor_sec);
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of computing this data at each call, it's maybe possible to store it in JointDataMimicTpl.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with you that computing every time seems like a waste, but I am not sure that it is worth storing it.

When JointDataMimicTpl is instantiated, it doesn't have any available information regarding the kinematic structure of the whole model. (The JointModelMimicTpl does not contain this information either)

include/pinocchio/algorithm/crba.hxx Outdated Show resolved Hide resolved
include/pinocchio/algorithm/crba.hxx Outdated Show resolved Hide resolved
include/pinocchio/algorithm/crba.hxx Outdated Show resolved Hide resolved
@EtienneAr
Copy link
Contributor

EtienneAr commented Jan 23, 2025

Following our IRL meeting, here is the todo list:

  • Refactor the translateJacobian to prevent performance drop (due to nested for loops and visitor call increase)
  • Make sure the API (C++ & Python) is not broken by this PR (i.e. check that the non-mimic test did not change)
  • Add a check "model has mimic" in robot model to factorize code, and use that check in algorithms
  • Double check the necessity of the SE3 static_cast
  • Add specific check for mimic in check.hxx (instead of just skipping with an if).
  • Revert all changes in unsupported algo
  • Rename nj, idx_j -> nv_extended, idx_v_extended
  • Make sure that jcalc is easily upgradable for non linear mimic (withoput API break)
  • Edit this PR to list more limitations of this feature: Which joints type are mimickable, what are the contraints on the joint ids, ...

The following point are Nice To Have and should be addressed in separate issues / PRs:

  • Function to go from "Reduced" mimic model to full "extended" model
  • Store extra data in robot model/data to speed up so algo
  • Make proper safe/unsafe function for every algo to check (or not) input parameters, for performance issues and to be able to check for python bindings
  • Function that give the constraint matrix from a "Reduced" mimic model

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants