TapeMeasure – Measuring distances between frames¶
-
class
trep.TapeMeasure(system, frames)¶ Parameters: A
TapeMeasureobject calculates the length of the line you get from playing “connect the dots” with the origins of a list of coordinate frames.TapeMeasurecan calculate the length of the line and its derivatives with respect to configuration variables, and the velocity of the length (\(\tfrac{dx}{dt}\)) and its derivatives.(figure here)
TapeMeasurecan be used as the basis for new constraints, potentials, and forces, or used independently for your own calculations.
Length and Velocity Calculations¶
Let \((p_0, p_1, p_2 \dots p_{n} )\) be the points at the origins of the frames specified by
frames. The length, \(x\) is calculated as follows.\[ \begin{align}\begin{aligned}v_k = p_{k+1} - p_k\\x_k = \sqrt{v_k^T v_k}\\x = \sum_{k=0}^{n-1} x_k\end{aligned}\end{align} \]The velocity is calculated by applying the chain rule to \(x\):
\[\dot{x} = \sum_k \sum_i \frac{\partial x_k}{\partial q_i} \dot{q}_i\]These calculations, and their derivatives, are optimized internally to take advantage of the fact that many of these terms are zero, significantly reducing the amount of calculation to do.
Warning
The derivatives of the length and velocity do not exist when the length of any part of the segment is zero.
TapeMeasuredoes not check for this condition and will returnNaNor cause a divide-by-zero error. Be careful to avoid these cases.
TapeMeasure Objects¶
-
TapeMeasure.system¶ The system that the
TapeMeasureworks in.(read-only)
-
TapeMeasure.length()¶ Return type: FloatCalculate the total length of the line segments at the system’s current configuration.
-
TapeMeasure.length_dq(q1)¶ Parameters: q1 ( Config) – Derivative variableReturn type: FloatCalculate the derivative of the length with respect to the value of q1.
-
TapeMeasure.length_dqdq(q1, q2)¶ Parameters: Return type: FloatCalculate the second derivative of the length with respect to the value of q1 and the value of q2.
-
TapeMeasure.length_dqdqdq(q1, q2, q3)¶ Parameters: Return type: FloatCalculate the third derivative of the length with respect to the value of q1, the value of q2, and the value of q3.
-
TapeMeasure.velocity()¶ Return type: Float
-
TapeMeasure.velocity_dq(q1)¶ Parameters: q1 ( Config) – Derivative variableReturn type: FloatCalculate the derivative of the velocity with respect to the value of q1.
-
TapeMeasure.velocity_ddq(dq1)¶ Parameters: dq1 ( Config) – Derivative variableReturn type: FloatCalculate the derivative of the velocity with respect to the velocity of q1.
-
TapeMeasure.velocity_dqdq(q1, q2)¶ Parameters: Return type: FloatCalculate the second derivative of the velocity with respect to the value of q1 and the value of q2.
Visualization¶
-
TapeMeasure.opengl_draw(width=1.0, color=(1.0, 1.0, 1.0))¶ Draw a representation of the line defined by the
TapeMeasurewith the specified width and color. The current OpenGL coordinate system should be the root coordinate frame of theSystem.This method can be called by constraints, forces, and potentials that are based on the
TapeMeasure.
Verifying Derivatives¶
-
TapeMeasure.validate_length_dq([delta=1e-6, tolerance=1e-6, verbose=False])¶ -
TapeMeasure.validate_length_dqdq([delta=1e-6, tolerance=1e-6, verbose=False])¶ -
TapeMeasure.validate_length_dqdqdq([delta=1e-6, tolerance=1e-6, verbose=False])¶ -
TapeMeasure.validate_velocity_dq([delta=1e-6, tolerance=1e-6, verbose=False])¶ -
TapeMeasure.validate_velocity_ddq([delta=1e-6, tolerance=1e-6, verbose=False])¶ -
TapeMeasure.validate_velocity_dqdq([delta=1e-6, tolerance=1e-6, verbose=False])¶ -
TapeMeasure.validate_velocity_ddqdq([delta=1e-6, tolerance=1e-6, verbose=False])¶ Unlike
Constraint,Potential, andForce,TapeMeasureis used directly and all of the calculations are already implemented and verified. These functions are primarily used for testing during developement, but they might be useful for debugging if you are using aTapeMeasureand having trouble.