"""Native scene fixture for the bounded obstacle challenge, never a planner input.""" import math def yaw_from_pose(pose): x, y, z, w = pose[3:7] return math.atan2(2 * (w * z + x * y), 1 - 2 * (y * y + z * z)) class ObstacleFixture: path = "/World/QualificationObstacle" def __init__(self, stage, spec, profile, *, physics_profile): from pxr import Gf, UsdGeom, UsdPhysics, UsdShade from terrain import apply_environment_contact_policy self.profile, self.spec = profile, spec self.record = None self.cube = UsdGeom.Cube.Define(stage, self.path) self.cube.CreateSizeAttr(1) self.translation = self.cube.AddTranslateOp() self.rotation = self.cube.AddRotateZOp() self.cube.AddScaleOp().Set(Gf.Vec3f(*spec["size_m"])) self.cube.CreateDisplayColorAttr([Gf.Vec3f(0.95, 0.25, 0.05)]) self.cube.CreateVisibilityAttr(UsdGeom.Tokens.invisible) self.collision = UsdPhysics.CollisionAPI.Apply(self.cube.GetPrim()) self.contact_policy = apply_environment_contact_policy(self.cube.GetPrim(), physics_profile) self.collision.CreateCollisionEnabledAttr(False) material = UsdShade.Material.Define(stage, "/World/Materials/QualificationObstacle") surface = UsdPhysics.MaterialAPI.Apply(material.GetPrim()) surface.CreateStaticFrictionAttr(0.9) surface.CreateDynamicFrictionAttr(0.8) surface.CreateRestitutionAttr(0) UsdShade.MaterialBindingAPI.Apply(self.cube.GetPrim()).Bind( material, UsdShade.Tokens.weakerThanDescendants, "physics" ) def activate(self, motion): from pxr import Gf, UsdGeom pose = motion["pose"] yaw = yaw_from_pose(pose) size = self.spec["size_m"] ahead = self.profile["length_m"] / 2 + self.spec["initial_clearance_m"] + size[0] / 2 centre = [ pose[0] + ahead * math.cos(yaw), pose[1] + ahead * math.sin(yaw), pose[2] - self.profile["body_contact_height_m"] + size[2] / 2, ] self.translation.Set(Gf.Vec3d(*centre)) self.rotation.Set(math.degrees(yaw)) self.cube.GetVisibilityAttr().Set(UsdGeom.Tokens.inherited) self.collision.GetCollisionEnabledAttr().Set(True) self.record = { "path": self.path, "centre": centre, "yaw": yaw, "size_m": size, "rover_size_xy_m": [self.profile["length_m"], self.profile["width_m"]], } return self.record def deactivate(self): from pxr import UsdGeom self.collision.GetCollisionEnabledAttr().Set(False) self.cube.GetVisibilityAttr().Set(UsdGeom.Tokens.invisible)