Karana.Dynamics.Algorithms#

Various dynamics algorithms.

Classes#

Functions#

constraintKinematicsSolver(...)

Return a constraint/inverse kinematics solver instance

evalCentroidalMomentum(→ Karana.Math.SpatialVector)

Calculate the centroidal spatial momentum for the SubTree

evalCentroidalMomentumMatrix(...)

Calculate the centroidal momentum matrix for the SubTree

evalCmLocation(...)

Return the location of the sub-tree CM from the virtual root.

evalComputedTorque(...)

Calculate the computed torque using NE algorithm

evalConstraintPoseGradientMatrix(...)

Compute the gradient matrix for the constraint pose errors.

evalDependentVelCoordinatesMatrix(...)

Compute the dependent velocity coordinates matrix map for the

evalExternalSpatialForce(→ Karana.Math.SpatialVector)

Calculate the overall external spatial force for for the SubTree about

evalForwardDynamics(→ None)

Compute the forward dynamics for a system.

evalFramesOSCM(...)

Calculate the tree system operational space compliance matrix (OSCM)

evalGravitationalPotentialEnergy(→ float)

Calculate the overall gravitational potential energy of the component

evalGravityCompensation(...)

Compute the gravity compensation torque for the system

evalIndepPoseConstraintIndices(...)

Compute the indices for best independent bilateral constraints on the

evalIndepPoseCoordIndices(...)

Compute the best indices for independent Q coordinates for the

evalIndepVelConstraintCoordIndices(...)

Compute the best indices for independent constraints and velocity

evalInverseDynamics(→ None)

Evaluate Newton-Euler inverse dynamics

evalKineticEnergy(→ float)

Calculate the overall kinetic energy of the component bodies in the

evalSerialChainMassMatrixInverse(...)

Calculate serial-chain system mass matrix inverse using {{ SOA }}

evalSpatialInertia(→ Karana.Math.SpatialInertia)

Calculate the overall spatial inertia for a sub-tree

evalSpatialMomentum(→ Karana.Math.SpatialVector)

Calculate the overall spatial momentum for the SubTree

evalSqueezeMatrix(...)

Return a matrix for computing squeeze generalized forces

evalTreeMassMatrixCRB(...)

Calculate the tree system mass matrix using CRB approach

evalTreeMassMatrixInvDyn(...)

Calculate the tree system mass matrix using Newton-Euler inverse

evalTreeMassMatrixInvFwdDyn(...)

Calculate the tree system mass matrix inverse using forward dynamics

evalTreeMassMatrixInverse(...)

Calculate the tree system mass matrix inverse using {{ SOA }}

evalVelCoordinatePartitioning(...)

Compute the best indices for independent and dependent velocity

evalVelocityConstraintMatrix(...)

Compute the velocity constraint matrix.

jacobianGenerator(...)

Return a Jacobian generator for the subtree

stateSpaceGenerator(→ Karana.Math.StateSpace)

Create generator for linearized state space representation of the

modalAnalysis(…)

Perform a modal analysis for the provided SubTree.

Package Contents#

Karana.Dynamics.Algorithms.constraintKinematicsSolver(sg: Karana.Dynamics._SOADyn_pybind11_Py.SubGraph) → Karana.Dynamics._SOADyn_pybind11_Py.ConstraintKinematicsSolver#

Return a constraint/inverse kinematics solver instance

Creates a constraint kinematics (CK) solver for the specified SubGraph and its coordinates and loop constraints. The CK solver uses the CoordData for the SubGraph for the coordinates to solver for. Coordinates can be frozen during the solution process. Only the subhinge coordinates are solved for, and deformation coordinates - if any - are not used.

See the Kinematics Algorithms section for more information.

Parameters:

sg – SubGraph instance

Returns:

The constraint kinematics solver instance

Karana.Dynamics.Algorithms.evalCentroidalMomentum(st: Karana.Dynamics._SOADyn_pybind11_Py.SubTree) → Karana.Math.SpatialVector#

Calculate the centroidal spatial momentum for the SubTree

This is the same as the sub-tree’s spatial momentum (computed by evalSpatialMomentum()), except that this value is referenced about the sub-tree’s center of mass location, though still represented in the virtual root frame. Note that this quantity is conserved in the absence of external forces on the system.

This method does not support deformable bodies.

See the Embedded Control Algorithms section for more information.

Parameters:

st – SubTree instance

Returns:

Spatial momentum.

Karana.Dynamics.Algorithms.evalCentroidalMomentumMatrix(st: Karana.Dynamics._SOADyn_pybind11_Py.SubTree) → Annotated[numpy.typing.NDArray[numpy.float64], [m, n]]#

Calculate the centroidal momentum matrix for the SubTree

This returns the centroidal momentum matrix (CMM) that defines the mapping between the system generalized velocities and the system’s centroidal momentum. Note that this matrix is configuration dependent. This matrix is used in the context the control of legged robots and managing the motion of their CM for stable walking.

See the Embedded Control Algorithms section for more information.

Parameters:

st – SubTree instance

Returns:

The 6xnU centroidal momentum matrix (CMM).

Karana.Dynamics.Algorithms.evalCmLocation(st: Karana.Dynamics._SOADyn_pybind11_Py.SubTree) → Annotated[numpy.typing.NDArray[numpy.float64], [3, 1]]#

Return the location of the sub-tree CM from the virtual root.

Return the current location of the center-of-mass frame for the

whole sub-tree with respect to the virtual root.

See the Embedded Control Algorithms section for more information.

Parameters:

st – SubTree instance

Returns:

The position of the CM with respect to the virtual root.

Karana.Dynamics.Algorithms.evalComputedTorque(st: Karana.Dynamics._SOADyn_pybind11_Py.SubTree) → Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]]#

Calculate the computed torque using NE algorithm

Method to compute the “computed torque”, i.e. the generalized forces needed - usually for a specific generalized acceleration inputs. This assumes that the state (generalized coordinates (Q) and velocities (U) have been set to the desired values in the multibody system, as have the generalized accelerations (Udot). If the generalized forces are T in the system, the returned value from this method subtracts out the input T from the values computed by inverse dynamics.

This method should not to be used for systems with deformable bodies. Systems with deformable bodies are under-actuated, while computed torque only applies to fully actuated systems. Prescribed subhinges and constraints are ignored in this computation.

See the Embedded Control Algorithms section for more information.

Parameters:

st – SubTree instance

Returns:

The computed T generalized forces

Karana.Dynamics.Algorithms.evalConstraintPoseGradientMatrix(sg: Karana.Dynamics._SOADyn_pybind11_Py.SubGraph) → Annotated[numpy.typing.NDArray[numpy.float64], [m, n]]#

Compute the gradient matrix for the constraint pose errors.

Compute the gradient matrix for the constraint pose errors for the bilateral constraints on the SubGraph.

Note that the returned matrix may not have full row rank when the constraints are not all independent.

The SubGraph::constraintErrorAt() and the SubGraph::constraintResidualAt() methods and can be used to look up the constraint instance associated with any specific row index in the returned matrix (based on whether with_constraint is ‘true’ or ‘false’ respectively). Similarly, the SubGraph::coordAt() method can be used to look up the coordinate instance for a specific column index in the returned matrix.

See the Constraints Related Algorithms section for more information.

Parameters:

sg – SubGraph instance

Returns:

The gradient matrix for the constraint pose errors.

Karana.Dynamics.Algorithms.evalDependentVelCoordinatesMatrix(sg: Karana.Dynamics._SOADyn_pybind11_Py.SubGraph, indep_indices: Annotated[numpy.typing.ArrayLike, numpy.int32, [m, 1]] = ..., full: bool = False) → Annotated[numpy.typing.NDArray[numpy.float64], [m, n]]#

Compute the dependent velocity coordinates matrix map for the specified set of independent coordinates

For a SubGraph with constraints, only a subset of the velocity coordinates are independent. This method computes the matrix X that can be used to compute the dependent velocity coordinates, U_d, for the specified set of independent velocity coordinates, U_i, via U_d = X * U_i,

See the Constraints Related Algorithms section for more information.

Parameters:
  • sg – SubGraph instance

  • indep_indices – the list of independent U indices

  • full – if true, the matrix also includes columns for the independent coordinates, else only for the dependent coordinates

Returns:

the dependent coordinates mapping matrix

Karana.Dynamics.Algorithms.evalExternalSpatialForce(st: Karana.Dynamics._SOADyn_pybind11_Py.SubTree) → Karana.Math.SpatialVector#

Calculate the overall external spatial force for for the SubTree about its CM

The computed value includes external force contributions from all of the force nodes on all the bodies (including active contact nodes) as well as any constraint forces from constraint nodes. The returned value is referenced about, and represented in the sub-tree’s center of mass frame.

See the Embedded Control Algorithms section for more information.

Parameters:

st – SubTree instance

Returns:

The overall external spatial force.

Karana.Dynamics.Algorithms.evalForwardDynamics(st: Karana.Dynamics._SOADyn_pybind11_Py.SubTree) → None#

Compute the forward dynamics for a system.

This uses tree-augmented forward dynamics if there are with loop constraints, and tree forward dynamics if there are no loop constraints.

The tree-augmented algorithm solves the graph system forward dynamics using recursive {{ SOA }} recursive algorithms with exact enforcement of the loop constraints. This algorithm does not require the computation of inversion of the mass matrix.

The tree forward dynamics uses Articulated Body Inertia (ATBI) based forward dynamics.

See the Forward Dynamics Algorithms section for more information.

Parameters:

st – SubTree instance

Karana.Dynamics.Algorithms.evalFramesOSCM(st: Karana.Dynamics._SOADyn_pybind11_Py.SubTree, body_frames: collections.abc.Sequence[Karana.Frame.Frame], subhinges: collections.abc.Sequence[Karana.Dynamics._SOADyn_pybind11_Py.PhysicalSubhinge] = []) → Annotated[numpy.typing.NDArray[numpy.float64], [m, n]]#

Calculate the tree system operational space compliance matrix (OSCM)

The OSCM is defined at J*M^{-1}*J^*, where J is the Jacobian matrix, and M is the mass matrix of the system. This method does not use this brute force expression. Instead it uses the {{ SOA }} recursive methods to do this computation without ever computing the mass matrix or its inverse, or even the Jacobian matrix itself.

In addition, one or more subhinges can also be provided. The returned matrix will include additional mass matrix inverse rows and columns for these subhinges. This is equivalent to computing the OSCM for the “extended Jacobian” defined as [J \ E], where E is a selector matrix that picks out a subset of the subhinges in the system. While the rows and columns associated with the frames define a mapping between spatial forces and spatial accelerations, the subhinge rows and columns define the mapping between generalized forces and generalized accelerations. The off-diagonal sub-blocks define cross-term mappings.

If no subhinges are specified, the returned matrix is the regular OSCM, and if no frames are specified, the returned matrix is the sub- block of the mass matrix inverse with rows and columns for the specified subhinges. This more general form of the OSCM allows users to properly handle a mix of constraints from the task and joint spaces.

See the System Properties Algorithms section for more information.

Parameters:
  • st – SubTree instance

  • body_frames – list of Frame instances to compute the OSCM for

  • subhinges – list of physical subhinge mass matrix inverse contributions to include

Returns:

The tree OSCM matrix

Karana.Dynamics.Algorithms.evalGravitationalPotentialEnergy(st: Karana.Dynamics._SOADyn_pybind11_Py.SubTree) → float#

Calculate the overall gravitational potential energy of the component bodies in the SubTree

See the System Properties Algorithms section for more information.

Parameters:

st – SubTree instance

Returns:

Gravitational potential energy.

Karana.Dynamics.Algorithms.evalGravityCompensation(st: Karana.Dynamics._SOADyn_pybind11_Py.SubTree) → Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]]#

Compute the gravity compensation torque for the system

Compute the generalized forces needed to support the gravitational load on the system. This method automatically takes into account additional bodies that are attached or detached from the system.

See the Embedded Control Algorithms section for more information.

Parameters:

st – SubTree instance

Returns:

The vector of generalized forces.

Karana.Dynamics.Algorithms.evalIndepPoseConstraintIndices(sg: Karana.Dynamics._SOADyn_pybind11_Py.SubGraph) → Annotated[numpy.typing.NDArray[numpy.int32], [m, 1]]#

Compute the indices for best independent bilateral constraints on the system based on the pose gradients matrix map.

For a SubGraph with constraints, only a subset of the Q pose-level constraints may be independent. This method computes the indices of the independent constraints.

Since the pose and velocity level constraints may not be the same, the results from this method may not match the constraint and coordinate indices returned by the evalIndepVelConstraintCoordIndices() method.

See the Constraints Related Algorithms section for more information.

Parameters:

sg – SubGraph instance

Returns:

a pair consisting of a list of independent constraint indices, and a list of independent coordinate indices based on the pose-level constraints

Karana.Dynamics.Algorithms.evalIndepPoseCoordIndices(sg: Karana.Dynamics._SOADyn_pybind11_Py.SubGraph, available_indices: Annotated[numpy.typing.ArrayLike, numpy.int32, [m, 1]] = ...) → Annotated[numpy.typing.NDArray[numpy.int32], [m, 1]]#

Compute the best indices for independent Q coordinates for the bilateral constraints on the system

For a SubGraph with constraints, only a subset of the Q pose-level coordinates are independent. This method computes the indices of the coordinates in the Q vector that are best choice for independent coordinates (at the current configuration). A non-empty available_indices list can be used to restrict the pool of indices to pick the independent coordinates from.

Since the pose and velocity level constraints may not be the same, the results from this method may not match the constraint and coordinate indices returned by the evalIndepVelConstraintCoordIndices() method.

See the Constraints Related Algorithms section for more information.

Parameters:
  • sg – SubGraph instance

  • available_indices – If non-empty, the indices to pick the independent coordinates from

Returns:

a list of independent coordinate indices based on the pose-level constraints

Karana.Dynamics.Algorithms.evalIndepVelConstraintCoordIndices(sg: Karana.Dynamics._SOADyn_pybind11_Py.SubGraph, available_indices: Annotated[numpy.typing.ArrayLike, numpy.int32, [m, 1]] = ...) → tuple[Annotated[numpy.typing.NDArray[numpy.int32], [m, 1]], Annotated[numpy.typing.NDArray[numpy.int32], [m, 1]]]#

Compute the best indices for independent constraints and velocity coordinates using the velocity constraint matrix

For a SubGraph with constraints, only a subset of the U velocity coordinates are independent (and not all constraints may be independent). This method computes the indices of the independent constraints, and the indices of the coordinates in the U vector that are best choice for independent velocity coordinates (at the current configuration).

Since the pose and velocity level constraints may not be the same, the results from this method may not match the constraint and coordinate indices returned by the evalIndepPoseCoordIndices() and evalIndepPoseConstraintIndices() methods.

See the Constraints Related Algorithms section for more information.

Parameters:
  • sg – SubGraph instance

  • available_indices – the list of indices to pick the independent ones from

Returns:

a pair consisting of a list of independent constraint indices, and a list of independent coordinate indices based on the velocity- level constraints

Karana.Dynamics.Algorithms.evalInverseDynamics(st: Karana.Dynamics._SOADyn_pybind11_Py.SubTree) → None#

Evaluate Newton-Euler inverse dynamics

See the Embedded Control Algorithms section for more information.

Parameters:

st – SubTree instance

Karana.Dynamics.Algorithms.evalKineticEnergy(st: Karana.Dynamics._SOADyn_pybind11_Py.SubTree) → float#

Calculate the overall kinetic energy of the component bodies in the SubTree

See the System Properties Algorithms section for more information.

Parameters:

st – SubTree instance

Returns:

Kinetic energy.

Karana.Dynamics.Algorithms.evalSerialChainMassMatrixInverse(subtree: Karana.Dynamics._SOADyn_pybind11_Py.SubTree, coord_data: Karana.Dynamics._SOADyn_pybind11_Py.CoordData = None) → Annotated[numpy.typing.NDArray[numpy.float64], [m, n]]#

Calculate serial-chain system mass matrix inverse using {{ SOA }} operator-based decomposition expressions

This method does not require the mass matrix or matrix inversions to compute the mass matrix inverse! The algorithm instead takes advantage of an analytical operator based decomposition of the mass matrix inverse to carry out the computation much lower cost.

A CoordData argument can be specified to set the specific order for the rows and columns in the computed mass matrix inverse. This method cannot be used for systems containing deformable bodies. This mass matrix inverse computation can also be done via the more general evalTreeMassMatrixInverse() which also works for deformable bodies. We however also have this method since it is considerably simpler for the simpler serial-chain topology.

This method does not allow internal 6 dof hinges to avoid ambiguities about whether mass properties should be coupled across such hinges. Also the prescribed motion flag for any subhinge that has been enabled is reset. This is to ensure that the mass matrix computed from this method are consistent with the results from the alternative dynamics based computation methods.

See the System Properties Algorithms section for more information.

Parameters:
  • st – SubTree instance

  • coord_data – CoordData to specify the order of the mass matrix inverse’s rows and columns

Returns:

The serial-chain mass matrix inverse

Karana.Dynamics.Algorithms.evalSpatialInertia(st: Karana.Dynamics._SOADyn_pybind11_Py.SubTree, ref_frame: Karana.Frame.Frame = None) → Karana.Math.SpatialInertia#

Calculate the overall spatial inertia for a sub-tree

Return the overall spatial inertia of all the bodies in the sub-tree about the reference frame. The multibody virtual root serves as the default reference frame.

See the System Properties Algorithms section for more information.

Parameters:
  • st – SubTree instance

  • ref_frame – reference frame for the spatial inertia (default: the virtual root)

Returns:

The overall tree spatial inertia

Karana.Dynamics.Algorithms.evalSpatialMomentum(st: Karana.Dynamics._SOADyn_pybind11_Py.SubTree) → Karana.Math.SpatialVector#

Calculate the overall spatial momentum for the SubTree

The returned value is by default is referenced about, and represented in the virtual root frame. Note that this quantity is conserved in the absence of external forces on the system.

See the Embedded Control Algorithms section for more information.

Parameters:

st – SubTree instance

Returns:

Spatial momentum.

Karana.Dynamics.Algorithms.evalSqueezeMatrix(sg: Karana.Dynamics._SOADyn_pybind11_Py.SubGraph) → Annotated[numpy.typing.NDArray[numpy.float64], [m, n]]#

Return a matrix for computing squeeze generalized forces

Compute the squeeze matrix, S, whose column space consists of “squeeze” generalized forces, i.e. generalized forces that only effect internal forces within the constrained multibody and do not induce any motion. Thus, the generalized force, S*x, for any vector x will not induce any motion. The row dimension is nU(), while the column dimension is the size of the constraints on the system.

Note that the returned matrix may not have full column rank when the constraints are not all independent. The evalIndepVelConstraintCoordIndices() method can be used to check for the columns that are independent.

See the Constraints Related Algorithms section for more information.

Parameters:

sg – SubGraph instance

Returns:

The squeeze matrix.

Karana.Dynamics.Algorithms.evalTreeMassMatrixCRB(subtree: Karana.Dynamics._SOADyn_pybind11_Py.SubTree, coord_data: Karana.Dynamics._SOADyn_pybind11_Py.CoordData = None) → Annotated[numpy.typing.NDArray[numpy.float64], [m, n]]#

Calculate the tree system mass matrix using CRB approach

This method uses the composite rigid body inertias (CRB) recursive method for computing the mass matrix

See the System Properties Algorithms section for more information.

This method does not allow internal 6 dof hinges to avoid ambiguities about whether mass properties should be coupled across such hinges. Also the prescribed motion flag for any subhinge that has been enabled is reset. This is to ensure that the mass matrix computed from this method are consistent with the results from the alternative dynamics based computation methods.

Parameters:
  • st – SubTree instance

  • coord_data – CoordData to specify the order of the mass matrix rows and columns

Returns:

The tree mass matrix

Karana.Dynamics.Algorithms.evalTreeMassMatrixInvDyn(subtree: Karana.Dynamics._SOADyn_pybind11_Py.SubTree, coord_data: Karana.Dynamics._SOADyn_pybind11_Py.CoordData = None) → Annotated[numpy.typing.NDArray[numpy.float64], [m, n]]#

Calculate the tree system mass matrix using Newton-Euler inverse dynamics

Calculate the tree system mass matrix using NE inverse dynamics. A CoordData argument can be specified to set the specific order for the rows and columns in the computed mass matrix.

This method does not currently support deformable bodies.

This method does not allow internal 6 dof hinges to avoid ambiguities about whether mass properties should be coupled across such hinges. Also the prescribed motion flag for any subhinge that has been enabled is reset. This is to ensure that the mass matrix computed from this method are consistent with the results from the alternative dynamics based computation methods.

See the System Properties Algorithms section for more information.

Parameters:
  • st – SubTree instance

  • coord_data – CoordData to specify the order of the mass matrix rows and columns

Returns:

The tree mass matrix

Karana.Dynamics.Algorithms.evalTreeMassMatrixInvFwdDyn(subtree: Karana.Dynamics._SOADyn_pybind11_Py.SubTree, coord_data: Karana.Dynamics._SOADyn_pybind11_Py.CoordData = None) → Annotated[numpy.typing.NDArray[numpy.float64], [m, n]]#

Calculate the tree system mass matrix inverse using forward dynamics

Calculate the tree system mass matrix inverse using ATBI forward dynamics. A CoordData argument can be specified to set the specific order for the rows and columns in the computed mass matrix inverse. This method currently supports physical rigid and flexible bodies, but not compound bodies.

This method does not allow internal 6 dof hinges to avoid ambiguities about whether mass properties should be coupled across such hinges. Also the prescribed motion flag for any subhinge that has been enabled is reset. This is to ensure that the mass matrix computed from this method are consistent with the results from the alternative dynamics based computation methods.

See the System Properties Algorithms section for more information.

Parameters:
  • st – SubTree instance

  • coord_data – CoordData to specify the order of the mass matrix inverse’s rows and columns

Returns:

The tree mass matrix inverse

Karana.Dynamics.Algorithms.evalTreeMassMatrixInverse(subtree: Karana.Dynamics._SOADyn_pybind11_Py.SubTree, coord_data: Karana.Dynamics._SOADyn_pybind11_Py.CoordData = None) → Annotated[numpy.typing.NDArray[numpy.float64], [m, n]]#

Calculate the tree system mass matrix inverse using {{ SOA }} decomposition expressions

This method does not require the mass matrix or matrix inversions to compute the mass matrix inverse! The algorithm instead takes advantage of an analytical operator based decomposition of the mass matrix inverse to carry out the computation much lower cost. For serial-chain system, the mass matrix inverse can also be computed using the evalSerialChainMassMatrixInverse() specifically for such systems.

A CoordData argument can be specified to set the specific order for the rows and columns in the computed mass matrix inverse. This method is currently limited to physical and rigid bodies.

This method supports both rigid and deformable bodies.

This method does not allow internal 6 dof hinges to avoid ambiguities about whether mass properties should be coupled across such hinges. Also the prescribed motion flag for any subhinge that has been enabled is reset. This is to ensure that the mass matrix computed from this method are consistent with the results from the alternative dynamics based computation methods.

See the System Properties Algorithms section for more information.

Parameters:
  • st – SubTree instance

  • coord_data – CoordData to specify the order of the mass matrix inverse’s rows and columns

Returns:

The tree mass matrix inverse

Karana.Dynamics.Algorithms.evalVelCoordinatePartitioning(sg: Karana.Dynamics._SOADyn_pybind11_Py.SubGraph, available_indices: Annotated[numpy.typing.ArrayLike, numpy.int32, [m, 1]] = ...) → tuple[Annotated[numpy.typing.NDArray[numpy.int32], [m, 1]], Annotated[numpy.typing.NDArray[numpy.float64], [m, n]]]#

Compute the best indices for independent and dependent velocity coordinates matrix map

For a SubGraph with constraints, only a subset of the velocity coordinates are independent. This method computes the indices of the coordinates in the U vector that are best choice for independent velocity coordinates (at the current configuration). It also returns a matrix X that can be used to compute the dependent velocity coordinates, U_d, for a set of independent velocity coordinates, U_i, via U_d = X * U_i,

See the Constraints Related Algorithms section for more information.

Parameters:
  • sg – SubGraph instance

  • available_indices – the list of indices to pick the independent ones from

Returns:

The list of independent coordinate indices and the dependent coordinate mapping matrix

Karana.Dynamics.Algorithms.evalVelocityConstraintMatrix(sg: Karana.Dynamics._SOADyn_pybind11_Py.SubGraph, with_constraints: bool) → Annotated[numpy.typing.NDArray[numpy.float64], [m, n]]#

Compute the velocity constraint matrix.

Compute the velocity constraint matrix, Gc, such that Gc * U = 0, i.e. the matrix whose null space contains the generalized velocity U values that satisfy the loop and coordinate constraints on the SubGraph.

If “with_constraints” is true, then Gc’s columns include ones for the loop hinge constraint coordinates, and the block row for each constraint contain the mapping to their constraint errors.

On the other hand, if “with_constraints” is false, Gc’s columns exclude ones for the constraint coordinates, and the block row for each loop hinge constraint maps to the residual vector for each constraint. In the latter case, the number of columns and rows shrink equally by the number of constraint coordinates.

Note that the returned matrix may not have full row rank when the constraints are not all independent. The evalIndepVelConstraintCoordIndices() method can be used to check for the rows that are independent.

The SubGraph::constraintErrorAt() and the SubGraph::constraintResidualAt() methods and can be used to look up the constraint instance associated with any specific row index in the returned matrix (based on whether with_constraint is ‘true’ or ‘false’ respectively). Similarly, the SubGraph::coordAt() method can be used to look up the coordinate instance for a specific column index in the returned matrix.

See the Constraints Related Algorithms section for more information.

Parameters:
  • sg – SubGraph instance

  • with_constraints – If true, columns for the cutjoint loop constraint coords are included

Returns:

The velocity constraint matrix.

Karana.Dynamics.Algorithms.jacobianGenerator(f2fs: collections.abc.Sequence[Karana.Frame.FrameToFrame], cd: Karana.Dynamics._SOADyn_pybind11_Py.CoordData) → Karana.Dynamics._SOADyn_pybind11_Py.MultiJacobianGenerator#

Return a Jacobian generator for the subtree

Create a Jacobian generator object for the specified SubGraph and its coordinates and the list source/target frame pairs in the list of frame2frames. Note that the resulting jacobian and pose gradient matrices will exclude columns for any coordinates frozen in the coord data of the subtree.

See the Kinematics Algorithms section for more information.

Parameters:
  • f2fs – list of FrameToFrames to compute the Jacobian for

  • cd – the CoordData that specify the columns in the computed Jacobian

Returns:

The Jacobian generator instance

Karana.Dynamics.Algorithms.stateSpaceGenerator(mm: Karana.Dynamics._SOADyn_pybind11_Py.ModelManager, n_inputs: SupportsInt | SupportsIndex, n_outputs: SupportsInt | SupportsIndex, u_fn: collections.abc.Callable[[Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]], Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]], None], y_fn: collections.abc.Callable[[Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]], Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]], Annotated[numpy.typing.NDArray[numpy.float64], [m, 1], flags.writeable]], None]) → Karana.Math.StateSpace#

Create generator for linearized state space representation of the system

Method to create a StateSpace object for creating (A,B,C,D) state space linear system matrices for sub-tree multibody system. The returned state space generation object’s generate(x,u) can be called to compute the state space matrices at the state and input vector set point values about which the linearization should be carried out.

The first two inputs are the size of the inputs and outputs for the state space system. The u_fn argument is a user-defined function that takes (x,u) arguments and sets the appropriate forces, gravity etc values for the in the multibody system for dynamics computations. The y_fn argument takes (x, u, y) arguments and computes the outputs y for the (x, u) and state and input values.

See the Guidance and Control Related Algorithms section for more information.

Parameters:
  • mm – The ModelManager whose SubTree and models will be used to generate the StateSpace.

  • n_inputs – number of inputs

  • n_outputs – number of outputs

  • u_fn – function to evaluate the state derivative value for an input value

  • y_fn – function to evaluate the output value for a given state

Returns:

State space generator instance

class Karana.Dynamics.Algorithms.ModalAnalysis(w: Karana.Math.Ktyping.Vec | Karana.Math.Ktyping.AngularVelocity[Karana.Math.Ktyping.Vec], phi: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, n]], coord_data: Karana.Dynamics._SOADyn_pybind11_Py.CoordData, q_i: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]])#
coord_data: Karana.Dynamics._SOADyn_pybind11_Py.CoordData#
showMode(mode: SupportsInt | SupportsIndex, scene: Karana.Scene.ProxyScene, amplitude: SupportsFloat | SupportsIndex = 1.0, steps: SupportsInt | SupportsIndex = 100, pause: SupportsFloat | SupportsIndex | numpy.timedelta64 = 0.01) → None#

Show the mode shape using a sine wave.

Parameters:
  • mode – The mode to show.

  • scene – The ProxyScene to update when showing the mode

  • amplitude – The amplitude of the sine wave.

  • steps – The number of steps to take.

  • pause – The time to sleep between steps.

property phi: Annotated[numpy.typing.NDArray[numpy.float64], [m, n]]#
property q_i: Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]]#
property w: Karana.Math.Ktyping.AngularVelocity[Karana.Math.Ktyping.Vec]#
Karana.Dynamics.Algorithms.modalAnalysis(mm: Karana.Dynamics._SOADyn_pybind11_Py.ModelManager, tol: SupportsFloat | SupportsIndex = 0.001, step_size: SupportsFloat | SupportsIndex | None = None) → ModalAnalysis#
Karana.Dynamics.Algorithms.modalAnalysis(body: Karana.Dynamics._SOAFlexDyn_pybind11_Py.PhysicalModalBody, tol: SupportsFloat | SupportsIndex = 0.001, step_size: SupportsFloat | SupportsIndex | None = None) → ModalAnalysis
Karana.Dynamics.Algorithms.modalAnalysis(subtree: Karana.Dynamics._SOADyn_pybind11_Py.SubTree, tol: SupportsFloat | SupportsIndex = 0.001, step_size: SupportsFloat | SupportsIndex | None = None) → ModalAnalysis

Perform a modal analysis for the provided SubTree.

This creates a state space model for the SubTree about the current configuration, and then solves an eigenproblem to its the frequencies and mode shapes.

See the Guidance and Control Related Algorithms section for more information.

Parameters:
  • subtree – The SubTree to do the modal analysis for.

  • tol – The tolerance used to eliminate rigid-body modes.

  • step_size – The step size to use for finite differences when performing the modal analysis.

Returns:

the eigen problem solution for the state space modal