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

Implementation of Fixed Base Task Space Inverse Dynamics #251

Merged
merged 11 commits into from May 11, 2021

Conversation

isorrentino
Copy link
Collaborator

@isorrentino isorrentino commented Mar 26, 2021

This PR implements the TaskSpaceInverseDynamics interface described in #230 and the QPFixedBaseTSID class which is a concrete implementation of the TSID.

The PR is blocked by #242.

[UPDATE]
The PR is ready to be reviewed @GiulioRomualdi @S-Dafarra @prashanthr05 @traversaro

@S-Dafarra
Copy link
Member

I think you probably need a rebase

@isorrentino
Copy link
Collaborator Author

I'll do a rebase on the master branch after the merging of #242.

@S-Dafarra
Copy link
Member

I'll do a rebase on the master branch after the merging of #242.

I should have read better the first comment 😁

#define BIPEDAL_LOCOMOTION_QP_FIXED_BASE_TSID_H

#include <memory>

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
#include <optional>
#include <string>
#include <vector>
#include <Eigen/Dense>
#include <iDynTree/KinDynComputations.h>

This is the reason why the compilation fails in windows

Copy link
Member

Choose a reason for hiding this comment

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

#include <optional> was missing

Copy link
Collaborator

Choose a reason for hiding this comment

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

also #include <functional>


#include <memory>

#include <BipedalLocomotion/TSID/TaskSpaceInverseDynamics.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
#include <BipedalLocomotion/TSID/TaskSpaceInverseDynamics.h>
#include <BipedalLocomotion/ParametersHandler/IParametersHandler.h>
#include <BipedalLocomotion/TSID/TaskSpaceInverseDynamics.h>

Remember to include what you use 😸

@GiulioRomualdi GiulioRomualdi added the enhancement New feature or request label Mar 31, 2021
Copy link
Collaborator

@prashanthr05 prashanthr05 left a comment

Choose a reason for hiding this comment

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

Initial comments

Comment on lines 23 to 30
/**
* State of the TaskSpaceInverseDynamics
*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

out-of-place documentation?

};
struct TSIDState
{
manif::SE3d::Tangent baseAcceleration; /**< Mixed spatial acceleration of the base */
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
manif::SE3d::Tangent baseAcceleration; /**< Mixed spatial acceleration of the base */
manif::SE3d::Tangent baseAcceleration; /**< Mixed acceleration of the base */

spatial is usually right trivialized.

@traversaro traversaro removed their request for review April 2, 2021 09:23
@traversaro
Copy link
Collaborator

Removing myself as I guess that @GiulioRomualdi and @prashanthr05 are enough.

Comment on lines 97 to 101
* Where the generalized robot acceleration is a vector containing the base spatialacceleration
(expressed in mixed representation) and the joint accelerations,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* Where the generalized robot acceleration is a vector containing the base spatialacceleration
(expressed in mixed representation) and the joint accelerations,
* Where the generalized robot acceleration is a vector containing the base acceleration
(expressed in mixed representation) and the joint accelerations,

src/TSID/src/QPFixedBaseTSID.cpp Outdated Show resolved Hide resolved
Comment on lines 33 to 35
std::unordered_map<std::string, TaskWithPriority> tasks;
std::vector<std::reference_wrapper<const TaskWithPriority>> constraints;
std::vector<std::reference_wrapper<TaskWithPriority>> costs;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you add a bit of a documentation here? Also why both constraints and costs have TaskWithPriority type? These are the tasks that are used to build the cost function.

src/TSID/src/QPFixedBaseTSID.cpp Show resolved Hide resolved
Comment on lines 151 to 154
bool QPFixedBaseTSID::addTask(std::shared_ptr<System::LinearTask> task,
const std::string& taskName,
std::size_t priority,
std::optional<Eigen::Ref<const Eigen::VectorXd>> weight)
Copy link
Collaborator

Choose a reason for hiding this comment

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

check for formatting, cc @GiulioRomualdi can advice on this.

src/TSID/src/QPFixedBaseTSID.cpp Outdated Show resolved Hide resolved
src/TSID/src/QPFixedBaseTSID.cpp Outdated Show resolved Hide resolved
src/TSID/src/QPFixedBaseTSID.cpp Outdated Show resolved Hide resolved
src/TSID/src/QPFixedBaseTSID.cpp Outdated Show resolved Hide resolved
Comment on lines +76 to +79
SE3ParameterHandler->setParameter("kp_linear", kp_se3task);
SE3ParameterHandler->setParameter("kd_linear", kd_se3task);
SE3ParameterHandler->setParameter("kp_angular", kp_se3task);
SE3ParameterHandler->setParameter("kd_angular", kd_se3task);
Copy link
Collaborator

Choose a reason for hiding this comment

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

how does the hard-coded 0s in createBaseTask() in FixedBaesQPTSID affect these settings?

@S-Dafarra
Copy link
Member

Removing myself as I guess that @GiulioRomualdi and @prashanthr05 are enough.

Same for me. Feel free to add me back if you want me to go through it.

Comment on lines 261 to 262
Eigen::Vector3d gravity;
gravity << 0, 0, -9.81;
Copy link
Member

Choose a reason for hiding this comment

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

