dair_pll.geometry
Collision geometry representation for multibody systems.
Each type of collision geometry is modeled as a class inheriting from the
CollisionGeometry
abstract type. Different types of inheriting geometries
will need to resolve collisions in unique ways, but one interface is always
expected: a list of scalars to track during training.
Many collision geometries, such as boxes and cylinders, fall into the class
of bounded (compact) convex shapes. A general interface is defined in the
abstract BoundedConvexCollisionGeometry
type, which returns a set of
witness points given support hyperplane directions. One implementation is
the SparseVertexConvexCollisionGeometry
type, which finds these points
via brute force optimization over a short list of vertices.
All collision geometries implemented here mirror a Drake Shape
object. A
general purpose converter is implemented in
PydrakeToCollisionGeometryFactory
.
- class dair_pll.geometry.CollisionGeometry(*args, **kwargs)[source]
-
Abstract interface for collision geometries.
Collision geometries have heterogeneous implementation depending on the type of shape. This class mainly enforces the implementation of bookkeeping interfaces.
When two collision geometries are evaluated for collision with
GeometryCollider
, their ordering is constrained via a total order on collision geometry types, enforced with an overload of the>
operator.Initializes internal Module state, shared by both nn.Module and ScriptModule.
- abstract scalars()[source]
Describes object via Tensorboard scalars.
Any namespace for the object (e.g. “object_5”) is assumed to be added by external code before adding to Tensorboard, so the names of the scalars can be natural descriptions of the geometry’s parameters.
Examples
A cylinder might be represented with the following output:
{'radius': 5.2, 'height': 4.1}
- class dair_pll.geometry.Plane(*args, **kwargs)[source]
Bases:
CollisionGeometry
Half-space/plane collision geometry.
Plane
geometries are assumed to be the plane z=0 in local (i.e. “body-axes” coordinates). Any tilted/raised/lowered half spaces are expected to be derived by placing thez=0
plane in a rigidly-transformed frame.Initializes internal Module state, shared by both nn.Module and ScriptModule.
- class dair_pll.geometry.BoundedConvexCollisionGeometry(*args, **kwargs)[source]
Bases:
CollisionGeometry
Interface for compact-convex collision geometries.
Such shapes have a representation via a “support function” h(d), which takes in a hyperplane direction and returns how far the shape S extends in that direction, i.e.:
h(d) = max_{s \in S} s \cdot d.
This representation can be leveraged to derive “witness points” – i.e. the closest point(s) between the
BoundedConvexCollisionGeometry
and another convex shape, such as anotherBoundedConvexCollisionGeometry
or aPlane
.Initializes internal Module state, shared by both nn.Module and ScriptModule.
- abstract support_points(directions)[source]
Returns a set of witness points representing contact with another shape off in the direction(s)
directions
.This method will return a set of points
S' \subset S
such that:argmax_{s \in S} s \cdot directions \subset convexHull(S').
In theory, returning exactly the argmax set would be sufficient. However,
- class dair_pll.geometry.SparseVertexConvexCollisionGeometry(n_query)[source]
Bases:
BoundedConvexCollisionGeometry
Partial implementation of
BoundedConvexCollisionGeometry
when witness points are guaranteed to be contained in a small set of vertices.An obvious subtype is any sort of Polytope, such as a
Box
. A less obvious subtype are shapes in which a direction-dependent set of vertices can be easily calculated. SeeCylinder
, for instance.Inits
SparseVertexConvexCollisionGeometry
with prescribed query interface.- Parameters:
n_query (
int
) – number of vertices to return in witness point set.
- support_points(directions)[source]
Implements
BoundedConvexCollisionGeometry.support_points()
via brute force optimization over the witness vertex set.Specifically, if S_v is the vertex set, this function returns
n_query
elements s of S_v for whichs \cdot directions
is highest. This set is not guaranteed to be sorted.Given the prescribed behavior of
BoundedConvexCollisionGeometry.support_points()
, an implicit assumption of this implementation is that the convex hull of the topn_query
points in S_v containsargmax_{s \in S} s \cdot directions
.
- class dair_pll.geometry.Polygon(vertices, n_query=4)[source]
Bases:
SparseVertexConvexCollisionGeometry
Concrete implementation of a convex polytope.
Implemented via
SparseVertexConvexCollisionGeometry
as a static set of vertices, where models the underlying shape as all convex combinations of the vertices.Inits
Polygon
object with initial vertex set.- Parameters:
-
vertices:
Parameter
- class dair_pll.geometry.DeepSupportConvex(vertices, n_query=4, depth=2, width=256, perturbation=0.4)[source]
Bases:
SparseVertexConvexCollisionGeometry
Deep support function convex shape.
Any convex shape \(S\) can be equivalently represented via its support function \(f(d)\), which returns the extent to which the object extends in the \(d\) direction:
\[f(d) = \max_{s \in S} s \cdot d.\]Given a direction, the set of points that form the \(\arg\max\) in \(f(d)\) is exactly the convex subgradient \(\partial_d f(d)\).
Furthermore, for every convex shape, \(f(d)\) is convex and positively homogeneous, and every convex and positively homogeneous \(f(d)\) is the support function of some convex shape.
This collision geometry type implements the support function directly as a convex and positively homogeneous neural network (
HomogeneousICNN
).Inits
DeepSupportConvex
object with initial vertex set.When calculating a sparse vertex set with
get_vertices()
, supplements the support direction with nearby directions randomly.- Parameters:
-
fcl_geometry:
BVHModel
fcl
mesh collision geometry representation.
-
network:
HomogeneousICNN
Support function representation as a neural net.
-
perturbations:
Tensor
Perturbed support directions, which aid mesh-plane contact stability.
- get_vertices(directions)[source]
Return batched view of support points of interest.
Given a direction \(d\), this function finds the support point of the object in that direction, calculated via envelope
- train(mode=True)[source]
Override training-mode setter from
torch
.Sets a static fcl mesh geometry for the entirety of evaluation time, as the underlying support function is not changing.
- Parameters:
mode (
bool
) –True
for training,False
for evaluation.- Return type:
- Returns:
self
.
- class dair_pll.geometry.Box(half_lengths, n_query)[source]
Bases:
SparseVertexConvexCollisionGeometry
Implementation of cuboid geometry as a sparse vertex convex hull.
To prevent learning negative box lengths, the learned parameters are stored as
length_params
, and the box’s half lengths can be computed as their absolute value. The desired half lengths can be accessed viaget_half_lengths()
.Inits
Box
object with initial size.- Parameters:
-
length_params:
Parameter
-
unit_vertices:
Tensor
- get_half_lengths()[source]
From the stored
length_params
, compute the half lengths of the box as its absolute value.- Return type:
- class dair_pll.geometry.Sphere(radius)[source]
Bases:
BoundedConvexCollisionGeometry
Implements sphere geometry via its support function.
It is trivial to calculate the witness point for a sphere contact as simply the product of the sphere’s radius and the support direction.
To prevent learning a negative radius, the learned parameter is stored as
length_param
, and the sphere’s radius can be computed as its absolute value. The desired radius can be accessed viaget_radius()
.Initializes internal Module state, shared by both nn.Module and ScriptModule.
-
length_param:
Parameter
- get_radius()[source]
From the stored
length_param
, compute the radius of the sphere as its absolute value.- Return type:
-
length_param:
- class dair_pll.geometry.PydrakeToCollisionGeometryFactory[source]
Bases:
object
Utility class for converting Drake
Shape
instances toCollisionGeometry
instances.- static convert(drake_shape)[source]
Converts abstract
pydrake.geometry.shape
toCollisionGeometry
.
- class dair_pll.geometry.GeometryCollider[source]
Bases:
object
Utility class for colliding two
CollisionGeometry
instances.- static collide(geometry_a, geometry_b, R_AB, p_AoBo_A)[source]
Collides two collision geometries.
Takes in the two geometries as well as a relative transform between them. This function is a thin shell for other static methods of
GeometryCollider
where the given geometries are guaranteed to have specific types.- Parameters:
geometry_a (
CollisionGeometry
) – first collision geometrygeometry_b (
CollisionGeometry
) – second collision geometry, with type orderingnot geometry_A > geometry_B
.R_AB (
Tensor
) – (*,3,3) rotation between geometry framesp_AoBo_A (
Tensor
) – (*, 3) offset of geometry frame origins
- Return type:
- Returns:
(*, N) batch of witness point pair distances (*, N, 3, 3) contact frame C rotation in A, R_AC, where the z axis of C is contained in the normal cone of body A at contact point Ac and is parallel (or antiparallel) to AcBc. (*, N, 3) witness points Ac on A, p_AoAc_A (*, N, 3) witness points Bc on B, p_BoBc_B