pinocchio 4.1.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
Loading...
Searching...
No Matches
constraint-model-inheritance.hpp
1//
2// Copyright (c) 2025 INRIA
3//
4
5#pragma once
6
7#include <boost/python.hpp>
8#include <eigenpy/exception.hpp>
9#include <eigenpy/eigen-to-python.hpp>
10
11#include "pinocchio/multibody.hpp"
12#include "pinocchio/constraints.hpp"
13#include "pinocchio/bindings/python/fwd.hpp"
14#include "pinocchio/bindings/python/utils/macros.hpp"
15
16namespace pinocchio
17{
18 namespace python
19 {
20 namespace bp = boost::python;
21
22 // -----------------------------------------------------------------
23 // Declaration of all inheritance visitor we want to apply
24 // i.e. level of CRTP where member or methods are declared
25 // -----------------------------------------------------------------
26 template<class T, class = void>
28
29 template<class T, class = void>
31
32 // -----------------------------------------------------------------
33 // The visitor that apply all the possible inheritance
34 // -----------------------------------------------------------------
35 template<class T>
37 : public bp::def_visitor<ConstraintModelInheritancePythonVisitor<T>>
38 {
39 public:
40 template<class PyClass>
41 void visit(PyClass & cl) const
42 {
43 // Apply all possible inheritance
46 }
47 };
48
49 // -----------------------------------------------------------------
50 // Actual implementation of visitors when there is inheritence
51 // -----------------------------------------------------------------
52
53 template<class T, class> // Default: do nothing
55 : public bp::def_visitor<BinaryKinematicsConstraintModelBasePythonVisitor<T>>
56 {
57 public:
58 template<class PyClass>
59 void visit(PyClass & /*cl*/) const
60 {
61 }
62 };
63
64 template<class T> // SFINAE specialization discard except when inherit
65 struct BinaryKinematicsConstraintModelBasePythonVisitor<T, enable_if_binarykinematic_model_t<T>>
66 : public bp::def_visitor<BinaryKinematicsConstraintModelBasePythonVisitor<T>>
67 {
68 typedef typename T::ConstraintData ConstraintData;
69 typedef typename T::MatrixSize6 MatrixSize6;
70 typedef typename T::SE3 SE3;
71 typedef context::Model Model;
72
73 public:
74 template<class PyClass>
75 void visit(PyClass & cl) const
76 {
77 cl.def(
78 bp::init<const Model &, JointIndex, const SE3 &, JointIndex, const SE3 &>(
79 (bp::arg("self"), bp::arg("model"), bp::arg("joint1_id"), bp::arg("joint1_placement"),
80 bp::arg("joint2_id"), bp::arg("joint2_placement")),
81 "Constructor from given joint index and placement for the two joints "
82 "implied in the constraint."))
83 .def(
84 bp::init<const Model &, JointIndex>(
85 (bp::arg("self"), bp::arg("model"), bp::arg("joint1_id")),
86 "Constructor from given joint index of the first joint "
87 "implied in the constraint."))
88 .def(
89 bp::init<const Model &, JointIndex, const SE3 &>(
90 (bp::arg("self"), bp::arg("model"), bp::arg("joint1_id"),
91 bp::arg("joint1_placement")),
92 "Constructor from given joint index and placement of the first joint "
93 "implied in the constraint."))
94 .def(
95 bp::init<const Model &, JointIndex, JointIndex>(
96 (bp::arg("self"), bp::arg("model"), bp::arg("joint1_id"), bp::arg("joint2_id")),
97 "Constructor from given joint index for the two joints "
98 "implied in the constraint."))
99 .def(
100 bp::init<const Model &>(
101 (bp::arg("self"), bp::arg("model")), "Constructor from the model only."))
102 .def(
103 "getA1", &getA1, bp::args("self", "constraint_data", "reference_frame"),
104 "Returns the constraint projector associated with joint 1. "
105 "This matrix transforms a spatial velocity expressed in a reference frame "
106 "to the first component of the constraint associated with joint 1.")
107 .def(
108 "getA2", &getA2, bp::args("self", "constraint_data", "reference_frame"),
109 "Returns the constraint projector associated with joint 2. "
110 "This matrix transforms a spatial velocity expressed in a reference frame "
111 "to the first component of the constraint associated with joint 2.")
112 .PINOCCHIO_ADD_PROPERTY(T, joint1_id, "Index of the first joint in the model tree.")
113 .PINOCCHIO_ADD_PROPERTY(T, joint2_id, "Index of the second joint in the model tree.")
114 .PINOCCHIO_ADD_PROPERTY(
115 T, joint1_placement, "Position of attached point with respect to the frame of joint1.")
116 .PINOCCHIO_ADD_PROPERTY(
117 T, joint2_placement, "Position of attached point with respect to the frame of joint2.")
118 .PINOCCHIO_ADD_PROPERTY(
119 T, desired_constraint_offset, "Desired constraint shift at position level.")
120 .PINOCCHIO_ADD_PROPERTY(
121 T, desired_constraint_velocity, "Desired constraint velocity at velocity level.")
122 .PINOCCHIO_ADD_PROPERTY(
123 T, desired_constraint_acceleration,
124 "Desired constraint velocity at acceleration level.")
125 .PINOCCHIO_ADD_PROPERTY(T, nv, "Dimension of the model velocity.")
126 .PINOCCHIO_ADD_PROPERTY(T, depth_joint1, "Depth of the kinematic tree for joint1.")
127 .PINOCCHIO_ADD_PROPERTY(T, depth_joint2, "Depth of the kinematic tree for joint2.");
128 }
129
130 static MatrixSize6
131 getA1(const T & self, const ConstraintData & constraint_data, ReferenceFrame rf)
132 {
133 MatrixSize6 res;
134 switch (rf)
135 {
136 case WORLD:
137 res = self.getA1(constraint_data, WorldFrameTag());
138 break;
139 case LOCAL:
140 res = self.getA1(constraint_data, LocalFrameTag());
141 break;
142 case LOCAL_WORLD_ALIGNED:
143 res = self.getA1(constraint_data, LocalWorldAlignedFrameTag());
144 break;
145 }
146 return res;
147 }
148
149 static MatrixSize6
150 getA2(const T & self, const ConstraintData & constraint_data, ReferenceFrame rf)
151 {
152 MatrixSize6 res;
153 switch (rf)
154 {
155 case WORLD:
156 res = self.getA2(constraint_data, WorldFrameTag());
157 break;
158 case LOCAL:
159 res = self.getA2(constraint_data, LocalFrameTag());
160 break;
161 case LOCAL_WORLD_ALIGNED:
162 res = self.getA2(constraint_data, LocalWorldAlignedFrameTag());
163 break;
164 }
165 return res;
166 }
167 }; // BinaryKinematicsConstraintModelBasePythonVisitor
168
169 template<class T, class> // Default: do nothing
171 : public bp::def_visitor<PointConstraintModelBasePythonVisitor<T>>
172 {
173 public:
174 template<class PyClass>
175 void visit(PyClass & /*cl*/) const
176 {
177 }
178 };
179
180 template<class T> // SFINAE specialization discard except when inherit
181 struct PointConstraintModelBasePythonVisitor<T, enable_if_point_model_t<T>>
182 : public bp::def_visitor<PointConstraintModelBasePythonVisitor<T>>
183 {
184 public:
185 template<class PyClass>
186 void visit(PyClass & cl) const
187 {
188 cl.def(
189 "computeConstraintSpatialInertia", &computeConstraintSpatialInertia,
190 bp::args("self", "placement", "diagonal_constraint_inertia"),
191 "This function computes the spatial inertia associated with the constraint.");
192 // computeConstraintInertias is not exposed as it is designed for Eigen Blocks
193 }
194
195 static context::Matrix6s computeConstraintSpatialInertia(
196 const T & self,
197 const context::SE3 & placement,
198 const context::Vector3s & diagonal_constraint_inertia)
199 {
200 return self.computeConstraintSpatialInertia(
201 placement, diagonal_constraint_inertia.asDiagonal());
202 }
203 }; // PointConstraintModelBasePythonVisitor
204
205 } // namespace python
206} // namespace pinocchio
Main pinocchio namespace.
Definition treeview.dox:11