Spatial Type ConstructionΒΆ

The spatial types support common 3D geometry operations locally. They do not require a client connection.

Build orientations with Quaternion from roll-pitch-yaw angles or axis-angle rotations, then compose them into Pose and Transform values. 4x4 homogeneous matrices round-trip through the SDK types.

The Python spatial types are immutable dataclasses. Roll-pitch-yaw angles are in radians using xyz extrinsic order.

import math

from olo.spatial import Point, Pose, Quaternion, Transform, Vector

# Spatial types also work locally without a live client connection.
home = Pose.identity()
print(home)

# Build orientations from roll-pitch-yaw or axis-angle rotations.
p1 = Pose(
    position=Point(x=0.4, y=0.0, z=0.3),
    orientation=Quaternion.from_rpy(0.0, math.radians(15), 0.0),
)
p2 = Pose(orientation=Quaternion.from_axis_angle([0, 0, 1], math.pi / 2))

# 4x4 homogeneous matrices round-trip through SDK types.
mat = p2.matrix()
print(mat)

p3 = Pose.from_matrix(mat)
assert p2.isclose(p3)

# Transforms include TF frame metadata.
base_to_tool = Transform(
    translation=Vector(z=0.12),
    rotation=Quaternion.from_rpy(0.0, 0.0, math.pi / 2),
    frame_id="base_link",
    child_frame_id="tool0",
)
print(base_to_tool)

Note

For heavier spatial algebra (Jacobians, trajectory interpolation, etc.), convert to a 4x4 matrix and use a dedicated library such as spatialmath-python:

import math
from spatialmath import SE3

from olo.spatial import Point, Pose, Quaternion

pose = Pose(
    position=Point(x=0.4, y=0.0, z=0.3),
    orientation=Quaternion.from_rpy(0.0, math.radians(15), 0.0),
)
se3 = SE3(pose.matrix())
print(se3)

The TypeScript spatial types are dependency-free classes. Roll-pitch-yaw angles are in radians using xyz extrinsic order.

import { Point, Pose, Quaternion, Transform, Vector } from "olo/spatial";

// Spatial types also work locally without a live client connection.
const home = Pose.identity();
console.log(`${home}`);

// Build orientations from roll-pitch-yaw or axis-angle rotations.
const p1 = new Pose(
  new Point(0.4, 0.0, 0.3),
  Quaternion.fromRpy(0.0, (15 * Math.PI) / 180, 0.0),
);
console.log(`${p1}`);

const p2 = new Pose(new Point(), Quaternion.fromAxisAngle([0, 0, 1], Math.PI / 2));

// 4x4 homogeneous matrices round-trip through SDK types.
const mat = p2.matrix();
console.log(mat);

const p3 = Pose.fromMatrix(mat);
console.assert(p2.isClose(p3));

// Transforms include TF frame metadata.
const baseToTool = new Transform({
  translation: new Vector(0.0, 0.0, 0.12),
  rotation: Quaternion.fromRpy(0.0, 0.0, Math.PI / 2),
  frameId: "base_link",
  childFrameId: "tool0",
});
console.log(`${baseToTool}`);