Utilities¶
Rotation Conversions¶
rot_utils
¶
Rotation utility functions for conversions between representations.
quaternion_to_matrix(quat: np.ndarray) -> np.ndarray
¶
Convert quaternion to 3x3 rotation matrix.
Input
quat: Quaternion in (w, x, y, z) format, shape (4,)
Output: rotation matrix, shape (3, 3)
Source code in drone_planning/utils/rot_utils.py
matrix_to_quaternion(rot: np.ndarray) -> np.ndarray
¶
Convert 3x3 rotation matrix to quaternion.
Input
rot: Rotation matrix, shape (3, 3)
Output: quaternion in (w, x, y, z) format, shape (4,)
Source code in drone_planning/utils/rot_utils.py
rpy_to_matrix(roll: float, pitch: float, yaw: float) -> np.ndarray
¶
Convert roll-pitch-yaw (XYZ Euler angles) to rotation matrix.
Input
roll: Rotation around X axis (radians) pitch: Rotation around Y axis (radians) yaw: Rotation around Z axis (radians)
Output: rotation matrix, shape (3, 3)
Source code in drone_planning/utils/rot_utils.py
matrix_to_rpy(rot: np.ndarray) -> tuple[float, float, float]
¶
Convert rotation matrix to roll-pitch-yaw (XYZ Euler angles).
Input
rot: Rotation matrix, shape (3, 3)
Output: (roll, pitch, yaw) in radians
Source code in drone_planning/utils/rot_utils.py
axis_angle_to_matrix(axis: np.ndarray, angle: float) -> np.ndarray
¶
Convert axis-angle representation to rotation matrix (Rodrigues formula).
Input
axis: Unit vector representing rotation axis, shape (3,) angle: Rotation angle in radians
Output: rotation matrix, shape (3, 3)
Source code in drone_planning/utils/rot_utils.py
matrix_to_axis_angle(rot: np.ndarray) -> tuple[np.ndarray, float]
¶
Convert rotation matrix to axis-angle representation.
Input
rot: Rotation matrix, shape (3, 3)
Output: (axis, angle) where axis is unit vector shape (3,), angle in radians
Source code in drone_planning/utils/rot_utils.py
Video Recorder¶
video_recorder
¶
Offscreen MP4 recorder for :class:PyBulletEnv.
Records MP4 clips from a headless PyBullet session by rendering frames
via getCameraImage and piping them into ffmpeg. Works with a
DIRECT connection (no GUI window required), which makes it safe to
use inside build pipelines, CI, or a doc-rendering driver.
Typical usage::
from drone_planning.utils.video_recorder import CameraView, VideoRecorder
with VideoRecorder(env, "output.mp4", camera=CameraView()) as rec:
rec.hold(seconds=0.5) # pause on the start pose
rec.play(configurations) # one frame per configuration
rec.hold(seconds=1.0) # pause on the final pose
The recorder assumes ffmpeg is on PATH. Frames are rendered with
the CPU TinyRenderer.
CameraView(target: tuple[float, float, float] = (2.6, 0.0, 1.0), distance: float = 6.0, yaw: float = -35.0, pitch: float = -25.0, roll: float = 0.0, fov: float = 45.0, near: float = 0.05, far: float = 30.0)
dataclass
¶
Static orbit-camera parameters passed to computeViewMatrixFromYawPitchRoll.
target points at a world-space location, distance is the
orbit radius, and yaw/pitch orbit around target in
degrees. fov is the vertical field of view of the projection.
The camera does not move during a clip.
VideoRecorder(env: 'PyBulletEnv', output_path: Path | str, fps: int = 30, resolution: tuple[int, int] = (960, 540), camera: CameraView = CameraView(), light_direction: tuple[float, float, float] = (0.55, -0.4, 1.3), crf: int = 28)
dataclass
¶
Render frames from a :class:PyBulletEnv into an H.264 MP4.
The recorder owns a running ffmpeg subprocess while the context is
open; frames are written directly to its stdin in rgba format.
capture() -> None
¶
Render the current env state as a single frame into the clip.