I don't know if this is the reason why it's not converging but the gravity here is different from the one used in getDesiredReference

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I changed it in the version I'm using to understand the problem. The branch is testbranchTSID, the gravity there is set to [0 0 -9.81] also in getDesiredReference.

@GiulioRomualdi
Copy link
Member

GiulioRomualdi commented Apr 16, 2021

After a F2F discussion with @isorrentino we decided to split the PR in two:

  1. Is for the TSID interface
  2. for the QPFixedBase implementation

Thanks to this split I can start using the interface to implement the TSID for walking, in the meantime @isorrentino can still debug the code and better understand if there are bugs

I will open a PR for 1 by cherry-picking @isorrentino's commit.

@isorrentino isorrentino marked this pull request as ready for review May 11, 2021 08:42
@isorrentino
Copy link
Collaborator Author

I rebased the branch on master and I tested it on all the OS. Then, I tested the library with an application that uses the iCub model https://github.com/dic-iit/element_torque-control-via-current/issues/186, both in simulation and with the real robot.
The PR can be reviewed again @GiulioRomualdi @prashanthr05.

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.

Some minor comments

* The TSID is here implemented as Quadratic Programming (QP) problem. The user should
* set the desired task with the method QPFixedBaseTSID::addTask. Each task has a given
* priority. Currently we support only priority equal to 0 or 1. If the task priority is set to 0
* the task will be considered as hard task, thus treated as an equality constraint. If the priority
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 task will be considered as hard task, thus treated as an equality constraint. If the priority
* the task will be considered as a hard task, thus treated as a constraint. If the priority

Comment on lines 43 to 44
bool createBaseSE3Task();
bool createDynamicsTask();
Copy link
Member

Choose a reason for hiding this comment

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

This two methods should be defined in Impl

* |:------------------------------------:|:--------:|:--------------------------------------------------------------------------------------------------:|:---------:|
* | `robot_acceleration_variable_name` | `string` | Name of the variable contained in `VariablesHandler` describing the generalized robot acceleration | Yes |
* | `robot_torque_variable_name` | `string` | Name of the variable contained in `VariablesHandler` describing the robot torque | Yes |
* | `robot_contact_wrench_variable_name` | `string` | Name of the variable contained in `VariablesHandler` describing the robot contact wrench | Yes |
Copy link
Member

Choose a reason for hiding this comment

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

I would just pass the name of the link that should be considered in contact.
Notice that in your implementation you are assuming that the root link is in contact. If you do not want to add the possibility to have a fixed frame different from you should remove robot_contact_wrench_variable_name


if (!m_pimpl->isKinDynSet)
{
log()->error("{} The object kinDyn is not set for the base SE3Task.", logPrefix);
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
log()->error("{} The object kinDyn is not set for the base SE3Task.", logPrefix);
log()->error("{} The object kinDyn is not valid.", logPrefix);

Comment on lines 393 to 402
if (!createBaseSE3Task())
{
log()->error("{} Error creating se3task for the base.", logPrefix);
return false;
}
if (!createDynamicsTask())
{
log()->error("{} Error creating task for the joint dynamics.", 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.

Suggested change
if (!createBaseSE3Task())
{
log()->error("{} Error creating se3task for the base.", logPrefix);
return false;
}
if (!createDynamicsTask())
{
log()->error("{} Error creating task for the joint dynamics.", logPrefix);
return false;
}
if (!m_pimpl->createBaseSE3Task())
{
log()->error("{} Error creating SE3task for the base.", logPrefix);
return false;
}
if (!m_pimpl->createDynamicsTask())
{
log()->error("{} Error creating task for the joint dynamics.", logPrefix);
return false;
}

Comment on lines +601 to +604
m_pimpl->solution.jointTorques
= m_pimpl->solver.getSolution().segment(m_pimpl->robotAccelerationVariable.offset
+ m_pimpl->robotAccelerationVariable.size,
joints);
Copy link
Member

Choose a reason for hiding this comment

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

Solution contains also the robot acceleration. I think you should fill also that

Comment on lines 262 to 263
Eigen::Vector3d gravity;
gravity << 0, 0, -BipedalLocomotion::Math::StandardAccelerationOfGravitation;;
Copy link
Member

Choose a reason for hiding this comment

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

I think you can move this before for (std::size_t numberOfJoints = 15; numberOfJoints < 40; numberOfJoints += 15)

@@ -61,6 +61,64 @@ struct QPFixedBaseTSID::Impl
std::shared_ptr<SE3Task> baseSE3Task;
std::shared_ptr<JointDynamicsTask> dynamicsTask;

bool createBaseSE3Task() {
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
bool createBaseSE3Task() {
bool createBaseSE3Task()
{

return true;
}

bool createDynamicsTask(){
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
bool createDynamicsTask(){
bool createDynamicsTask()
{

@GiulioRomualdi
Copy link
Member

Let's wait for CI then I will merge

@GiulioRomualdi
Copy link
Member

Merging thank you @isorrentino for the effort

@GiulioRomualdi GiulioRomualdi merged commit 0c055db into ami-iit:master May 11, 2021
@isorrentino isorrentino deleted the QPFixedBaseTSID branch May 11, 2021 13:49
@prashanthr05
Copy link
Collaborator

Looks like I was a bit too late?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants