dair_pll.drake_state_converter
Utility classes for interfacing with Drake’s internal state format.
Classes herein mainly support the implementation of DrakeStateConverter. In
order to make Drake states compatible with available StateSpace
inheriting classes, users must define the drake system by a collection of
URDF files, each of which contains a model for exactly one floating- or
fixed-base rigid multibody chain. This allows for the system to be modeled as
having a ProductSpace state space, where each factor space is a
FloatingBaseSpace or FixedBaseSpace.
For flexible usage, the conversion is between contexts and numpy ndarray
types. This is particularly useful as it allows pydrake symbolic types to
be used, facilitating differentiable geometric analysis of the relationship
between the coordinate systems in multibody_terms.py.
- dair_pll.drake_state_converter.state_ndarray_reformat(x)[source]
Resizes Drake coordinates to
StateSpacebatch.- Return type:
- dair_pll.drake_state_converter.drake_ndarray_reformat(x)[source]
Resizes
StateSpacebatch to Drake coordinates.- Return type:
- class dair_pll.drake_state_converter.DrakeFloatingBaseStateConverter[source]
Bases:
objectConverts between the
np.ndarraystate coordinates of a Drake MultibodyPlant model instance and a floating-base open kinematic chain.When a Drake model instance is a single floating-base rigid chain, it represents the configuration in tangent bundle of SE(3) x R^n_joints, with coordinates as a quaternion; world-frame floating base c.o.m., joint positions/angles, world-axes floating base angular/linear velocity, and joint velocities.
Conversion between coordinate sets is then simply a frame transformation on the angular velocity between world and floating base frame.
- class dair_pll.drake_state_converter.DrakeFixedBaseStateConverter[source]
Bases:
objectConverts between the
np.ndarraystate coordinates of a Drake MultibodyPlant model instance and a fixed-base open kinematic chain.When a Drake model instance is a single fixed-base rigid chain, it represents the configuration in tangent bundle of R^n_joints, with the same exact coordinate system that
FixedBaseSpaceuses. Therefore, conversion between these types is a simple passthrough that copies the coordinates in memory.
- class dair_pll.drake_state_converter.DrakeModelStateConverterFactory[source]
Bases:
objectFactory class for selecting Drake-to-
BaseSpacecoordinate conversions.
- class dair_pll.drake_state_converter.DrakeStateConverter[source]
Bases:
objectUtility namespace for conversion between Drake state format and
ProductSpaceformats.Given a
MultibodyPlantand a complete list of its models,DrakeStateConverterconverts between a numpyndarrayandContextrepresentation of the state space. This class leverages the one-open-kinematic-chain-per-model assumption to iterate over the models, and convert the factor space coordinates withDrakeModelStateConverterFactory.- static context_to_state(plant, plant_context, model_ids, space)[source]
Retrieves
ProductSpace-formatted state from plant’s context.- Parameters:
plant (
MultibodyPlant) – plant from which to retrieve state.plant_context (
Context) – plant’s context which stores its state.model_ids (
List[ModelInstanceIndex]) – List of plant’s modelsspace (
ProductSpace) – state space of output state.
- Return type:
- Returns:
(space.n_x,) current state of plant.
- static state_to_context(plant, plant_context, x, model_ids, space)[source]
Transforms and assigns
ProductSpace-formatted state in plant’s mutable context.- Parameters:
plant (
MultibodyPlant) – plant in which to store state.plant_context (
Context) – plant’s context which stores its state.x (
ndarray) – (1, space.n_x) or (space.n_x,) state.model_ids (
List[ModelInstanceIndex]) – Mapping from plant’s model names to instancesspace (
ProductSpace) – state space of output state.
- Return type: