Skip to content

Commit

Permalink
Merge pull request #242 from dic-iit/DynamicalSystem
Browse files Browse the repository at this point in the history
General improvement of DynamicalSystem and implementation of FixedBaseDynamics
  • Loading branch information
GiulioRomualdi authored Mar 26, 2021
2 parents 463742f + 84e69ad commit de3a3f8
Show file tree
Hide file tree
Showing 42 changed files with 1,814 additions and 1,230 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ All notable changes to this project are documented in this file.
- Implement LinearizedFrictionCone class (https://github.com/dic-iit/bipedal-locomotion-framework/pull/244)
- Added a check on whether the installed public headers have the correct folder structure (https://github.com/dic-iit/bipedal-locomotion-framework/pull/247)
- Implement python bindings for VariablesHandler class (https://github.com/dic-iit/bipedal-locomotion-framework/pull/234)
- Implement FixedBaseDynamics class (https://github.com/dic-iit/bipedal-locomotion-framework/pull/242)

### Changed
- Move all the Contacts related classes in Contacts component (https://github.com/dic-iit/bipedal-locomotion-framework/pull/204)
Expand All @@ -28,6 +29,7 @@ All notable changes to this project are documented in this file.
- Use std::optional instead of raw pointer in ISensorBridge. (https://github.com/dic-iit/bipedal-locomotion-framework/pull/226)
- Use `System::LinearTask` in TSID component (https://github.com/dic-iit/bipedal-locomotion-framework/pull/240)
- Restructure python bindings in submodules (https://github.com/dic-iit/bipedal-locomotion-framework/pull/238)
- Integrators and DynamicalSystems are now in the `ContinuousDynamicalSystem` component (https://github.com/dic-iit/bipedal-locomotion-framework/pull/242)

### Fixed
- Fix missing implementation of `YarpSensorBridge::getFailedSensorReads()`. (https://github.com/dic-iit/bipedal-locomotion-framework/pull/202)
Expand Down
4 changes: 4 additions & 0 deletions cmake/BipedalLocomotionFrameworkDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ framework_dependent_option(FRAMEWORK_COMPILE_ContactModels

framework_dependent_option(FRAMEWORK_COMPILE_System
"Compile System library?" ON
"" OFF)

framework_dependent_option(FRAMEWORK_COMPILE_ContinuousDynamicalSystem
"Compile System ContinuousDynamicalSystem?" ON
"FRAMEWORK_COMPILE_ContactModels" OFF)

framework_dependent_option(FRAMEWORK_COMPILE_AutoDiffCppAD
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# This software may be modified and distributed under the terms of the
# GNU Lesser General Public License v2.1 or any later version.

add_subdirectory(ContinuousDynamicalSystem)
add_subdirectory(TextLogging)
add_subdirectory(GenericContainer)
add_subdirectory(YarpUtilities)
Expand Down
26 changes: 26 additions & 0 deletions src/ContinuousDynamicalSystem/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright (C) 2021 Istituto Italiano di Tecnologia (IIT). All rights reserved.
# This software may be modified and distributed under the terms of the
# GNU Lesser General Public License v2.1 or any later version.


if(FRAMEWORK_COMPILE_ContinuousDynamicalSystem)

set(H_PREFIX include/BipedalLocomotion/ContinuousDynamicalSystem)

# set target name
add_bipedal_locomotion_library(
NAME ContinuousDynamicalSystem
PUBLIC_HEADERS ${H_PREFIX}/DynamicalSystem.h ${H_PREFIX}/LinearTimeInvariantSystem.h
${H_PREFIX}/FloatingBaseSystemKinematics.h ${H_PREFIX}/FloatingBaseDynamicsWithCompliantContacts.h ${H_PREFIX}/FixedBaseDynamics.h
${H_PREFIX}/Integrator.h ${H_PREFIX}/FixedStepIntegrator.h ${H_PREFIX}/ForwardEuler.h
${H_PREFIX}/CompliantContactWrench.h
PRIVATE_HEADERS ${H_PREFIX}/impl/traits.h
SOURCES src/LinearTimeInvariantSystem.cpp src/FloatingBaseSystemKinematics.cpp src/CompliantContactWrench.cpp src/FloatingBaseDynamicsWithCompliantContacts.cpp src/FixedBaseDynamics.cpp
PUBLIC_LINK_LIBRARIES BipedalLocomotion::ParametersHandler BipedalLocomotion::ContactModels
iDynTree::idyntree-high-level iDynTree::idyntree-model
Eigen3::Eigen BipedalLocomotion::TextLogging BipedalLocomotion::Math
PRIVATE_LINK_LIBRARIES BipedalLocomotion::CommonConversions
SUBDIRECTORIES tests
)

endif()
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
/**
* @file ContactWrench.h
* @file CompliantContactWrench.h
* @authors Giulio Romualdi
* @copyright 2020 Istituto Italiano di Tecnologia (IIT). This software may be modified and
* @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_SYSTEM_CONTACT_WRENCH_H
#define BIPEDAL_LOCOMOTION_SYSTEM_CONTACT_WRENCH_H
#ifndef BIPEDAL_LOCOMOTION_CONTINUOUS_DYNAMICAL_SYSTEM_COMPLIANT_CONTACT_WRENCH_H
#define BIPEDAL_LOCOMOTION_CONTINUOUS_DYNAMICAL_SYSTEM_COMPLIANT_CONTACT_WRENCH_H

#include <memory>

#include <iDynTree/Core/Wrench.h>
#include <iDynTree/Model/Indices.h>
#include <BipedalLocomotion/ContactModels/ContactModel.h>
#include <iDynTree/Model/Indices.h>

namespace BipedalLocomotion
{

namespace System
namespace ContinuousDynamicalSystem
{

/**
* A wrench excerted on a link due to an external contact.
*/
class ContactWrench
class CompliantContactWrench
{
iDynTree::FrameIndex m_frame; /**< Useful for identifying the variable in the Model */
std::shared_ptr<ContactModels::ContactModel> m_contactModel; /**< Contact model */

public:

/**
* Constructor
* @param index index of the frame
* @param wrench the contact wrench
*/
ContactWrench(const iDynTree::FrameIndex& index,
std::shared_ptr<ContactModels::ContactModel> model);
CompliantContactWrench(const iDynTree::FrameIndex& index,
std::shared_ptr<ContactModels::ContactModel> model);

/**
* Get the index of the frame
Expand All @@ -55,7 +55,7 @@ class ContactWrench
const std::weak_ptr<ContactModels::ContactModel> contactModel() const noexcept;
};

} // namespace System
} // namespace ContinuousDynamicalSystem
} // namespace BipedalLocomotion

#endif // BIPEDAL_LOCOMOTION_SYSTEM_CONTACT_WRENCH_H
#endif // BIPEDAL_LOCOMOTION_CONTINUOUS_DYNAMICAL_SYSTEM_COMPLIANT_CONTACT_WRENCH_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/**
* @file DynamicalSystem.h
* @authors Giulio Romualdi
* @copyright 2020 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_CONTINUOUS_DYNAMICAL_SYSTEM_DYNAMICAL_SYSTEM_H
#define BIPEDAL_LOCOMOTION_CONTINUOUS_DYNAMICAL_SYSTEM_DYNAMICAL_SYSTEM_H

#include <memory>
#include <tuple>

#include <BipedalLocomotion/ContinuousDynamicalSystem/impl/traits.h>
#include <BipedalLocomotion/GenericContainer/TemplateHelpers.h>
#include <BipedalLocomotion/ParametersHandler/IParametersHandler.h>

namespace BipedalLocomotion
{
namespace ContinuousDynamicalSystem
{

/**
* DynamicalSystem defines a continuous time dynamical system, i.e. \f$\dot{x}=f(x, u, t)\f$. Please
* inherit publicly from this class in order to define your custom dynamical system.
* Just be sure to call after your class definition
* #BLF_DEFINE_CONTINUOUS_DYNAMICAL_SYSTEM_INTERAL_STRUCTURE()
* For instance
* \code{.cpp}
* namespace BipedalLocomotion
* {
* namespace ContinuousDynamicalSystem
* {
* // forward declaration
* class Foo;
* }
* }
* // Here we define the internal structure of the Foo. Notice that the number of types contained in
* // the FooStateType must be equal to the number of FooStateDerivetiveType (This is required by the integrator class)
*
* using FooStateType = Eigen::Vector2d;
* using FooStateDerivativeType = Eigen::Vector2d;
* using FooInputType = Eigen::Vector2d;
* BLF_DEFINE_CONTINUOUS_DYNAMICAL_SYSTEM_INTERAL_STRUCTURE(Foo, (FooStateType),
* (FooStateDerivativeType),
* (FooInputType))
* namespace BipedalLocomotion
* {
* namespace ContinuousDynamicalSystem
* {
* // class definition
* class Foo : public DynamicalSystem<Foo>
* {
* ...
* }
* }
* }
* \endcode
*/
template <class _Derived> class DynamicalSystem
{
constexpr _Derived& derived()
{
return *static_cast<_Derived*>(this);
}
constexpr const _Derived& derived() const
{
return *static_cast<const _Derived*>(this);
}

public:
using State = typename internal::traits<_Derived>::State; /**< State space type */
using StateDerivative = typename internal::traits<_Derived>::StateDerivative; /**< State space
derivative type
*/
using Input = typename internal::traits<_Derived>::Input; /**< Input type */

static_assert(is_specialization<State, std::tuple>::value,
"Please define the internal structure of the dynamical system with "
"BLF_DEFINE_CONTINUOUS_DYNAMICAL_SYSTEM_INTERAL_STRUCTURE() macro.");

static_assert(is_specialization<StateDerivative, std::tuple>::value,
"Please define the internal structure of the dynamical system with "
"BLF_DEFINE_CONTINUOUS_DYNAMICAL_SYSTEM_INTERAL_STRUCTURE() macro.");

static_assert(is_specialization<Input, std::tuple>::value,
"Please define the internal structure of the dynamical system with "
"BLF_DEFINE_CONTINUOUS_DYNAMICAL_SYSTEM_INTERAL_STRUCTURE() macro.");

/**
* Initialize the Dynamical system.
* @param handler pointer to the parameter handler.
* @return true in case of success/false otherwise.
*/
bool initialize(std::weak_ptr<ParametersHandler::IParametersHandler> handler);

/**
* Set the state of the dynamical system.
* @note In principle, there is no need to override this method. This value is stored in an
* internal buffer.
* @param state tuple containing a const reference to the state elements.
* @return true in case of success, false otherwise.
*/
bool setState(const State& state);

/**
* Get the state to the dynamical system.
* @return the current state of the dynamical system
*/
const State& getState() const;

/**
* Set the control input to the dynamical system.
* @note In principle, there is no need to override this method. This value is stored in an
* internal buffer.
* @param controlInput the value of the control input used to compute the system dynamics.
* @return true in case of success, false otherwise.
*/
bool setControlInput(const Input& controlInput);

/**
* Computes the system dynamics. It return \f$f(x, u, t)\f$.
* @note The control input and the state have to be set separately with the methods
* setControlInput and setState.
* @param time the time at witch the dynamics is computed.
* @param stateDynamics tuple containing a reference to the element of the state derivative
* @warning Please implement the function in your custom dynamical system.
* @return true in case of success, false otherwise.
*/
bool dynamics(const double& time, StateDerivative& stateDerivative);
};

template <class _Derived>
bool DynamicalSystem<_Derived>::initialize(
std::weak_ptr<ParametersHandler::IParametersHandler> handler)
{
return this->derived().initialize(handler);
}

template <class _Derived> bool DynamicalSystem<_Derived>::setState(const State& state)
{
return this->derived().setState(state);
}

template <class _Derived>
const typename DynamicalSystem<_Derived>::State& DynamicalSystem<_Derived>::getState() const
{
return this->derived().getState();
}

template <class _Derived>
bool DynamicalSystem<_Derived>::setControlInput(const typename DynamicalSystem<_Derived>::Input& controlInput)
{
return this->derived().setControlInput(controlInput);
}

template <class _Derived>
bool DynamicalSystem<_Derived>::dynamics(const double& time, StateDerivative& stateDerivative)
{
return this->derived().dynamics(time, stateDerivative);
}

} // namespace ContinuousDynamicalSystem
} // namespace BipedalLocomotion

#endif // BIPEDAL_LOCOMOTION_CONTINUOUS_DYNAMICAL_SYSTEM_DYNAMICAL_SYSTEM_H
Loading

0 comments on commit de3a3f8

Please sign in to comment.