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 SubModelKinDynWrapper class #605

Merged
merged 2 commits into from
Feb 28, 2023

Conversation

isorrentino
Copy link
Collaborator

Adding the SubModelKinDynWrapper class. It handles the KinDynComputation object of a sub-model and keeps updated the dynamics and kinematics information.

This PR is blocked by #604.

@S-Dafarra
Copy link
Member

Please, ping me again after #604 is merged and this is ready to be reviewed. Now I can see both PRs code and it is confusing 😊

@isorrentino isorrentino force-pushed the feature/kinDynSubModel branch from a56a473 to ef6fc89 Compare February 13, 2023 13:56
@isorrentino isorrentino marked this pull request as draft February 14, 2023 08:43
@isorrentino isorrentino force-pushed the feature/kinDynSubModel branch 5 times, most recently from c19baa4 to 47c6b65 Compare February 20, 2023 15:02
@isorrentino isorrentino marked this pull request as ready for review February 20, 2023 15:09
@isorrentino
Copy link
Collaborator Author

Hi @S-Dafarra @GiulioRomualdi, the PR (#604) blocking this one has been merged. It is ready for review.

Comment on lines 167 to 190
Eigen::VectorXd motorTorques(numberOfJoints);
Eigen::VectorXd frictionTorques(numberOfJoints);
Eigen::VectorXd contactTorques(numberOfJoints);

Eigen::VectorXd baseAcceleration(6);
REQUIRE(kinDynSubModel.getBaseAcceleration(kinDyn,
robotBaseAcceleration,
robotJointAcceleration,
baseAcceleration));

Eigen::VectorXd baseVelocity(6);
baseVelocity = kinDynSubModel.getBaseVelocity(kinDyn);

Eigen::VectorXd jointAcceleration(numberOfJoints);

for (int i = 0; i < numberOfJoints; i++)
{
motorTorques(i) = random_double();
frictionTorques(i) = random_double();
contactTorques(i) = random_double();
}

REQUIRE(kinDynSubModel.inverseDynamics(motorTorques,
frictionTorques,
contactTorques,
baseAcceleration,
jointAcceleration));
Copy link
Member

Choose a reason for hiding this comment

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

Does it make sense to run these tests with meaningful inputs to check if the output makes sense?

@GiulioRomualdi
Copy link
Member

Tomorrow I will do a better review, but I noticed that you are using idyntree matrices and vectors in the interface can you use eigen or manif?

@isorrentino
Copy link
Collaborator Author

@GiulioRomualdi @S-Dafarra I changed the code after your reviews. It's ready to be checked again. Thanks.

Copy link
Member

@S-Dafarra S-Dafarra left a comment

Choose a reason for hiding this comment

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

I just noticed a couple of other dynamic memory allocations. Apologies for not noticing it before.

@isorrentino isorrentino force-pushed the feature/kinDynSubModel branch 2 times, most recently from 1502d99 to 32cfd8c Compare February 21, 2023 13:59
Copy link
Member

@S-Dafarra S-Dafarra left a comment

Choose a reason for hiding this comment

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

Minor comment

@isorrentino isorrentino force-pushed the feature/kinDynSubModel branch from 32cfd8c to a88121d Compare February 21, 2023 19:53
Copy link
Member

@GiulioRomualdi GiulioRomualdi left a comment

Choose a reason for hiding this comment

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

In general, you may avoid using iDynTree::Vector and Matrices since all the KinDynComputations get and set methods take as input iDynTree::Span and iDynTree::MatrixView

Comment on lines 117 to 132
for (int idx = 0; idx < m_subModel.getJointMapping().size(); idx++)
{
m_qj.setVal(idx, m_jointPositionModel[m_subModel.getJointMapping()[idx]]);
m_dqj.setVal(idx, m_jointVelocityModel[m_subModel.getJointMapping()[idx]]);
}

if (!m_kinDyn.setRobotState(m_worldTBase, m_qj, m_baseVelocityiDyn, m_dqj, m_worldGravity))
{
blf::log()->error("{} Unable to set the robot state.", logPrefix);
return false;
}
Copy link
Member

Choose a reason for hiding this comment

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

You can use directly eigen vectors here

Comment on lines 113 to 117
bool inverseDynamics(Eigen::VectorXd& motorTorqueAfterGearbox,
Eigen::VectorXd& frictionTorques,
Eigen::VectorXd& tauExt,
Eigen::VectorXd& baseAcceleration,
Eigen::VectorXd& jointAcceleration);
Copy link
Member

Choose a reason for hiding this comment

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

you can use the eigen ref

Comment on lines 128 to 129
const Eigen::VectorXd& robotBaseAcceleration,
const Eigen::VectorXd& robotJointAcceleration,
Copy link
Member

Choose a reason for hiding this comment

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

as above

* @param kinDynFullModel is the KinDynComputation object associated to a model.
* @return baseVelocity the the base velocity of the sub-model.
*/
Eigen::Ref<Eigen::VectorXd> getBaseVelocity(std::shared_ptr<iDynTree::KinDynComputations> kinDynFullModel);
Copy link
Member

Choose a reason for hiding this comment

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

This gives the user the possibility to change the base velocity is this wanted?

Suggested change
Eigen::Ref<Eigen::VectorXd> getBaseVelocity(std::shared_ptr<iDynTree::KinDynComputations> kinDynFullModel);
Eigen::Ref<const Eigen::VectorXd> getBaseVelocity(std::shared_ptr<iDynTree::KinDynComputations> kinDynFullModel) const;

Copy link
Member

Choose a reason for hiding this comment

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

Actually this should be a manif::SE3d::Tangent object

Comment on lines 8 to 9
#ifndef BIPEDAL_LOCOMOTION_ESTIMATORS_SUBMODELKINDYNWRAPPER_H
#define BIPEDAL_LOCOMOTION_ESTIMATORS_SUBMODELKINDYNWRAPPER_H
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
#ifndef BIPEDAL_LOCOMOTION_ESTIMATORS_SUBMODELKINDYNWRAPPER_H
#define BIPEDAL_LOCOMOTION_ESTIMATORS_SUBMODELKINDYNWRAPPER_H
#ifndef BIPEDAL_LOCOMOTION_ESTIMATORS_SUB_MODEL_KINDYN_WRAPPER_H
#define BIPEDAL_LOCOMOTION_ESTIMATORS_SUB_MODEL_KINDYN_WRAPPER_H

std::map<const std::string, Eigen::VectorXd> m_dJnuList; /**< Accelerometer bias accelerations */
std::map<const std::string, Eigen::Matrix3d> m_accRworldList; /**< Rotation matrix of the
accelerometer frame wrt world */
Eigen::VectorXd m_baseVelocity; /**< Velocity of the base of the sub-model */
Copy link
Member

Choose a reason for hiding this comment

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

We use manif::SE3Tangentd for the velocity

std::map<const std::string, Eigen::MatrixXd> m_jacContactList; /**< Jacobians of the external
contacts */
std::map<const std::string, Eigen::VectorXd> m_dJnuList; /**< Accelerometer bias accelerations */
std::map<const std::string, Eigen::Matrix3d> m_accRworldList; /**< Rotation matrix of the
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
std::map<const std::string, Eigen::Matrix3d> m_accRworldList; /**< Rotation matrix of the
std::map<const std::string, manif::SO3d> m_accRworldList; /**< Rotation matrix of the

Comment on lines 137 to 142
if (!m_kinDyn.getFreeFloatingMassMatrix(m_idynMassMatrix))
{
blf::log()->error("{} Unable to get the mass matrix of the sub-model.", logPrefix);
return false;
}
m_massMatrix = iDynTree::toEigen(m_idynMassMatrix);
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 (!m_kinDyn.getFreeFloatingMassMatrix(m_idynMassMatrix))
{
blf::log()->error("{} Unable to get the mass matrix of the sub-model.", logPrefix);
return false;
}
m_massMatrix = iDynTree::toEigen(m_idynMassMatrix);
if (!m_kinDyn.getFreeFloatingMassMatrix(m_massMatrix))
{
blf::log()->error("{} Unable to get the mass matrix of the sub-model.", logPrefix);
return false;
}

m_FTBaseAcc.resize(m_numOfJoints);
m_totalTorques.resize(m_numOfJoints);

m_idynMassMatrix = iDynTree::FreeFloatingMassMatrix(m_subModel.getModel());
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
m_idynMassMatrix = iDynTree::FreeFloatingMassMatrix(m_subModel.getModel());

iDynTree::VectorDynSize m_qj;
iDynTree::VectorDynSize m_dqj;

iDynTree::FreeFloatingMassMatrix m_idynMassMatrix;
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::FreeFloatingMassMatrix m_idynMassMatrix;

@isorrentino isorrentino force-pushed the feature/kinDynSubModel branch 2 times, most recently from a9f94be to 1f2067f Compare February 26, 2023 07:04
@isorrentino
Copy link
Collaborator Author

isorrentino commented Feb 26, 2023

@GiulioRomualdi I changed the code following your suggestions. I hope I got how to change it.

@isorrentino isorrentino force-pushed the feature/kinDynSubModel branch 2 times, most recently from 1eb1edb to 6861db0 Compare February 26, 2023 08:41
@GiulioRomualdi GiulioRomualdi merged commit 741c6b9 into ami-iit:master Feb 28, 2023
@isorrentino isorrentino deleted the feature/kinDynSubModel branch March 31, 2023 08:42
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.

3 participants