Constraint
– Base Class for Holonomic Constraints¶
-
class
trep.
Constraint
(system[, name=None, tolerance=1e-10])¶ Parameters: This is the base class for all holonomic constraints in a
System
. It should never be created directly. Constraints are created by instantiating a specific type of constraint.See trep.constraints - Holonomic Constraints for the built-in types of constraints. Additional constraints can be added through either the Python or C-API.
Holonomic constraints restrict the allowable configurations of a mechanical system. Every constraint has an associated constraint function \(h(q) : Q \rightarrow R\). A configuration \(q\) is acceptable if and only if \(h(q) = 0\).
Constraint Objects¶
-
Constraint.
name
¶ The name of this constraint or
None
.
-
Constraint.
index
¶ The index of the constraint in
System.constraints
. This is also the index of the constraint’s force in any values of \(\lambda\) or its derivatives used throughtrep
.(read-only)
-
Constraint.
tolerance
¶ The constraint should be considered satisfied if \(|h(q)| < tolerance\). This is primarly used by the variational integrator when it finds the next configuration, or by
System.satisfy_constraints()
.
-
Constraint.
h
()¶ Return type: Float
Return the value of the constraint function at the system’s current state. This function should be implemented by derived Constraints.
-
Constraint.
h_dq
(q1)¶ Parameters: q1 ( Config
) – Derivative variableReturn type: Float
Return the derivative of h with respect to q1.
-
Constraint.
h_dqdq
(q1, q2)¶ Parameters: Return type: Float
Return the second derivative of h with respect to q1 and q2.
-
Constraint.
h_dqdqdq
(q1, q2, q3)¶ Parameters: Return type: Float
Return the third derivative of h with respect to q1, q2, and q3.
Verifying Derivatives of the Constraint¶
It is important that the derivatives of h()
are correct. The
easiest way to check their correctness is to approximate each
derivative using numeric differentiation. These methods are provided
to perform this test. The derivatives are only compared at the
current configuration of the system. For improved coverage, try
running each test several times at different configurations.
-
Constraint.
validate_h_dq
(delta=1e-6, tolerance=1e-6, verbose=False)¶ -
Constraint.
validate_h_dqdq
(delta=1e-6, tolerance=1e-6, verbose=False)¶ -
Constraint.
validate_h_dqdqdq
(delta=1e-6, tolerance=1e-6, verbose=False)¶ -
Constraint.
validate_h_dqdqdqdq
(delta=1e-6, tolerance=1e-6, verbose=False)¶ Parameters: - delta – Amount to add to each configuration
- tolerance – Acceptable difference between the calculated and approximate derivatives
- verbose – Boolean to print error and result messages.
Return type: Boolean indicating if all tests passed
Check the derivatives against the approximate numeric derivative calculated from one less derivative (ie, approximate
h_dq()
fromh()
andh_dqdq()
fromh_dq()
).See
System.test_derivative_dq()
for details of the approximation and comparison.