28 :
public bp::def_visitor<ConstraintModelBasePythonVisitor<ConstraintModelDerived>>
30 typedef ConstraintModelDerived Self;
31 typedef typename ::pinocchio::traits<Self>::ConstraintModel ConstraintModel;
32 typedef typename ::pinocchio::traits<Self>::ConstraintData ConstraintData;
33 typedef typename ::pinocchio::traits<Self>::Scalar Scalar;
35 typedef typename ::pinocchio::traits<Self>::ConstraintSet ConstraintSet;
36 typedef typename ::pinocchio::traits<Self>::JordanOperation JordanOperation;
38 typedef typename ::pinocchio::traits<Self>::ResidualVectorType ResidualVectorType;
39 typedef typename ::pinocchio::traits<Self>::JacobianMatrixType JacobianMatrixType;
40 typedef typename ::pinocchio::traits<Self>::ConeVectorType ConeVectorType;
41 typedef typename ::pinocchio::traits<Self>::ConeScalingVectorType ConeScalingVectorType;
43 static constexpr bool has_baumgarte_corrector =
44 ::pinocchio::traits<Self>::has_baumgarte_corrector;
45 static constexpr bool has_set = ::pinocchio::traits<Self>::has_set;
47 typedef context::Model Model;
48 typedef context::Data Data;
49 typedef std::vector<context::Force> ForceVector;
50 typedef std::vector<context::Motion> MotionVector;
52 typedef typename Self::BooleanVector BooleanVector;
53 typedef typename Self::EigenIndexVector EigenIndexVector;
55 typedef BaumgarteCorrectorParametersTpl<context::Scalar> BaumgarteCorrectorParameters;
58 template<
class PyClass>
59 void visit(PyClass & cl)
const 61 cl.PINOCCHIO_ADD_PROPERTY(Self, name,
"Name of the constraint.")
62#ifndef PINOCCHIO_PYTHON_SKIP_COMPARISON_OPERATIONS 63 .def(bp::self == bp::self)
64 .def(bp::self != bp::self)
66 .def(
"classname", &Self::classname)
67 .staticmethod(
"classname")
68 .def(
"shortname", &Self::shortname,
"Short name of the class.")
70 "createData", &Self::createData,
"Create a Data object for the given constraint model.")
72 "residualSize", &residualSize,
73 (bp::arg(
"self"), bp::arg(
"sel") = ConstraintSelectionType::CURRENT),
74 "Constraint size for the selection.")
76 "symmetricConeResidualSize", &symmetricConeResidualSize,
77 (bp::arg(
"self"), bp::arg(
"sel") = ConstraintSelectionType::CURRENT),
78 "Symmetric cone residual size for the selection.")
80 "setCompliance", &setCompliance,
81 (bp::arg(
"self"), bp::arg(
"vec"), bp::arg(
"sel") = ConstraintSelectionType::CURRENT),
82 "Set the compliance value for the selected constraint.")
84 "retrieveCompliance", &retrieveCompliance,
85 (bp::arg(
"self"), bp::arg(
"sel") = ConstraintSelectionType::CURRENT),
86 "Retrieve the compliance value for the selected constraint.")
88 "setBaumgarteCorrectorParameters", &setBaumgarteCorrectorParameters,
89 (bp::arg(
"self"), bp::arg(
"bp"), bp::arg(
"sel") = ConstraintSelectionType::CURRENT),
90 "Set the Baumgarte parameters.");
91 if constexpr (has_baumgarte_corrector)
94 "baumgarte_corrector_parameters",
96 +[](
const Self & self) ->
const BaumgarteCorrectorParameters & {
97 return self.baumgarte_corrector_parameters();
99 bp::return_internal_reference<>()),
101 +[](Self & self,
const BaumgarteCorrectorParameters &
copy) {
102 self.baumgarte_corrector_parameters() =
copy;
104 bp::return_internal_reference<>()),
105 "Baumgarte parameters associated with the constraint.");
107 if constexpr (has_set)
111 +[](
const Self & self,
const ConstraintData & cdata) -> ConstraintSet {
112 return self.set(cdata);
114 bp::args(
"self",
"constraint_data"),
"Constraint set.");
117 "calc", &calc, bp::args(
"self",
"model",
"data",
"constraint_data"),
118 "Evaluate the constraint values at the current state given by data and store the " 121 "getRowSparsityPattern",
124 const Self & self,
const Model & model,
const Data & data,
125 const ConstraintData & cdata,
const Eigen::Index row_id) -> BooleanVector {
127 self.getRowSparsityPattern(model, data, cdata, row_id, res);
130 "Active colwise sparsity associated with a given row.")
135 const Self & self,
const Model & model,
const Data & data,
136 const ConstraintData & cdata,
const Eigen::Index row_id) -> EigenIndexVector {
137 EigenIndexVector res;
138 self.getRowIndexes(model, data, cdata, row_id, res);
141 "Vector of the active indexes associated with a given row.")
144 (JacobianMatrixType (Self::*)(
const Model &,
const Data &, ConstraintData &)
const)
146 bp::args(
"self",
"model",
"data",
"constraint_data"),
147 "Compute the constraint jacobian.")
149 "jacobianMatrixProduct", &jacobianMatrixProduct,
150 bp::args(
"self",
"model",
"data",
"constraint_data",
"matrix"),
151 "Forward chain rule: return product between the jacobian and a matrix.")
153 "jacobianTransposeMatrixProduct", &jacobianTransposeMatrixProduct,
154 bp::args(
"self",
"model",
"data",
"constraint_data",
"matrix"),
155 "Backward chain rule: return product between the jacobian transpose and a matrix.")
157 "mapConstraintForceToJointSpace", &mapConstraintForceToJointSpace,
158 (bp::arg(
"self"), bp::arg(
"model"), bp::arg(
"data"), bp::arg(
"constraint_data"),
159 bp::arg(
"constraint_forces"), bp::arg(
"joint_forces"),
160 bp::arg(
"reference_frame") = LOCAL),
161 "Map constraint forces to joint space.")
163 "mapJointSpaceToConstraintMotion", &mapJointSpaceToConstraintMotion,
164 (bp::arg(
"self"), bp::arg(
"model"), bp::arg(
"data"), bp::arg(
"constraint_data"),
165 bp::arg(
"joint_motions"), bp::arg(
"joint_generalized_velocity"),
166 bp::arg(
"reference_frame") = LOCAL),
167 "Map joint space quantities to constraint motion.")
169 "appendCouplingConstraintInertias", &appendCouplingConstraintInertias,
170 (bp::arg(
"self"), bp::arg(
"model"), bp::arg(
"data"), bp::arg(
"constraint_data"),
171 bp::arg(
"diagonal_constraint_inertia"), bp::arg(
"reference_frame") = LOCAL),
172 "Append to data the apparent inertia due to the constraint.");
175 static int residualSize(
const Self & self, ConstraintSelectionType sel)
179 case ConstraintSelectionType::CURRENT:
180 return self.residualSize(CurrentSelection());
181 case ConstraintSelectionType::MAXIMAL:
182 return self.residualSize(MaximalSelection());
184 PINOCCHIO_UNREACHABLE();
188 static int symmetricConeResidualSize(
const Self & self, ConstraintSelectionType sel)
192 case ConstraintSelectionType::CURRENT:
193 return self.symmetricConeResidualSize(CurrentSelection());
194 case ConstraintSelectionType::MAXIMAL:
195 return self.symmetricConeResidualSize(MaximalSelection());
197 PINOCCHIO_UNREACHABLE();
201 static int symmetricConeResidualScalingSize(
const Self & self, ConstraintSelectionType sel)
205 case ConstraintSelectionType::CURRENT:
206 return self.symmetricConeResidualScalingSize(CurrentSelection());
207 case ConstraintSelectionType::MAXIMAL:
208 return self.symmetricConeResidualScalingSize(MaximalSelection());
210 PINOCCHIO_UNREACHABLE();
215 setCompliance(Self & self,
const ResidualVectorType & vector, ConstraintSelectionType sel)
219 case ConstraintSelectionType::CURRENT:
220 return self.setCompliance(vector, CurrentSelection());
221 case ConstraintSelectionType::MAXIMAL:
222 return self.setCompliance(vector, MaximalSelection());
226 static ResidualVectorType retrieveCompliance(
const Self & self, ConstraintSelectionType sel)
230 case ConstraintSelectionType::CURRENT: {
231 ResidualVectorType rescs(self.residualSize(CurrentSelection()));
232 self.retrieveCompliance(rescs, CurrentSelection());
235 case ConstraintSelectionType::MAXIMAL: {
236 ResidualVectorType resms(self.residualSize(MaximalSelection()));
237 self.retrieveCompliance(resms, MaximalSelection());
241 PINOCCHIO_UNREACHABLE();
245 static void setBaumgarteCorrectorParameters(
246 Self & self,
const BaumgarteCorrectorParameters &
copy, ConstraintSelectionType sel)
250 case ConstraintSelectionType::CURRENT:
251 return self.setBaumgarteCorrectorParameters(
copy, CurrentSelection());
252 case ConstraintSelectionType::MAXIMAL:
253 return self.setBaumgarteCorrectorParameters(
copy, MaximalSelection());
258 const Self & self,
const Model & model,
const Data & data, ConstraintData & constraint_data)
260 self.calc(model, data, constraint_data);
263 static context::MatrixXs jacobianMatrixProduct(
267 const ConstraintData & constraint_data,
268 const context::RefConstMatrixXs & matrix)
270 context::MatrixXs res = context::MatrixXs::Zero(self.residualSize(), matrix.cols());
271 self.jacobianMatrixProduct(model, data, constraint_data, matrix, res);
275 static context::MatrixXs jacobianTransposeMatrixProduct(
279 const ConstraintData & constraint_data,
280 const context::RefConstMatrixXs & matrix)
282 context::MatrixXs res = context::MatrixXs::Zero(model.nv, matrix.cols());
283 self.jacobianTransposeMatrixProduct(model, data, constraint_data, matrix, res);
287 static context::VectorXs mapConstraintForceToJointSpace(
291 const ConstraintData & cdata,
292 const context::VectorXs & constraint_forces,
293 ForceVector & joint_forces,
296 context::VectorXs joint_torques = context::VectorXs::Zero(model.nv);
300 self.mapConstraintForceToJointSpace(
301 model, data, cdata, constraint_forces, joint_forces, joint_torques, WorldFrameTag());
304 self.mapConstraintForceToJointSpace(
305 model, data, cdata, constraint_forces, joint_forces, joint_torques, LocalFrameTag());
307 case LOCAL_WORLD_ALIGNED:
308 self.mapConstraintForceToJointSpace(
309 model, data, cdata, constraint_forces, joint_forces, joint_torques,
310 LocalWorldAlignedFrameTag());
313 return joint_torques;
316 static context::VectorXs mapJointSpaceToConstraintMotion(
320 const ConstraintData & cdata,
321 const MotionVector & joint_motions,
322 const context::VectorXs & joint_generalized_velocity,
325 context::VectorXs constraint_motions = context::VectorXs::Zero(self.residualSize());
329 self.mapJointSpaceToConstraintMotion(
330 model, data, cdata, joint_motions, joint_generalized_velocity, constraint_motions,
334 self.mapJointSpaceToConstraintMotion(
335 model, data, cdata, joint_motions, joint_generalized_velocity, constraint_motions,
338 case LOCAL_WORLD_ALIGNED:
339 self.mapJointSpaceToConstraintMotion(
340 model, data, cdata, joint_motions, joint_generalized_velocity, constraint_motions,
341 LocalWorldAlignedFrameTag());
344 return constraint_motions;
347 static void appendCouplingConstraintInertias(
351 const ConstraintData & constraint_data,
352 const context::VectorXs & diagonal_constraint_inertia,
358 self.appendCouplingConstraintInertias(
359 model, data, constraint_data, diagonal_constraint_inertia, WorldFrameTag());
362 self.appendCouplingConstraintInertias(
363 model, data, constraint_data, diagonal_constraint_inertia, LocalFrameTag());
365 case LOCAL_WORLD_ALIGNED:
366 self.appendCouplingConstraintInertias(
367 model, data, constraint_data, diagonal_constraint_inertia, LocalWorldAlignedFrameTag());