Local preservation snapshot, not a new deployment or simulation acceptance.
196 lines
8.8 KiB
Python
196 lines
8.8 KiB
Python
"""DCD-006 geometry with a provisional four-wheel differential contact proxy.
|
|
|
|
CAD dimensions and the owner's working mass are explicit. The mass split,
|
|
friction and joint drives remain an unqualified contact approximation.
|
|
"""
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
ROBOT_DOCUMENT = json.loads((Path(__file__).parent / "robots/dcd006-v020.json").read_text())
|
|
PROFILE = ROBOT_DOCUMENT["physics"]
|
|
|
|
|
|
def mass_distribution(profile=PROFILE):
|
|
"""One total mass, with an explicitly assumed split for this contact proxy."""
|
|
import math
|
|
|
|
total, wheel = profile["mass_kg"], profile["wheel_mass_kg"]
|
|
chassis = total - len(profile["wheel_names"]) * wheel
|
|
if not all(math.isfinite(value) and value > 0 for value in (total, wheel, chassis)):
|
|
raise ValueError("Invalid rover mass distribution")
|
|
return chassis, wheel
|
|
|
|
|
|
class DifferentialDrive:
|
|
"""Velocity drive plus physical wheel-position hold when braking.
|
|
|
|
Holding uses joint drive forces, never teleportation or a frozen chassis.
|
|
The same actuator is used by capability qualification and the live scene.
|
|
"""
|
|
|
|
def __init__(self, articulation):
|
|
self.robot = articulation
|
|
self.body = articulation
|
|
self.indices = articulation.get_dof_indices(PROFILE["wheel_names"])
|
|
self.holding = None
|
|
|
|
def command(self, velocity, yaw_rate=0.0):
|
|
hold = abs(velocity) + abs(yaw_rate) < 1e-5
|
|
if hold != self.holding:
|
|
if hold:
|
|
position = self.robot.get_dof_positions(dof_indices=self.indices)
|
|
self.robot.set_dof_position_targets(position, dof_indices=self.indices)
|
|
self.robot.set_dof_gains(
|
|
stiffnesses=PROFILE["brake_stiffness"] if hold else 0.0,
|
|
dampings=PROFILE["brake_damping"] if hold else PROFILE["drive_damping"],
|
|
dof_indices=self.indices,
|
|
)
|
|
self.holding = hold
|
|
half_track, radius = PROFILE["track_width_m"] / 2, PROFILE["wheel_radius_m"]
|
|
left = (velocity - yaw_rate * half_track) / radius
|
|
right = (velocity + yaw_rate * half_track) / radius
|
|
self.robot.set_dof_velocity_targets([[left, left, right, right]], dof_indices=self.indices)
|
|
|
|
def step(self, dt):
|
|
pass # Native joint drives are integrated by PhysX.
|
|
|
|
def side_speeds(self):
|
|
rates = self.robot.get_dof_velocities(dof_indices=self.indices).numpy()[0]
|
|
return [float((rates[i] + rates[i + 1]) * 0.5 * PROFILE["wheel_radius_m"]) for i in (0, 2)]
|
|
|
|
@property
|
|
def metrics(self):
|
|
return {"model": "four-wheel-proxy", "belt_mps": self.side_speeds()}
|
|
|
|
|
|
def open_drive(root_path="/World/Rover", *, model=None, contact_filter_paths=None, document=None):
|
|
document = document or ROBOT_DOCUMENT
|
|
model = model or document["physics"].get("contact_model", "wheels")
|
|
if model == "tracks":
|
|
from tracked_rover import TrackedDrive
|
|
|
|
if not contact_filter_paths:
|
|
raise ValueError("Tracked drive requires explicit terrain contact filters")
|
|
return TrackedDrive(document, root_path, contact_filter_paths)
|
|
if model != "wheels":
|
|
raise ValueError("Unknown rover contact model")
|
|
from isaacsim.core.experimental.prims import Articulation
|
|
|
|
return DifferentialDrive(Articulation(root_path))
|
|
|
|
|
|
def create_rover(
|
|
stage,
|
|
spawn,
|
|
heading,
|
|
ground_normal=(0, 0, 1),
|
|
root_path="/World/Rover",
|
|
visual_asset=None,
|
|
*,
|
|
model=None,
|
|
document=None,
|
|
):
|
|
document = document or ROBOT_DOCUMENT
|
|
profile = document["physics"]
|
|
model = model or profile.get("contact_model", "wheels")
|
|
if model == "tracks":
|
|
from tracked_rover import create_tracked_rover
|
|
|
|
create_tracked_rover(
|
|
stage, document, spawn, heading, ground_normal, root_path, visual_asset
|
|
)
|
|
return profile
|
|
if model != "wheels":
|
|
raise ValueError("Unknown rover contact model")
|
|
import carb.settings
|
|
from omni.physx.bindings._physx import SETTING_COLLISION_APPROXIMATE_CYLINDERS
|
|
from pxr import Gf, PhysxSchema, UsdGeom, UsdPhysics, UsdShade
|
|
|
|
# Official PhysX cylinder approximation avoids the pathological contact
|
|
# cost measured on the Forest reconstruction. This changes collision
|
|
# representation, not wheel radius, chassis dimensions or terrain limits.
|
|
carb.settings.get_settings().set_bool(SETTING_COLLISION_APPROXIMATE_CYLINDERS, True)
|
|
|
|
tire = UsdShade.Material.Define(stage, "/World/Materials/RoverTire")
|
|
tire_physics = UsdPhysics.MaterialAPI.Apply(tire.GetPrim())
|
|
tire_physics.CreateStaticFrictionAttr(PROFILE["static_friction"])
|
|
tire_physics.CreateDynamicFrictionAttr(PROFILE["dynamic_friction"])
|
|
tire_physics.CreateRestitutionAttr(0)
|
|
|
|
root = UsdGeom.Xform.Define(stage, root_path)
|
|
root.AddTranslateOp().Set(Gf.Vec3d(*spawn))
|
|
tilt = Gf.Rotation(Gf.Vec3d(0, 0, 1), Gf.Vec3d(*ground_normal)).GetQuat()
|
|
yaw = Gf.Rotation(Gf.Vec3d(0, 0, 1), heading).GetQuat()
|
|
root.AddOrientOp().Set(Gf.Quatf(tilt * yaw))
|
|
UsdPhysics.ArticulationRootAPI.Apply(root.GetPrim())
|
|
articulation = PhysxSchema.PhysxArticulationAPI.Apply(root.GetPrim())
|
|
articulation.CreateEnabledSelfCollisionsAttr(False)
|
|
articulation.CreateSolverPositionIterationCountAttr(PROFILE["solver_position_iterations"])
|
|
articulation.CreateSolverVelocityIterationCountAttr(PROFILE["solver_velocity_iterations"])
|
|
|
|
def contact(prim):
|
|
UsdPhysics.CollisionAPI.Apply(prim)
|
|
collision = PhysxSchema.PhysxCollisionAPI.Apply(prim)
|
|
collision.CreateContactOffsetAttr(PROFILE["contact_offset_m"])
|
|
collision.CreateRestOffsetAttr(0.0)
|
|
|
|
body = UsdGeom.Xform.Define(stage, root_path + "/chassis")
|
|
body.AddTranslateOp().Set(Gf.Vec3d(0, 0, 0.12))
|
|
UsdPhysics.RigidBodyAPI.Apply(body.GetPrim())
|
|
PhysxSchema.PhysxRigidBodyAPI.Apply(body.GetPrim()).CreateMaxDepenetrationVelocityAttr(1.0)
|
|
chassis_mass, wheel_mass = mass_distribution()
|
|
UsdPhysics.MassAPI.Apply(body.GetPrim()).CreateMassAttr(chassis_mass)
|
|
hull = UsdGeom.Cube.Define(stage, root_path + "/chassis/hull")
|
|
hull.CreateSizeAttr(1)
|
|
hull.AddScaleOp().Set(
|
|
Gf.Vec3f(PROFILE["length_m"], PROFILE["width_m"] - 2 * PROFILE["wheel_width_m"], 0.24)
|
|
)
|
|
hull.CreateDisplayColorAttr([Gf.Vec3f(0.65, 0.67, 0.61)])
|
|
contact(hull.GetPrim())
|
|
# Mast is visual geometry under the rigid chassis (not a separate body).
|
|
sensor = UsdGeom.Cube.Define(stage, root_path + "/chassis/sensor")
|
|
sensor.CreateSizeAttr(1)
|
|
sensor.AddTranslateOp().Set(Gf.Vec3d(0.25, 0, 0.3))
|
|
sensor.AddScaleOp().Set(Gf.Vec3f(0.16, 0.16, 0.6))
|
|
sensor.CreateDisplayColorAttr([Gf.Vec3f(0.12, 0.13, 0.13)])
|
|
for name in PROFILE["wheel_names"]:
|
|
x = PROFILE["wheelbase_m"] / 2 * (1 if name.startswith("front") else -1)
|
|
y = PROFILE["track_width_m"] / 2 * (1 if name.endswith("left") else -1)
|
|
path = root_path + "/" + name
|
|
wheel = UsdGeom.Cylinder.Define(stage, path)
|
|
wheel.CreateAxisAttr("Y")
|
|
wheel.CreateRadiusAttr(PROFILE["wheel_radius_m"])
|
|
wheel.CreateHeightAttr(PROFILE["wheel_width_m"])
|
|
wheel.AddTranslateOp().Set(Gf.Vec3d(x, y, 0))
|
|
wheel.CreateDisplayColorAttr([Gf.Vec3f(0.08, 0.08, 0.08)])
|
|
UsdPhysics.RigidBodyAPI.Apply(wheel.GetPrim())
|
|
PhysxSchema.PhysxRigidBodyAPI.Apply(wheel.GetPrim()).CreateMaxDepenetrationVelocityAttr(1.0)
|
|
contact(wheel.GetPrim())
|
|
UsdShade.MaterialBindingAPI.Apply(wheel.GetPrim()).Bind(
|
|
tire, UsdShade.Tokens.weakerThanDescendants, "physics"
|
|
)
|
|
UsdPhysics.MassAPI.Apply(wheel.GetPrim()).CreateMassAttr(wheel_mass)
|
|
joint = UsdPhysics.RevoluteJoint.Define(stage, root_path + "/joints/" + name)
|
|
joint.CreateBody0Rel().SetTargets([body.GetPath()])
|
|
joint.CreateBody1Rel().SetTargets([wheel.GetPath()])
|
|
joint.CreateLocalPos0Attr(Gf.Vec3f(x, y, -0.12))
|
|
joint.CreateLocalPos1Attr(Gf.Vec3f(0))
|
|
joint.CreateAxisAttr("Y")
|
|
drive = UsdPhysics.DriveAPI.Apply(joint.GetPrim(), "angular")
|
|
drive.CreateTypeAttr("force")
|
|
drive.CreateStiffnessAttr(0)
|
|
drive.CreateDampingAttr(PROFILE["drive_damping"])
|
|
drive.CreateMaxForceAttr(PROFILE["joint_max_force_nm"])
|
|
drive.CreateTargetVelocityAttr(0)
|
|
if visual_asset is not None:
|
|
# Only renderables are hidden. Joint bodies and contacts remain active.
|
|
hull.CreateVisibilityAttr(UsdGeom.Tokens.invisible)
|
|
sensor.CreateVisibilityAttr(UsdGeom.Tokens.invisible)
|
|
for name in PROFILE["wheel_names"]:
|
|
UsdGeom.Imageable(stage.GetPrimAtPath(root_path + "/" + name)).MakeInvisible()
|
|
visual = UsdGeom.Xform.Define(stage, root_path + "/chassis/DCD006")
|
|
visual.GetPrim().GetReferences().AddReference(str(visual_asset))
|
|
visual.AddTranslateOp().Set(Gf.Vec3d(0, 0, -PROFILE["body_contact_height_m"]))
|
|
return PROFILE
|