pinocchio 4.1.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
Loading...
Searching...
No Matches
delassus-operator.hpp
1//
2// Copyright (c) 2024-2026 INRIA
3//
4
5#pragma once
6
7#include <type_traits>
8
9#include <eigenpy/memory.hpp>
10
11#include "pinocchio/algorithm/delassus-operator.hpp"
12
13namespace pinocchio
14{
15 namespace python
16 {
17 namespace bp = boost::python;
18
19 namespace details
20 {
22 template<typename, typename = void>
23 constexpr bool is_matrix_bool_bool_method = false;
24
25 template<typename T>
26 constexpr bool
27 is_matrix_bool_bool_method<T, std::void_t<decltype(std::declval<T>().matrix(true, true))>> =
28 true;
29 } // namespace details
30
31 template<typename DelassusOperator>
33 : public boost::python::def_visitor<DelassusOperatorBasePythonVisitor<DelassusOperator>>
34 {
35 typedef DelassusOperator Self;
36 typedef typename DelassusOperator::Scalar Scalar;
37 typedef context::MatrixXs MatrixXs;
38 typedef context::VectorXs VectorXs;
39 typedef typename traits<DelassusOperator>::getDampingReturnType getDampingReturnType;
40
41 template<class PyClass>
42 void visit(PyClass & cl) const
43 {
44 cl.def(bp::self * bp::other<MatrixXs>())
45 .def(
46 "__matmul__",
47 +[](const DelassusOperator & self, const MatrixXs & other) -> MatrixXs {
48 return MatrixXs(self * other);
49 },
50 bp::args("self", "other"),
51 "Matrix multiplication between self and another matrix. Returns the result of Delassus "
52 "* matrix.")
53
54 .def(
55 "solve", &DelassusOperator::template solve<MatrixXs>, bp::args("self", "mat"),
56 "Returns the solution x of Delassus * x = mat using the current decomposition of the "
57 "Delassus matrix.")
58
59 .def(
60 "updateCompliance",
61 (void (DelassusOperator::*)(const Scalar))&DelassusOperator::updateCompliance,
62 bp::args("self", "mu"),
63 "Add a compliance term to the diagonal of the Delassus matrix. The compliance term "
64 "should be "
65 "positive.")
66 .def(
67 "updateCompliance", &DelassusOperator::template updateCompliance<VectorXs>,
68 bp::args("self", "mus"),
69 "Add a compliance term to the diagonal of the Delassus matrix. The compliance terms "
70 "should "
71 "be all positive.")
72
73 .def(
74 "getCompliance",
75 +[](const DelassusOperator & self) -> VectorXs { return self.getCompliance(); },
76 bp::arg("self"),
77 "Returns the value of the compliance terms contained in the Delassus operator")
78
79 .def(
80 "updateDamping",
81 (void (DelassusOperator::*)(const Scalar))&DelassusOperator::updateDamping,
82 bp::args("self", "mu"),
83 "Add a damping term to the diagonal of the Delassus matrix. The damping term should be "
84 "positive.")
85 .def(
86 "updateDamping", &DelassusOperator::template updateDamping<VectorXs>,
87 bp::args("self", "mus"),
88 "Add a damping term to the diagonal of the Delassus matrix. The damping terms should "
89 "be all positive.")
90
91 .def(
92 "getDamping",
93 +[](const DelassusOperator & self) -> std::remove_reference_t<getDampingReturnType> {
94 return self.getDamping();
95 },
96 bp::arg("self"),
97 "Returns the value of the damping terms contained in the Delassus operator")
98 .def(
99 "inverse", &DelassusOperator::inverse, bp::arg("self"),
100 "Returns the inverse of the Delassus expression as a dense matrix.")
101
102 .def(
103 "size", &DelassusOperator::size, bp::arg("self"),
104 "Returns the size of the decomposition.")
105 .def("rows", &DelassusOperator::rows, bp::arg("self"), "Returns the number of rows.")
106 .def("cols", &DelassusOperator::cols, bp::arg("self"), "Returns the number of columns.");
107 if constexpr (details::is_matrix_bool_bool_method<DelassusOperator>)
108 {
109 cl.def(
110 "matrix",
111 static_cast<MatrixXs (DelassusOperator::*)(bool, bool) const>(
112 &DelassusOperator::matrix),
113 (bp::arg("self"), bp::arg("enforce_symmetry") = false, bp::arg("with_damping") = true),
114 "Returns the Delassus expression as a dense matrix.");
115 }
116 }
117 };
118
119 } // namespace python
120} // namespace pinocchio
Main pinocchio namespace.
Definition treeview.dox:11