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

Implement FeasibleContactWrenchTask for TSID component #369

Merged
merged 7 commits into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ All notable changes to this project are documented in this file.
- Implement `skew` function in Math component (https://github.com/dic-iit/bipedal-locomotion-framework/pull/352)
- Implement `QPTSID` class (https://github.com/dic-iit/bipedal-locomotion-framework/pull/366)
- Implement motor pwm, motor encoders, wbd joint torque estimates, pid reading in `YarpSensorBridge`(https://github.com/dic-iit/bipedal-locomotion-framework/pull/359).
- Implement FeasibleContactWrenchTask for TSID component (https://github.com/dic-iit/bipedal-locomotion-framework/pull/369).

### Changed
- Add common Python files to gitignore (https://github.com/dic-iit/bipedal-locomotion-framework/pull/338)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class ContactWrenchCone
* | `foot_limits_y` | `vector<double>` | y coordinate of the foot limits w.r.t the frame attached to the surface | Yes |
* @return true in case of success/false otherwise.
*/
bool initialize(std::weak_ptr<ParametersHandler::IParametersHandler> handler);
bool initialize(std::weak_ptr<const ParametersHandler::IParametersHandler> handler);

/**
* Get the matrix A.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class LinearizedFrictionCone
* | `static_friction_coefficient` | `double` | Static friction coefficient. |
* @return true in case of success/false otherwise.
*/
bool initialize(std::weak_ptr<ParametersHandler::IParametersHandler> handler);
bool initialize(std::weak_ptr<const ParametersHandler::IParametersHandler> handler);

/**
* Get the matrix A.
Expand Down
2 changes: 1 addition & 1 deletion src/Math/src/ContactWrenchCone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

using namespace BipedalLocomotion::Math;

bool ContactWrenchCone::initialize(std::weak_ptr<ParametersHandler::IParametersHandler> handler)
bool ContactWrenchCone::initialize(std::weak_ptr<const ParametersHandler::IParametersHandler> handler)
{
constexpr auto errorPrefix = "[ContactWrenchCone::initialize]";
constexpr int wrenchSize = Wrench<double>::SizeAtCompileTime;
Expand Down
2 changes: 1 addition & 1 deletion src/Math/src/LinearizedFrictionCone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

using namespace BipedalLocomotion::Math;

bool LinearizedFrictionCone::initialize(std::weak_ptr<ParametersHandler::IParametersHandler> handler)
bool LinearizedFrictionCone::initialize(std::weak_ptr<const ParametersHandler::IParametersHandler> handler)
{
constexpr auto errorPrefix = "[LinearizedFrictionCone::initialize]";

Expand Down
2 changes: 2 additions & 0 deletions src/TSID/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ if(FRAMEWORK_COMPILE_TSID)
PUBLIC_HEADERS ${H_PREFIX}/TSIDLinearTask.h ${H_PREFIX}/SO3Task.h ${H_PREFIX}/SE3Task.h ${H_PREFIX}/JointTrackingTask.h ${H_PREFIX}/CoMTask.h
${H_PREFIX}/BaseDynamicsTask.h ${H_PREFIX}/JointDynamicsTask.h
${H_PREFIX}/TaskSpaceInverseDynamics.h
${H_PREFIX}/FeasibleContactWrenchTask.h
${H_PREFIX}/QPFixedBaseTSID.h ${H_PREFIX}/QPTSID.h
SOURCES src/SO3Task.cpp src/SE3Task.cpp src/JointTrackingTask.cpp src/CoMTask.cpp
src/BaseDynamicsTask.cpp src/JointDynamicsTask.cpp
src/FeasibleContactWrenchTask.cpp
src/QPFixedBaseTSID.cpp src/QPTSID.cpp
PUBLIC_LINK_LIBRARIES Eigen3::Eigen
BipedalLocomotion::Contacts
Expand Down
132 changes: 132 additions & 0 deletions src/TSID/include/BipedalLocomotion/TSID/FeasibleContactWrenchTask.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/**
* @file FeasibleContactWrenchTask.h
* @authors Giulio Romualdi
* @copyright 2021 Istituto Italiano di Tecnologia (IIT). This software may be modified and
* distributed under the terms of the GNU Lesser General Public License v2.1 or any later version.
*/

#ifndef BIPEDAL_LOCOMOTION_TSID_FEASIBLE_CONTACT_WRENCH_TASK_H
#define BIPEDAL_LOCOMOTION_TSID_FEASIBLE_CONTACT_WRENCH_TASK_H

#include <memory>

#include <manif/manif.h>

#include <BipedalLocomotion/TSID/TSIDLinearTask.h>
#include <BipedalLocomotion/Math/ContactWrenchCone.h>


#include <iDynTree/KinDynComputations.h>


namespace BipedalLocomotion
{
namespace TSID
{

/**
* FeasibleContactWrenchTask is a concrete implementation of the TSIDLinearTask. Please use this
* element if you want to ensure that the contact wrench satisfies the constraints implemented in
* BipedalLocomotion::Math::ContactWrenchCone. Differently from the
* BipedalLocomotion::Math::ContactWrenchCone class, FeasibleContactWrenchTask requires also the
* positivstellensatz of the normal force written in local coordinate.
* @note FeasibleContactWrenchTask::disable will force the wrench associated to the task to be equal
* to a null wrench. FeasibleContactWrenchTask::enable will allow the wrench to be different from
* zero.
*/
class FeasibleContactWrenchTask : public TSIDLinearTask
{
struct ContactWrench
{
iDynTree::FrameIndex frameIndex; /**< Frame used to express the contact wrench */
System::VariablesHandler::VariableDescription variable; /**< Variable describing the contact
wrench */
Eigen::Matrix3d frame_R_inertial;
};

ContactWrench m_contactWrench;

BipedalLocomotion::Math::ContactWrenchCone m_cone;

bool m_isInitialized{false}; /**< True if the task has been initialized. */
bool m_isValid{false}; /**< True if the task is valid. */

Eigen::MatrixXd m_AinBodyCoordinate; /**< Matrix A written in body frame */

std::shared_ptr<iDynTree::KinDynComputations> m_kinDyn; /**< Pointer to a KinDynComputations
object */
public:

/**
* Initialize the task.
* @param handler pointer to the parameter handler.
* @note The following parameters are required:
* | Parameter Name | Type | Description | Mandatory |
* |:-----------------------------:|:----------------:|:-----------------------------------------------------------------------------:|:---------:|
* | `frame_name` | `string` | Name of the frame associated to the contact | Yes |
* | `variable_name` | `string` | Name of the variable contained in `VariablesHandler` describing the contact | Yes |
* | `number_of_slices` | `int` | Number of slices used to split 90 deg. | Yes |
* | `static_friction_coefficient` | `double` | Static friction coefficient. | Yes |
* | `foot_limits_x` | `vector<double>` | x coordinate of the foot limits w.r.t the frame attached to the surface | Yes |
* | `foot_limits_y` | `vector<double>` | y coordinate of the foot limits w.r.t the frame attached to the surface | Yes |
* @return true in case of success/false otherwise.
*/
bool initialize(std::weak_ptr<const ParametersHandler::IParametersHandler> paramHandler);

/**
* Set the kinDynComputations object.
* @param kinDyn pointer to a kinDynComputations object.
* @return True in case of success, false otherwise.
*/
bool setKinDyn(std::shared_ptr<iDynTree::KinDynComputations> kinDyn);

/**
* Set the set of variables required by the task. The variables are stored in the
* System::VariablesHandler.
* @param variablesHandler reference to a variables handler.
* @note The handler must contain a variable named as the parameter
* `variable_name` stored in the parameter handler. The variable represents the contact wrench
* acting of the robot.
* @return True in case of success, false otherwise.
*/
bool setVariablesHandler(const System::VariablesHandler& variablesHandler) override;

/**
* Update the content of the element.
* @return True in case of success, false otherwise.
*/
bool update() override;

/**
* Enable the task. I.e. a contact wrench different from zero is allowed.
*/
void enable();

/**
* Disable the task. I.e. the contact wrench is forced to be equal to zero.
*/
void disable();
Copy link
Member

Choose a reason for hiding this comment

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

There is some potential confusion on whether it is the task to be disabled (hence the wrench is not constrained), or if the wrench cannot be used to control the robot. A possibility could be to allow setting directly the maximum normal component. Another possibility could be to have a method like setContactState with an enum. Otherwise also a different naming could do the trick, although I did not find any good alternatives myself.

Copy link
Member Author

Choose a reason for hiding this comment

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

I like setContactState! the enum could be Active Inactive, what do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

That would be nice. On the other hand, we should try to be coherent and use that enum also inside the class. Right now it is a boolean https://github.com/dic-iit/bipedal-locomotion-framework/blob/d81b390683127a451669b0e09ff06da199f9490a/src/Contacts/include/BipedalLocomotion/Contacts/Contact.h#L102
and only in the EstimatedContact.

For the time being, we could simply add the boolean and start using it in separate PRs.

Copy link
Member Author

Choose a reason for hiding this comment

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

In 9b8662b I implemented the function we discussed.


/**
* Get the size of the task. (I.e the number of rows of the vector b)
* @return the size of the task.
*/
std::size_t size() const override;

/**
* The CoMTask is an equality task.
* @return the size of the task.
*/
Type type() const override;

/**
* Determines the validity of the objects retrieved with getA() and getB()
* @return True if the objects are valid, false otherwise.
*/
bool isValid() const override;
};

} // namespace TSID
} // namespace BipedalLocomotion

#endif // BIPEDAL_LOCOMOTION_TSID_FEASIBLE_CONTACT_WRENCH_TASK_H
Loading