-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement python bindings for ML component
- Loading branch information
1 parent
27989df
commit 94cb36d
Showing
9 changed files
with
263 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright (C) 2023 Istituto Italiano di Tecnologia (IIT). All rights reserved. | ||
# This software may be modified and distributed under the terms of the | ||
# BSD-3-Clause license. | ||
|
||
if(FRAMEWORK_COMPILE_ML) | ||
|
||
set(H_PREFIX include/BipedalLocomotion/bindings/ML) | ||
|
||
add_bipedal_locomotion_python_module( | ||
NAME MLBindings | ||
SOURCES src/Module.cpp src/MANN.cpp src/MANNAutoregressive.cpp | ||
HEADERS ${H_PREFIX}/Module.h ${H_PREFIX}/MANN.h ${H_PREFIX}/MANNAutoregressive.h | ||
LINK_LIBRARIES BipedalLocomotion::ML | ||
) | ||
|
||
endif() |
26 changes: 26 additions & 0 deletions
26
bindings/python/ML/include/BipedalLocomotion/bindings/ML/MANN.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* @file MANN.h | ||
* @authors Giulio Romualdi | ||
* @copyright 2023 Istituto Italiano di Tecnologia (IIT). This software may be modified and | ||
* distributed under the terms of the BSD-3-Clause license. | ||
*/ | ||
|
||
#ifndef BIPEDAL_LOCOMOTION_BINDINGS_ML_MANN_H | ||
#define BIPEDAL_LOCOMOTION_BINDINGS_ML_MANN_H | ||
|
||
#include <pybind11/pybind11.h> | ||
|
||
namespace BipedalLocomotion | ||
{ | ||
namespace bindings | ||
{ | ||
namespace ML | ||
{ | ||
|
||
void CreateMANN(pybind11::module& module); | ||
|
||
} // namespace ML | ||
} // namespace bindings | ||
} // namespace BipedalLocomotion | ||
|
||
#endif // BIPEDAL_LOCOMOTION_BINDINGS_ML_MANN_H |
26 changes: 26 additions & 0 deletions
26
bindings/python/ML/include/BipedalLocomotion/bindings/ML/MANNAutoregressive.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* @file MANNAutoregressive.h | ||
* @authors Giulio Romualdi | ||
* @copyright 2023 Istituto Italiano di Tecnologia (IIT). This software may be modified and | ||
* distributed under the terms of the BSD-3-Clause license. | ||
*/ | ||
|
||
#ifndef BIPEDAL_LOCOMOTION_BINDINGS_ML_MANN_TRAJECTORY_GENERATION_H | ||
#define BIPEDAL_LOCOMOTION_BINDINGS_ML_MANN_TRAJECTORY_GENERATION_H | ||
|
||
#include <pybind11/pybind11.h> | ||
|
||
namespace BipedalLocomotion | ||
{ | ||
namespace bindings | ||
{ | ||
namespace ML | ||
{ | ||
|
||
void CreateMANNAutoregressive(pybind11::module& module); | ||
|
||
} // namespace ML | ||
} // namespace bindings | ||
} // namespace BipedalLocomotion | ||
|
||
#endif // BIPEDAL_LOCOMOTION_BINDINGS_ML_MANN_TRAJECTORY_GENERATION_H |
26 changes: 26 additions & 0 deletions
26
bindings/python/ML/include/BipedalLocomotion/bindings/ML/Module.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* @file Module.h | ||
* @authors Giulio Romualdi | ||
* @copyright 2023 Istituto Italiano di Tecnologia (IIT). This software may be modified and | ||
* distributed under the terms of the BSD-3-Clause license. | ||
*/ | ||
|
||
#ifndef BIPEDAL_LOCOMOTION_BINDINGS_ML_MODULE_H | ||
#define BIPEDAL_LOCOMOTION_BINDINGS_ML_MODULE_H | ||
|
||
#include <pybind11/pybind11.h> | ||
|
||
namespace BipedalLocomotion | ||
{ | ||
namespace bindings | ||
{ | ||
namespace ML | ||
{ | ||
|
||
void CreateModule(pybind11::module& module); | ||
|
||
} // namespace ML | ||
} // namespace bindings | ||
} // namespace BipedalLocomotion | ||
|
||
#endif // BIPEDAL_LOCOMOTION_BINDINGS_ML_MODULE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* @file MANN.cpp | ||
* @authors Giulio Romualdi | ||
* @copyright 2023 Istituto Italiano di Tecnologia (IIT). This software may be modified and | ||
* distributed under the terms of the BSD-3-Clause license. | ||
*/ | ||
|
||
#include <pybind11/eigen.h> | ||
#include <pybind11/pybind11.h> | ||
#include <pybind11/stl.h> | ||
|
||
#include <BipedalLocomotion/ML/MANN.h> | ||
|
||
#include <BipedalLocomotion/bindings/ML/MANN.h> | ||
#include <BipedalLocomotion/bindings/System/Advanceable.h> | ||
|
||
namespace BipedalLocomotion | ||
{ | ||
namespace bindings | ||
{ | ||
namespace ML | ||
{ | ||
|
||
void CreateMANN(pybind11::module& module) | ||
{ | ||
namespace py = ::pybind11; | ||
namespace ML = BipedalLocomotion::ML; | ||
namespace System = BipedalLocomotion::System; | ||
|
||
py::class_<ML::MANNInput>(module, "MANNInput") | ||
.def(py::init()) | ||
.def_readwrite("base_position_trajectory", &ML::MANNInput::basePositionTrajectory) | ||
.def_readwrite("facing_direction_trajectory", &ML::MANNInput::facingDirectionTrajectory) | ||
.def_readwrite("base_velocity_trajectory", &ML::MANNInput::baseVelocitiesTrajectory) | ||
.def_readwrite("joint_positions", &ML::MANNInput::jointPositions) | ||
.def_readwrite("joint_velocities", &ML::MANNInput::jointVelocities); | ||
|
||
py::class_<ML::MANNOutput>(module, "MANNOutput") | ||
.def(py::init()) | ||
.def_readwrite("future_base_position_trajectory", | ||
&ML::MANNOutput::futureBasePositionTrajectory) | ||
.def_readwrite("future_facing_direction_trajectory", | ||
&ML::MANNOutput::futureFacingDirectionTrajectory) | ||
.def_readwrite("future_base_velocities_trajectory", | ||
&ML::MANNOutput::futureBaseVelocitiesTrajectory) | ||
.def_readwrite("joint_positions", &ML::MANNOutput::jointPositions) | ||
.def_readwrite("joint_velocities", &ML::MANNOutput::jointVelocities) | ||
.def_readwrite("projected_base_velocity", &ML::MANNOutput::projectedBaseVelocity); | ||
|
||
BipedalLocomotion::bindings::System::CreateAdvanceable<ML::MANNInput, // | ||
ML::MANNOutput>(module, "MANN"); | ||
py::class_<ML::MANN, System::Advanceable<ML::MANNInput, ML::MANNOutput>>(module, "MANN") | ||
.def(py::init()); | ||
} | ||
|
||
} // namespace ML | ||
} // namespace bindings | ||
} // namespace BipedalLocomotion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* @file MannAutoregressive.cpp | ||
* @authors Giulio Romualdi | ||
* @copyright 2023 Istituto Italiano di Tecnologia (IIT). This software may be modified and | ||
* distributed under the terms of the BSD-3-Clause license. | ||
*/ | ||
|
||
#include <iDynTree/Model/Model.h> | ||
#include <pybind11/eigen.h> | ||
#include <pybind11/pybind11.h> | ||
#include <pybind11/stl.h> | ||
|
||
#include <BipedalLocomotion/ML/MANNAutoregressive.h> | ||
#include <BipedalLocomotion/bindings/ML/MANNAutoregressive.h> | ||
#include <BipedalLocomotion/bindings/System/Advanceable.h> | ||
#include <BipedalLocomotion/bindings/type_caster/swig.h> | ||
|
||
namespace BipedalLocomotion | ||
{ | ||
namespace bindings | ||
{ | ||
namespace ML | ||
{ | ||
|
||
void CreateMANNAutoregressive(pybind11::module& module) | ||
{ | ||
namespace py = ::pybind11; | ||
namespace ML = BipedalLocomotion::ML; | ||
namespace System = BipedalLocomotion::System; | ||
|
||
py::class_<ML::MANNAutoregressiveInput>(module, "MANNAutoregressiveInput") | ||
.def(py::init()) | ||
.def_readwrite("desired_future_base_trajectory", | ||
&ML::MANNAutoregressiveInput::desiredFutureBaseTrajectory) | ||
.def_readwrite("desired_future_base_velocities", | ||
&ML::MANNAutoregressiveInput::desiredFutureBaseVelocities) | ||
.def_readwrite("desired_future_facing_directions", | ||
&ML::MANNAutoregressiveInput::desiredFutureFacingDirections); | ||
|
||
py::class_<ML::MANNAutoregressiveOutput>(module, "MANNAutoregressiveOutput") | ||
.def(py::init()) | ||
.def_readwrite("joint_positions", &ML::MANNAutoregressiveOutput::jointsPosition) | ||
.def_readwrite("base_pose", &ML::MANNAutoregressiveOutput::basePose) | ||
.def_readwrite("left_foot", &ML::MANNAutoregressiveOutput::leftFoot) | ||
.def_readwrite("right_foot", &ML::MANNAutoregressiveOutput::rightFoot); | ||
|
||
BipedalLocomotion::bindings::System::CreateAdvanceable<ML::MANNAutoregressiveInput, // | ||
ML::MANNAutoregressiveOutput> // | ||
(module, "MANNAutoregressive"); | ||
py::class_<ML::MANNAutoregressive, | ||
System::Advanceable<ML::MANNAutoregressiveInput, // | ||
ML::MANNAutoregressiveOutput>>(module, | ||
"MANNAutoregressive") | ||
.def(py::init()) | ||
.def("reset", py::overload_cast<const ML::MANNInput&, const Contacts::EstimatedContact&, | ||
const Contacts::EstimatedContact&, | ||
const manif::SE3d&, | ||
const manif::SE3Tangentd&>(&ML::MANNAutoregressive::reset)) | ||
.def("set_robot_model", [](ML::MANNAutoregressive& impl, ::pybind11::object& obj) { | ||
iDynTree::Model* cls = py::detail::swig_wrapped_pointer_to_pybind<iDynTree::Model>(obj); | ||
|
||
if (cls == nullptr) | ||
{ | ||
throw ::pybind11::value_error("Invalid input for the function. Please provide " | ||
"an iDynTree::Model object."); | ||
} | ||
return impl.setRobotModel(*cls); | ||
}); | ||
} | ||
|
||
} // namespace ML | ||
} // namespace bindings | ||
} // namespace BipedalLocomotion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* @file Module.cpp | ||
* @authors Giulio Romualdi | ||
* @copyright 2023 Istituto Italiano di Tecnologia (IIT). This software may be modified and | ||
* distributed under the terms of the BSD-3-Clause license. | ||
*/ | ||
|
||
#include <pybind11/pybind11.h> | ||
|
||
#include <BipedalLocomotion/bindings/ML/MANN.h> | ||
#include <BipedalLocomotion/bindings/ML/MANNAutoregressive.h> | ||
|
||
namespace BipedalLocomotion | ||
{ | ||
namespace bindings | ||
{ | ||
namespace ML | ||
{ | ||
void CreateModule(pybind11::module& module) | ||
{ | ||
module.doc() = "ML module."; | ||
|
||
CreateMANN(module); | ||
CreateMANNAutoregressive(module); | ||
} | ||
} // namespace ML | ||
} // namespace bindings | ||
} // namespace BipedalLocomotion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters