dair_pll.multibody_termsο
Mathematical implementation of multibody dynamics terms calculations.
This file implements the MultibodyTerms type, which interprets a
list of urdfs as a learnable Lagrangian system with contact, taking the state
space from the corresponding MultibodyPlantDiagram as a given, and
interpreting the various inertial and geometric terms stored within it as
initial conditions of learnable parameters.
Multibody dynamics can be derived from four functions of state [q,v]:
M(q), the generalized mass-matrix
F(q), the non-contact/Lagrangian force terms.
phi(q), the signed distance between collision candidates.
J(q), the contact-frame velocity Jacobian between collision candidates.
The first two terms depend solely on state and inertial properties, and parameterize the contact-free Lagrangian dynamics as:
dv/dt = (M(q) ** (-1)) * F(q)
These terms are accordingly encapsulated in a LagrangianTerms
instance.
The latter two terms depend solely on the geometry of bodies coming into
contact, and are encapsulated in a ContactTerms instance.
For both sets of terms, we derive their functional form either directly or in
part through symbolic analysis of the MultibodyPlant of the
associated MultibodyPlantDiagram. The MultibodyTerms
object manages the symbolic calculation and has corresponding
LagrangianTerms and ContactTerms members.
- dair_pll.multibody_terms.init_symbolic_plant_context_and_state(plant_diagram)[source]ο
- Generates a symbolic interface for a - MultibodyPlantDiagram.- Generates a new Drake - Expressiondata type state in- StateSpaceformat, and sets this state inside a new context for a symbolic version of the diagramβs- MultibodyPlant.- Parameters:
- plant_diagram ( - MultibodyPlantDiagram) β Drake MultibodyPlant diagram to convert to symbolic.
- Return type:
- Tuple[- MultibodyPlant_π£Expressionπ€,- Context,- ndarray,- ndarray]
- Returns:
- New symbolic plant. New plantβs context, with symbolic states set. (n_q,) symbolic - StateSpaceconfiguration. (n_v,) symbolic- StateSpacevelocity.
 
- class dair_pll.multibody_terms.LagrangianTerms(plant_diagram)[source]ο
- Bases: - Module- Container class for non-contact/Lagrangian dynamics terms. - Accepts batched pytorch callback functions for M(q) and F(q) and related contact terms in - thetaformat (see- inertia.py).- Inits - LagrangianTermswith prescribed parameters and functional forms.- Parameters:
- plant_diagram ( - MultibodyPlantDiagram) β Drake MultibodyPlant diagram to extract terms from.
 - 
mass_matrix: typing.Optional[typing.Callable[[Tensor,Tensor],Tensor]]ο
 - 
lagrangian_forces: typing.Optional[typing.Callable[[Tensor,Tensor,Tensor,Tensor],Tensor]]ο
 - 
inertial_parameters: torch.nn.parameter.Parameterο
 - static extract_body_parameters_and_variables(plant, model_ids, context)[source]ο
- Generates parameterization and symbolic variables for all bodies. - For a multibody plant, finds all bodies that should have inertial properties; extracts the current values as an initial condition for - theta-format learnable parameters, and sets new symbolic versions of these variables.- Parameters:
- plant ( - MultibodyPlant_π£Expressionπ€) β Symbolic plant from which to extract parameterization.
- model_ids ( - List[- ModelInstanceIndex]) β List of models in plant.
- context ( - Context) β Plantβs symbolic context.
 
- Return type:
- Returns:
- (n_bodies, 10) - thetaparameters initial conditions. (n_bodies, 10) symbolic inertial variables.
 
 
- dair_pll.multibody_terms.make_configuration_callback(expression, q)[source]ο
- Converts drake symbolic expression to pytorch function via - drake_pytorch.
- class dair_pll.multibody_terms.ContactTerms(plant_diagram)[source]ο
- Bases: - Module- Container class for contact-related dynamics terms. - Derives batched pytorch callback functions for collision geometry position and velocity kinematics from a - MultibodyPlantDiagram.- Inits - ContactTermswith prescribed kinematics and geometries.- phi(q) and J(q) are calculated implicitly from kinematics and - n_g == len(geometries)collision geometries C.- Parameters:
- plant_diagram ( - MultibodyPlantDiagram) β Drake MultibodyPlant diagram to extract terms from.
 - 
geometry_local_poses: torch.nn.parameter.Parameterο
 - 
geometry_rotations: typing.Optional[typing.Callable[[Tensor],Tensor]]ο
 - 
geometry_translations: typing.Optional[typing.Callable[[Tensor],Tensor]]ο
 - 
geometry_spatial_jacobians: typing.Optional[typing.Callable[[Tensor],Tensor]]ο
 - 
geometries: torch.nn.modules.container.ModuleListο
 - 
friction_params: torch.nn.parameter.Parameterο
 - 
collision_candidates: torch.Tensorο
 - get_friction_coefficients()[source]ο
- From the stored - friction_params, compute the friction coefficient as its absolute value.- Return type:
 
 - static extract_geometries_and_kinematics(plant, inspector, geometry_ids, context)[source]ο
- Extracts modules and kinematics of list of geometries G. - Parameters:
- plant ( - MultibodyPlant_π£Expressionπ€) β Multibody plant from which terms are extracted.
- inspector ( - SceneGraphInspector) β Scene graph inspector associated with plant.
- geometry_ids ( - List[- GeometryId]) β List of geometries to model.
- context ( - Context) β Plantβs context with symbolic state.
 
- Return type:
- Tuple[- List[- CollisionGeometry],- List[- ndarray],- List[- ndarray],- List[- ndarray]]
- Returns:
- List of - CollisionGeometrymodels with one-to-one correspondence with provided geometries. List[(3,3)] of corresponding rotation matrices R_WG List[(3,)] of corresponding geometry frame origins p_WoGo_W List[(6,n_v)] of geometry spatial jacobians w.r.t. drake velocity coordinates, J(v_drake)_V_WG_W
 
 - static assemble_velocity_jacobian(R_CW, Jv_V_WC_W, p_CoCc_C)[source]ο
- Helper method to generate velocity jacobian from contact information. - Parameters:
- R_CW β (*, n_c, 3, 3) Rotation of world frame w.r.t. geometry frame. 
- Jv_V_WC_W β (*, 1, 6, n_v) Geometry spatial velocity Jacobian. 
- p_CoCc_C β (*, n_c, 3) Geometry-frame contact points. 
 
- Returns:
- (*, n_c, 3, n_v) World-frame contact point translational velocity Jacobian. 
 
 - static relative_velocity_to_contact_jacobian(Jv_v_W_BcAc_F, mu)[source]ο
- Helper method to reorder contact Jacobian columns. 
 
- class dair_pll.multibody_terms.MultibodyTerms(urdfs)[source]ο
- Bases: - Module- Derives and manages computation of terms of multibody dynamics with contact. - Primarily - Inits - MultibodyTermsfor system described in URDFs- Interpretation is performed as a thin wrapper around - LagrangianTermsand- ContactTerms.- As this module is also responsible for evaluating updated URDF representations, the associations between bodies and geometries is also tracked to enable URDF rendering in - MultibodyTerms.EvalUrdfRepresentationand Tensorboard logging in- MultibodyTerms.scalars.- Parameters:
 - forward(q, v, u)[source]ο
- Evaluates multibody system dynamics terms at given state and input. - Calculation is performed as a thin wrapper around - LagrangianTermsand- ContactTerms. For convenience, this function also returns the Delassus operator D(q) = J(q)^T inv(M(q)) J(q).- Parameters:
- Return type:
- Returns:
- (*, 3 * n_collisions, 3 * n_collisions) Delassus operator D(q). (*, n_v, n_v) mass matrix batch M(q). (*, 3 * n_collisions, n_v) contact Jacobian J(q). (*, n_collisions) signed distance phi(q). (*, n_v) Contact-free acceleration inv(M(q)) * F(q). 
 
 - 
lagrangian_terms: dair_pll.multibody_terms.LagrangianTermsο
 - 
contact_terms: dair_pll.multibody_terms.ContactTermsο
 - 
geometry_body_assignment: typing.Dict[str,typing.List[int]]ο
 - 
plant_diagram: dair_pll.drake_utils.MultibodyPlantDiagramο
 - 
urdfs: typing.Dict[str,str]ο