-
Notifications
You must be signed in to change notification settings - Fork 412
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
base: devel
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
c43fad1
to
52358ed
Compare
There was a problem hiding this 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.
3f25772
to
5ea8402
Compare
Hi, I started using mimic joints, so I'm following this PR with interest ! How/Where can I report any bug I find ? |
There was a problem hiding this comment.
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;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why ? There is no joint typedef in model.hpp
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()); |
There was a problem hiding this comment.
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
bd466b3
to
b90f6e0
Compare
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 ! |
What do you mean ? Opening a PR in your forked repository ? |
ea956c8
to
083d240
Compare
@@ -149,6 +149,7 @@ namespace pinocchio | |||
PINOCCHIO_CHECK_ARGUMENT_SIZE(Jout.rows(), 6); | |||
|
|||
Matrix6xLikeOut & Jout_ = Jout.const_cast_derived(); | |||
Jout_.setZero(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why setZero
here ? It should be done in the part that will do a +=.
@@ -324,6 +324,10 @@ namespace pinocchio | |||
/// \brief End index of the Joint motion subspace | |||
std::vector<int> end_idx_v_fromRow; | |||
|
|||
/// \brief Extended model mapping of the joint rows (idx_v_extended_fromRow[idx_v_extended] = | |||
/// idx_v) | |||
std::vector<int> idx_v_extended_fromRow; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be named idx_v_fromRow.
|
||
v_out = v_in; | ||
v_out += v_in; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like for CRBA, the += can hurt performances. So it should be done in a dedicated for loop.
@@ -319,7 +325,7 @@ namespace pinocchio | |||
data.iMf[parent] = data.liMi[i] * data.iMf[i]; | |||
|
|||
Matrix6xLike & J_ = J.const_cast_derived(); | |||
jmodel.jointCols(J_) = data.iMf[i].actInv(jdata.S()); | |||
jmodel.jointCols(J_) += data.iMf[i].actInv(jdata.S()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, we should add a second step in computeJointJacobian
to avoid the +=.
@@ -83,6 +83,22 @@ namespace pinocchio | |||
return bp::make_tuple(ancestor_id, index_ancestor_in_support1, index_ancestor_in_support2); | |||
} | |||
|
|||
template<typename Scalar, int Options, template<typename, int> class JointCollectionTpl> | |||
ModelTpl<Scalar, Options, JointCollectionTpl> transformJointIntoMimic( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use the same pattern as findCommonAncestor_proxy, this avoid to specify the full signature in the definition.
bp::def( | ||
"transformJointIntoMimic", | ||
(Model(*)( | ||
const Model &, const JointIndex &, const JointIndex &, const double &, const double &))( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use transformJointIntoMimic_proxy to note specify the full signature
@@ -193,6 +193,32 @@ namespace pinocchio | |||
PINOCCHIO_EIGEN_CONST_CAST(Matrix6Type, I), update_I)); | |||
} | |||
|
|||
template<typename InputType, typename ReturnType> | |||
struct jointConfigExtendedModelSelectorVisitor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jointConfigExtendedModelSelectorVisitor => JointConfigExtendedModelSelectorVisitor
{ | ||
return buildModel(filename, rootJoint, "root_joint", model, verbose); | ||
return buildModel(filename, rootJoint, "root_joint", model, mimic, verbose); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return buildModel(filename, rootJoint, "root_joint", model, mimic, verbose); | |
return buildModel(filename, rootJoint, "root_joint", model, verbose, mimic); |
Be careful, this error is in a lot of place
// ar & make_nvp("base_class",base_object< pinocchio::JointModelBase<JointType> | ||
// >(joint)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this dead code.
@@ -83,6 +83,22 @@ namespace pinocchio | |||
return bp::make_tuple(ancestor_id, index_ancestor_in_support1, index_ancestor_in_support2); | |||
} | |||
|
|||
template<typename Scalar, int Options, template<typename, int> class JointCollectionTpl> | |||
ModelTpl<Scalar, Options, JointCollectionTpl> transformJointIntoMimic_proxy( | |||
const ModelTpl<Scalar, Options, JointCollectionTpl> & input_model, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can simplify (like findCommonAncestor) by using context::Model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
transform mimic cannot take context, because it's not cppad compatible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of some equality tests ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not have time to investigate, it just won't compile, and since it's in a file with the PINOCCHIO_SKIP_ALGORITHM define, i just thought it made sense to use double.
If we want it with casadi and autodiff, i can add it to the todo list
@@ -290,7 +291,7 @@ struct TestADOnJoints | |||
void operator()(const pinocchio::JointModelBase<JointModel_> &) const | |||
{ | |||
JointModel_ jmodel = init<JointModel_>::run(); | |||
jmodel.setIndexes(0, 0, 0); | |||
// jmodel.setIndexes(0, 0, 0, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove dead code
static void test(const pinocchio::JointModelMimic<JointModel_> & /*jmodel*/) | ||
template<typename Scalar, int Options, template<typename, int> class JointCollection> | ||
static void | ||
test(const pinocchio::JointModelMimicTpl<Scalar, Options, JointCollection> & /*jmodel*/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mimic joint are not working with casadi ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We did the same test as for joint composite
template<class JointModel> | ||
struct buildModel<JointModelMimic<JointModel>> | ||
{ | ||
typedef JointModelMimic<JointModel> JointModel_; | ||
// template<class JointModel> | ||
// struct buildModel<JointModelMimic<JointModel>> | ||
// { | ||
// typedef JointModelMimic<JointModel> JointModel_; | ||
|
||
static Model run(const JointModel_ & jmodel) | ||
{ | ||
Model model; | ||
model.addJoint(0, jmodel.jmodel(), SE3::Identity(), "joint"); | ||
model.addJoint(0, jmodel, SE3::Identity(), "joint_mimic"); | ||
// static Model run(const JointModel_ & jmodel) | ||
// { | ||
// Model model; | ||
// model.addJoint(0, jmodel.jmodel(), SE3::Identity(), "joint"); | ||
// model.addJoint(0, jmodel, SE3::Identity(), "joint_mimic"); | ||
|
||
return model; | ||
} | ||
}; | ||
// return model; | ||
// } | ||
// }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this code is not used anymore, delete it.
@@ -429,7 +440,7 @@ struct TestJointConstraint | |||
void operator()(const JointModelBase<JointModel> &) const | |||
{ | |||
JointModel jmodel = init<JointModel>::run(); | |||
jmodel.setIndexes(0, 0, 0); | |||
// jmodel.setIndexes(0, 0, 0, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No dead code.
unittest/kinematics.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can add a test with a mimic joint (like for crba, create the extended model and compare with the mimic one)
} | ||
|
||
BOOST_AUTO_TEST_CASE(build_model_sample_manipulator) | ||
{ | ||
pinocchio::Model model; | ||
pinocchio::buildModels::manipulator(model); | ||
pinocchio::buildModels::manipulator(model, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like for humanoid random, keep the test without mimic.
@@ -67,4 +100,71 @@ BOOST_AUTO_TEST_CASE(build_model_sample_humanoid) | |||
* direct geometry with respect to reference values. */ | |||
} | |||
|
|||
BOOST_AUTO_TEST_CASE(compare_mimic) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get the purpose of this test.
It test RNEA, CRBA, nonLinearEffect, forwardKinematics. But these test should already be done in the rnea, crba and kinematics test file.
Overview
This PR enhances support for the mimic joint.$q_{mimic} = \alpha * q_{primary} + \beta$ (where $\alpha, \beta$ are defined by the user)
Mimic joint refer to a joint which configuration depends on the configuration of another joint (that we named the primary joint). The relation is
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 tofalse
) in order to preserve backward compatibility.Robot and Joint Model Modifications:
nq
andnv
(resp.idx_q
,idx_v
) values have now been extended with anvExtended
(respidx_vExtended
) value, holding the dimension of the extended robot/joint tangeant space. (for all classical jointnv==nvExtened
but for mimicnv==0
andnvExtended==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 (ccrba)
- Reachable Workspace
Testing & Validation:
Limitations:
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 intojointVelCols
andjointJacCols
(respectively if they refer toidx_v
/nv
oridx_j
/nj
)SimilarlyjointConfigSelector
was splitted intojointConfigFromDofSelector
andjointConfigFromNqSelector
to meet the need for mimic joint to select config either from the parent joint or don't select anythingSimilarlyjointVelocitySelector
was splitted intojointVelocityFromDofSelector
andjointConfigFromNqSelector
to meet the need for mimic joint to select config either from the parent joint or don't select anythingNext
Non linear mimic support
We can add a functor to JointModelMimicTpl constructor argument. This functor will hold the functon to apply to the config and velocity vectors.
This can be added latter as:
The latter options is less effective.
In both case, this will avoid a call to a visitor, since the configVectorAffineTransform can be solved at the JointModelMimmicTpl construction.
Special Thanks:
A special thank you to @EtienneAr for his guidance and advice throughout this development process.
Current TODO list
Following our IRL meeting, here is the todo list:
...
The following point are Nice To Have and should be addressed in separate issues / PRs: