Files
DCCONSTRUCTIONS d0e5f90952 Preserve installed operator workspace before consolidation
Local preservation snapshot, not a new deployment or simulation acceptance.
2026-10-08 09:59:51 +03:00

73 lines
3.6 KiB
Python

"""Shared physical rig cubes and their conservative navigation projection.
Coordinates are body X-forward/Y-left/Z-up from nominal track contact. The
simulator and navigation consume these same descriptors; contact bands remain
the chassis' own geometry. This is a yaw-plane bound, not full 3D swept CAD.
"""
import math
def install_rig_colliders(stage, mounts, contact_height_m, root_path="/World/Rover"):
"""Install the same physical cubes in production and native qualification."""
from pxr import Gf, UsdGeom, UsdPhysics
for descriptor in rig_collision_shapes(mounts):
name, center, size, pitch = (descriptor[key] for key in
("name", "center_m", "size_m", "pitch_degrees"))
shape = UsdGeom.Cube.Define(stage, root_path + "/chassis/Sensor" + name)
shape.CreateSizeAttr(1)
shape.AddTranslateOp().Set(Gf.Vec3d(center[0], center[1], center[2] - contact_height_m))
shape.AddRotateYOp().Set(-pitch)
shape.AddScaleOp().Set(Gf.Vec3f(*size))
shape.CreateDisplayColorAttr([Gf.Vec3f(0.07, 0.08, 0.09)])
UsdPhysics.CollisionAPI.Apply(shape.GetPrim())
def rig_collision_shapes(mounts):
x4, depth, lidar = (mounts[key] for key in ("insta360", "realsense", "k1"))
pitch = float(depth["pitch_degrees"])
p = math.radians(pitch)
depth_center = [origin - .014 * direction for origin, direction in
zip(depth["origin_m"], (math.cos(p), 0., math.sin(p)), strict=True)]
lidar_pitch = -float(lidar["tilt_forward_degrees"])
p = math.radians(lidar_pitch)
lidar_center = [origin - .12 * direction for origin, direction in
zip(lidar["origin_m"], (-math.sin(p), 0., math.cos(p)), strict=True)]
shapes = [
dict(name="Insta360", center_m=list(x4["body_center_m"]),
size_m=list(x4["body_size_m"]), pitch_degrees=0.),
dict(name="RealSense", center_m=depth_center,
size_m=list(depth["body_size_m"]), pitch_degrees=pitch),
dict(name="K1", center_m=lidar_center,
size_m=list(lidar["body_size_m"]), pitch_degrees=lidar_pitch),
]
for shape in shapes:
if (len(shape["center_m"]) != 3 or len(shape["size_m"]) != 3
or not all(math.isfinite(x) for x in
[*shape["center_m"], *shape["size_m"], shape["pitch_degrees"]])
or min(shape["size_m"]) <= 0):
raise ValueError("Invalid rig collision cube")
return shapes
def collision_geometry(geometry, mounts):
"""Keep support geometry; enlarge only collision XY and vertical ceiling.
A centered rectangle deliberately over-approximates an asymmetric rig at
the rear too. No physical shape is shrunk to fit a navigation threshold.
"""
half = [geometry["length_m"] / 2, geometry["width_m"] / 2]
top = geometry["height_m"]
for shape, spec in zip(rig_collision_shapes(mounts),
(mounts[key] for key in ("insta360", "realsense", "k1")), strict=True):
x, y, z = shape["center_m"]
sx, sy, sz = shape["size_m"]
p = math.radians(shape["pitch_degrees"])
hx = (abs(math.cos(p))*sx + abs(math.sin(p))*sz)/2
half[0] = max(half[0], abs(x)+hx)
half[1] = max(half[1], abs(y)+sy/2)
# Preserve the prior conservative sphere ceiling for raised returns.
anchor_z = spec.get("body_center_m", spec.get("origin_m"))[2]
top = max(top, max(z, anchor_z) + math.sqrt(sx*sx + sy*sy + sz*sz)/2)
return {**geometry, "collision_length_m": 2*half[0],
"collision_width_m": 2*half[1], "collision_top_m": top}