-
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 the python bindings for the Wrench class
- Loading branch information
1 parent
3819ea3
commit 4b444f7
Showing
3 changed files
with
66 additions
and
1 deletion.
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
63 changes: 63 additions & 0 deletions
63
bindings/python/Math/include/BipedalLocomotion/bindings/Math/Wrench.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,63 @@ | ||
/** | ||
* @file Constants.h | ||
* @authors Giulio Romualdi | ||
* @copyright 2021 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_MATH_WRENCH_H | ||
#define BIPEDAL_LOCOMOTION_BINDINGS_MATH_WRENCH_H | ||
|
||
#include <pybind11/eigen.h> | ||
#include <pybind11/pybind11.h> | ||
|
||
#include <BipedalLocomotion/Math/Wrench.h> | ||
|
||
namespace BipedalLocomotion | ||
{ | ||
namespace bindings | ||
{ | ||
namespace Math | ||
{ | ||
|
||
template <typename Scalar> struct WrenchTrampoline | ||
{ | ||
BipedalLocomotion::Math::Wrench<Scalar> wrench; | ||
}; | ||
|
||
template <typename Scalar> void CreateWrench(pybind11::module& module, const std::string& suffix) | ||
{ | ||
namespace py = ::pybind11; | ||
using namespace BipedalLocomotion::Math; | ||
|
||
py::class_<WrenchTrampoline<Scalar>>(module, ("Wrench" + suffix).c_str()) | ||
.def(py::init<>()) | ||
.def(py::init([](const Eigen::Matrix<Scalar, 6, 1>& vector) -> WrenchTrampoline<Scalar> { | ||
WrenchTrampoline<Scalar> tmp; | ||
tmp.wrench = vector; | ||
return tmp; | ||
})) | ||
.def("get_local_cop", | ||
[](const WrenchTrampoline<Scalar>& impl) -> Eigen::Matrix<Scalar, 3, 1> { | ||
return impl.wrench.getLocalCoP(); | ||
}) | ||
.def_property( | ||
"force", | ||
[](const WrenchTrampoline<Scalar>& impl) | ||
-> Eigen::Ref<const Eigen::Matrix<Scalar, 3, 1>> { return impl.wrench.force(); }, | ||
[](WrenchTrampoline<Scalar>& impl, const Eigen::Matrix<Scalar, 3, 1>& force) { | ||
impl.wrench.force() = force; | ||
}) | ||
.def_property( | ||
"torque", | ||
[](const WrenchTrampoline<Scalar>& impl) | ||
-> Eigen::Ref<const Eigen::Matrix<Scalar, 3, 1>> { return impl.wrench.torque(); }, | ||
[](WrenchTrampoline<Scalar>& impl, const Eigen::Matrix<Scalar, 3, 1>& torque) { | ||
impl.wrench.torque() = torque; | ||
}); | ||
} | ||
} // namespace Math | ||
} // namespace bindings | ||
} // namespace BipedalLocomotion | ||
|
||
#endif // BIPEDAL_LOCOMOTION_BINDINGS_MATH_WRENCH_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