pinocchio 4.1.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
Loading...
Searching...
No Matches
constraints-models.hpp
1//
2// Copyright (c) 2025 INRIA
3//
4
5#pragma once
6
7#include "pinocchio/constraints.hpp"
8#include "pinocchio/bindings/python/fwd.hpp"
9#include "pinocchio/bindings/python/utils/printable.hpp"
10#include "pinocchio/bindings/python/algorithm/constraints/constraint-model-inheritance.hpp"
11
12namespace pinocchio
13{
14 namespace python
15 {
16 namespace bp = boost::python;
17
18 // ---------------------
19 // Generic expose_constraint_model : do nothing special
20 template<class T>
21 bp::class_<T> & expose_constraint_model(bp::class_<T> & cl)
22 {
23 return cl;
24 }
25
26 // specialization for terminal ConstraintModels
27 template<>
28 bp::class_<context::PointContactConstraintModel> &
29 expose_constraint_model(bp::class_<context::PointContactConstraintModel> & cl)
30 {
31 typedef context::PointContactConstraintModel Self;
32 return cl.def("getFriction", &Self::getFriction, "Get coulomb friction coefficient.")
33 .def("setFriction", &Self::setFriction, "Set coulomb friction coefficient.")
34 .def_readwrite("geom1_id", &Self::geom1_id, "Index of the first geometry object.")
35 .def_readwrite("geom2_id", &Self::geom2_id, "Index of the second geometry object.");
36 }
37
38 template<>
39 bp::class_<context::JointFrictionConstraintModel> &
40 expose_constraint_model(bp::class_<context::JointFrictionConstraintModel> & cl)
41 {
42 typedef typename context::JointFrictionConstraintModel::JointIndexVector JointIndexVector;
43 typedef context::JointFrictionConstraintModel Self;
44 typedef context::VectorXs VectorXs;
45 cl.def(
46 bp::init<const context::Model &, const JointIndexVector &>(
47 (bp::arg("self"), bp::arg("model"), bp::arg("m_active_joints")),
48 "Constructor from given joint index vector "
49 "implied in the constraint."))
50 .def(
51 bp::init<
52 const context::Model &, const JointIndexVector &, const context::VectorXs &,
53 const context::VectorXs &>(
54 (bp::arg("self"), bp::arg("model"), bp::arg("m_active_joints"), bp::arg("lb"),
55 bp::arg("ub")),
56 "Full constructor from model, active joints, lower and upper friction bounds."))
57 .def(
58 bp::init<const context::Model &>(
59 (bp::arg("self"), bp::arg("model")), "Constructor from the model only."))
60 .def(
61 "getActiveJoints", &Self::getActiveJoints,
62 bp::return_value_policy<bp::copy_const_reference>())
63 .def(
64 "getActiveDofs", &Self::getActiveDofs,
65 bp::return_value_policy<bp::copy_const_reference>())
66 .def(
67 "getFrictionLowerLimit", &Self::getFrictionLowerLimit,
68 bp::return_value_policy<bp::copy_const_reference>(), "Get friction lower limit.")
69 .def(
70 "setFrictionLowerLimit", bp::make_function(+[](Self & self, const VectorXs & lb) {
71 self.setFrictionLowerLimit(lb);
72 }),
73 "Set friction lower limit.")
74 .def(
75 "getFrictionUpperLimit", &Self::getFrictionUpperLimit,
76 bp::return_value_policy<bp::copy_const_reference>(), "Get friction upper limit.")
77 .def(
78 "setFrictionUpperLimit", bp::make_function(+[](Self & self, const VectorXs & ub) {
79 self.setFrictionUpperLimit(ub);
80 }),
81 "Set friction upper limit.")
82 .def(
83 "getTimeStep", &Self::getTimeStep,
84 "Get dt used to convert friction force limits to impulse limits.")
85 .def(
86 "setTimeStep", +[](Self & self, const context::Scalar dt) { self.setTimeStep(dt); },
87 bp::args("self", "dt"),
88 "Set dt used to convert friction force limits to impulse limits.");
89 return cl;
90 }
91
92 template<>
93 bp::class_<context::JointLimitConstraintModel> &
94 expose_constraint_model(bp::class_<context::JointLimitConstraintModel> & cl)
95 {
96 typedef typename context::JointLimitConstraintModel::JointIndexVector JointIndexVector;
97 typedef typename context::JointLimitConstraintModel Self;
98 cl.def(
99 bp::init<const context::Model &, const JointIndexVector &>(
100 (bp::arg("self"), bp::arg("model"), bp::arg("activable_joints")),
101 "Constructor from given joint index vector "
102 "implied in the constraint."))
103 .def(
104 bp::init<
105 const context::Model &, const JointIndexVector &, const context::VectorXs &,
106 const context::VectorXs &>(
107 (bp::arg("self"), bp::arg("model"), bp::arg("activable_joints"), bp::arg("lb"),
108 bp::arg("ub")),
109 "Constructor from given joint index vector "
110 "implied in the constraint."))
111 .def(
112 bp::init<
113 const context::Model &, const JointIndexVector &, const context::VectorXs &,
114 const context::VectorXs &, const context::VectorXs &>(
115 (bp::arg("self"), bp::arg("model"), bp::arg("activable_joints"), bp::arg("lb"),
116 bp::arg("ub"), bp::arg("margin")),
117 "Constructor from given joint index vector "
118 "implied in the constraint."))
119 .def(
120 bp::init<const context::Model &>(
121 (bp::arg("self"), bp::arg("model")), "Constructor from the model only."))
122 .def(
123 "getSelectedJoints", &Self::getSelectedJoints,
124 bp::return_value_policy<bp::copy_const_reference>(),
125 "Joints for which there is at least one position limit.")
126 .def("getNqReduce", &Self::getNqReduce, "Sum of nq of activable joints.")
127 .def("getMaxOfNvs", &Self::getMaxOfNvs, "Max nv of atomic joints in activable joints.")
128 .def(
129 "getActivablePositionLimit", &Self::getActivablePositionLimit,
130 bp::return_value_policy<bp::copy_const_reference>(),
131 "Position limit of the dof of the constraints.")
132 .def(
133 "lowerResidualSize",
134 +[](const Self & self, ConstraintSelectionType sel) -> int {
135 switch (sel)
136 {
137 case ConstraintSelectionType::CURRENT:
138 return self.lowerResidualSize(CurrentSelection());
139 case ConstraintSelectionType::MAXIMAL:
140 return self.lowerResidualSize(MaximalSelection());
141 default:
142 PINOCCHIO_UNREACHABLE();
143 }
144 },
145 (bp::arg("self"), bp::arg("sel") = ConstraintSelectionType::CURRENT))
146 .def(
147 "upperResidualSize",
148 +[](const Self & self, ConstraintSelectionType sel) -> int {
149 switch (sel)
150 {
151 case ConstraintSelectionType::CURRENT:
152 return self.upperResidualSize(CurrentSelection());
153 case ConstraintSelectionType::MAXIMAL:
154 return self.upperResidualSize(MaximalSelection());
155 default:
156 PINOCCHIO_UNREACHABLE();
157 }
158 },
159 (bp::arg("self"), bp::arg("sel") = ConstraintSelectionType::CURRENT))
160 .def(
161 "setPositionLimitAndMargin",
162 +[](
163 Self & self, const context::VectorXs & lb, const context::VectorXs & ub,
164 const context::VectorXs & margin) -> void {
165 self.setPositionLimitAndMargin(lb, ub, margin);
166 },
167 (bp::arg("self"), bp::arg("lb"), bp::arg("ub"), bp::arg("margin")),
168 "Set position limit and margin for activable constraints from lower_bound, upper_bound "
169 "and margin of size model.nq.")
170 .def(
171 "makeSelectionMaximal", &Self::makeSelectionMaximal, bp::arg("self"),
172 "Make the selection maximal (all activable constraints become active).")
173 .def(
174 "makeSelectionFilteredByLimitProximity",
175 +[](Self & self, const context::VectorXs & q) {
176 self.makeSelectionFilteredByLimitProximity(q);
177 },
178 bp::args("self", "q"),
179 "Set the selection to constraints that are near their limits given configuration q.")
180 .def(
181 "active_idx_in_activable",
182 +[](const Self & self) -> const typename Self::VectorOfSize & {
183 return self.active_idx_in_activable();
184 },
185 bp::return_internal_reference<>(),
186 "Vector of active indices in the activable constraints.");
187 return cl;
188 }
189 } // namespace python
190} // namespace pinocchio
Main pinocchio namespace.
Definition treeview.dox:11