Skip to content

Commit

Permalink
Update the interface of the ContactModel library accordingly to 01d406c
Browse files Browse the repository at this point in the history
  • Loading branch information
GiulioRomualdi committed Mar 25, 2020
1 parent 7044d40 commit 7a64ab0
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 208 deletions.
10 changes: 5 additions & 5 deletions src/ContactModels/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
if(BIPEDAL_LOCOMOTION_CONTROLLERS_COMPILE_ContactModels)

add_bipedal_component(
NAME ContactModels
SOURCES src/ContactModel.cpp src/ContinuousContactModel.cpp
PUBLIC_HEADERS include/BipedalLocomotionControllers/ContactModels/ContactModel.h include/BipedalLocomotionControllers/ContactModels/ContactModel.tpp include/BipedalLocomotionControllers/ContactModels/ContinuousContactModel.h
PUBLIC_LINK_LIBRARIES ${iDynTree_LIBRARIES}
SUBDIRECTORIES tests)
NAME ContactModels
SOURCES src/ContactModel.cpp src/ContinuousContactModel.cpp
PUBLIC_HEADERS include/BipedalLocomotionControllers/ContactModels/ContactModel.h include/BipedalLocomotionControllers/ContactModels/ContinuousContactModel.h
PUBLIC_LINK_LIBRARIES iDynTree::idyntree-core BipedalLocomotionControllers::ParametersHandler
SUBDIRECTORIES tests)

endif()
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@
#define BIPEDAL_LOCOMOTION_CONTROLLERS_CONTACT_MODELS_CONTACT_MODEL_H

#include <any>
#include <unordered_map>
#include <memory>
#include <string>
#include <unordered_map>

#include <iDynTree/Core/MatrixFixSize.h>
#include <iDynTree/Core/Transform.h>
#include <iDynTree/Core/Twist.h>
#include <iDynTree/Core/VectorFixSize.h>
#include <iDynTree/Core/Wrench.h>

#include <BipedalLocomotionControllers/ParametersHandler/IParametersHandler.h>

namespace BipedalLocomotionControllers
{
namespace ContactModels
Expand Down Expand Up @@ -58,25 +63,20 @@ class ContactModel
*/
virtual void computeControlMatrix() = 0;

/**
* Get variable from a set of variables
* @param variables map containing variables
* @param variableName name of the variable
* @param variable variable
* @return true/false in case of success/failure
*/
template <class T>
bool getVariable(const std::unordered_map<std::string, std::any>& variables,
const std::string& variableName,
T& variable);

public:
/**
* Set the immutable parameters
* @retun true/false in case of success/failure
* Initialization of the class. Please call this method before evaluating any other function
* @param handler std::weak_ptr to a parameter container. This class does not have the ownership
* of the container.
* @warning std::weak_ptr models temporary ownership: when the handler is accessed only if it
* exists, the std::weak_ptr is converted in a std::shared_ptr.
* @note the required parameters may depends on the particular implementation. An example
* can be found in BipedalLocomotionControllers::ContactModel::ContinuousContactmodel::initialize
* @return true/false in case of success/failure
*/
virtual bool setImmutableParameters(const std::unordered_map<std::string, std::any>& parameters) = 0;
virtual bool initialize(std::weak_ptr<ParametersHandler::IParametersHandler> handler) = 0;

public:
/**
* Get and compute (only if it is necessary) the contact wrench
* @return the contact wrench expressed in mixed representation
Expand All @@ -96,21 +96,17 @@ class ContactModel
const iDynTree::Matrix6x6& getControlMatrix();

/**
* Set the internal state of the model
* Set the internal state of the model.
* @note the meaning of the parameters may depend on the particular implementation. An example
* can be found in BipedalLocomotionControllers::ContactModel::ContinuousContactmodel::setState
* @retun true/false in case of success/failure
*/
virtual bool setState(const std::unordered_map<std::string, std::any>& state) = 0;
virtual void setState(const iDynTree::Twist& twist,
const iDynTree::Transform& transform,
const iDynTree::Transform& nullForceTransform) = 0;

/**
* Set the mutable parameters
* @retun true/false in case of success/failure
*/
virtual bool setMutableParameters(const std::unordered_map<std::string, std::any>& parameters) = 0;
};
} // namespace ContactModels
} // namespace BipedalLocomotionControllers


#include "ContactModel.tpp"

#endif // BIPEDAL_LOCOMOTION_CONTROLLERS_CONTACT_MODELS_CONTACT_MODEL_H

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <iDynTree/Core/Wrench.h>

#include <BipedalLocomotionControllers/ContactModels/ContactModel.h>
#include <BipedalLocomotionControllers/ParametersHandler/IParametersHandler.h>

namespace BipedalLocomotionControllers
{
Expand All @@ -34,18 +35,21 @@ namespace ContactModels
*/
class ContinuousContactModel final : public ContactModel
{
iDynTree::Transform m_frameTransform; /**< Homogeneous transformation of the frame placed in the
center of the contact surface */
iDynTree::Transform m_nullForceTransform; /**< Homogeneous transformation corresponding to a
null contact wrench */
iDynTree::Twist m_twist; /**< Twist expressed in mixed representation of the frame placed in the
center of the contact surface */
/** Homogeneous transformation of the frame placed in the center of the contact surface */
iDynTree::Transform m_frameTransform{iDynTree::Transform::Identity()};

double m_springCoeff; /**< Spring coefficient associated to the model */
double m_damperCoeff; /**< Damper coefficient associated to the model */
/** Homogeneous transformation corresponding to a null contact wrench */
iDynTree::Transform m_nullForceTransform{iDynTree::Transform::Identity()};

double m_length; /**< Length of the rectangular contact surface */
double m_width; /**< Width of the rectangular contact surface */
/** Twist expressed in mixed representation of the frame placed in the center of the contact
* surface */
iDynTree::Twist m_twist{iDynTree::Twist::Zero()};

double m_springCoeff{0.0}; /**< Spring coefficient associated to the model */
double m_damperCoeff{0.0}; /**< Damper coefficient associated to the model */

double m_length{0.0}; /**< Length of the rectangular contact surface */
double m_width{0.0}; /**< Width of the rectangular contact surface */

/**
* Evaluate the contact wrench given a specific contact model
Expand All @@ -62,62 +66,36 @@ class ContinuousContactModel final : public ContactModel
*/
void computeControlMatrix() final;

/**
* Set the parameters that cannot change
* @param state std::unordered_map containing the mutable parameters of the system. To compute the contact
* wrench between two systems (i.e. a link of a robot and the environment) the following data have
* to be available. If not an std::runtime_error is thrown.
* - \a length (double): length in meters associated to the model
* - \a width (double): width in meters associated to the model
* @retun true/false in case of success/failure
*/
bool setImmutableParameters(const std::unordered_map<std::string, std::any>& parameters) final;

public:

/**
* Constructor. It instantiates the value of the mutable parameters and the immutable parameters.
* @param immutableParameters std::unordered_map containing the immutable parameters of the
* system. The list of the required parameters could be found in @ref
* BipedalLocomotionController::ContactModels::setImmutableparameters
* @param mutableParameters std::unordered_map containing the mutable parameters of the
* system. The list of the required parameters could be found in @ref
* BipedalLocomotionController::ContactModels::setMutableparameters
* Constructor
*/
ContinuousContactModel(const std::unordered_map<std::string, std::any>& immutableParameters,
const std::unordered_map<std::string, std::any>& mutableParameters);
ContinuousContactModel();

/**
* Constructor. It instantiate the value of the mutable parameters and the immutable parameters.
* @param parameters std::unordered_map containing the immutable and mutable parameters of the
* system. The list of the required parameters could be found in @ref
* BipedalLocomotionController::ContactModels::setMutableparameters
* Initialization of the class. Please call this method before evaluating any other function
* @param handler std::weak_ptr to a parameter container. This class does not have the ownership
* of the container.
* @note The following parameters are required.
* - \a length (double): length in meters associated to the model
* - \a width (double): width in meters associated to the model
* - \a spring_coeff (double): spring coefficient associated to the model
* - \a damper_coeff (double): damper coefficient associated to the model
* @return true/false in case of success/failure
*/
ContinuousContactModel(const std::unordered_map<std::string, std::any>& parameters);

bool initialize(std::weak_ptr<ParametersHandler::IParametersHandler> handler) final;

/**
* Set the internal state of the model.
* @param state std::unordered_map containing the state of the system. To compute the contact
* wrench between two systems (i.e. a link of a robot and the environment) the following data have
* to be available. If not an std::runtime_error is thrown.
* - \a frame_transform (iDynTree::Transform): transformation between the link and the inertial frame;
* - \a null_force_transform (iDynTree::Transform): transformation corresponding to a null force;
* - \a twist (iDynTree::Twist): twist (expressed in mixed representation) of the link
* @retun true/false in case of success/failure
*/
bool setState(const std::unordered_map<std::string, std::any>& state) final;

/**
* Set the parameters that may depend on time/state (i.e. they are not considered constant)
* @param state std::unordered_map containing the mutable parameters of the system. To compute the contact
* wrench between two systems (i.e. a link of a robot and the environment) the following data have
* to be available. If not an std::runtime_error is thrown.
* - \a spring_coeff (double): spring coefficient associated to the model
* - \a damper_coeff (double): damper coefficient associated to the model
* @retun true/false in case of success/failure
* @param twist spatial velocity (expressed in mixed representation) of the link
* @param transform transformation between the link and the inertial frame
* @param nullForceTransform transformation corresponding to a null force expressed w.r.t. the
* inertial frame
*/
bool setMutableParameters(const std::unordered_map<std::string, std::any>& parameters) final;
void setState(const iDynTree::Twist& twist,
const iDynTree::Transform& transform,
const iDynTree::Transform& nullForceTransform) final;

/**
* Compute the contact force applied by the environment on the system in a particular point of
Expand Down
Loading

0 comments on commit 7a64ab0

Please sign in to comment.