8d3415602f
DECISION: Refine R0.3 into a separate R0.4 exterior using the user's physical-hand photographs, preserving all five four-axis finger chains, including the little finger removed from the photographed sample. WHY: On 2026-11-17 the user supplied five close-ups and asked for a comparison-based improvement, explicitly explaining the missing little finger. The photographs reveal curved shells, fork openings, stepped joint caps, black contact pads and a spatial thumb root more clearly than the earlier website screenshot. design-docs/lh20-r04-photo-refinement.md records the interpretation, assumptions, rejected alternatives and checks. No scale marker or internal section was supplied, so the existing dimension baseline remains an original design input and the internal drive remains pending. ALTERNATIVE CONSIDERED AND REJECTED: Merely changing colours, duplicating the missing-finger state, or presenting a concept image would not improve the actual complete CAD model. Reusing earlier verification reports would conceal new geometry and motion failures. WHAT CHANGES: Add curved shells and removable covers, nested fork ears, stepped three-fastener caps, wraparound black pads, segmented flex-circuit placeholders and a canted thumb mounting frame. Preserve native articulated source, binding geometry checks and previews to captured packages. A small export adapter uses the native writer's existing metadata_properties=False option and saves complete descriptive records in a hashed sidecar because >22 kB constraint strings overflow the OCCT STEP reader; geometry and assembly structure remain intact, and the shared SDK is unchanged. Checked: Single finger and complete hand passed positive-volume, BREP validity, constraint and exact interference checks in straight and specified light-flex poses. Diagnosed and removed a 0.256 mm3 knuckle overlap without changing the 0.01 mm3 threshold. All five fingers retain four axes. STEP reimport retained 245 solids with relative volume error 4.03e-7. URDF has 21 links, 20 joints and 84 mesh files. Reviewed actual front/back/oblique/side CAD views and the R0.3 comparison. Packaging verified 102 files, relative mesh paths, source hashes and independent-finger versus nested-finger volumes. Python compilation passed. Full travel, actuator integration, continuous flex routing, manufacturing and hardware performance are not qualified. Co-Authored-By: Codex <noreply@openai.com>
164 lines
6.2 KiB
Python
164 lines
6.2 KiB
Python
"""STEP and visual URDF for the checked exterior; no invented drive properties."""
|
|
|
|
import hashlib, json, re
|
|
import xml.etree.ElementTree as ET
|
|
import numpy as np
|
|
from scipy.spatial.transform import Rotation
|
|
from exchange_step import export_compatible_step
|
|
from simplecadapi.exporter._surface_mesh import tessellate_solid
|
|
from OCP.STEPControl import STEPControl_Reader
|
|
from OCP.IFSelect import IFSelect_RetDone
|
|
from OCP.TopExp import TopExp_Explorer
|
|
from OCP.TopAbs import TopAbs_SOLID
|
|
from parameters import OUT, FINGERS, AXES, MATERIALS
|
|
from model_io import read_model, flatten
|
|
from verify import volume
|
|
|
|
|
|
def seq(values):
|
|
return " ".join(f"{v:.10g}" for v in values)
|
|
|
|
|
|
def sub(parent, tag, **attrs):
|
|
return ET.SubElement(parent, tag, {k: str(v) for k, v in attrs.items()})
|
|
|
|
|
|
def main():
|
|
package = OUT / "hand.scadpkg"
|
|
digest = hashlib.sha256(package.read_bytes()).hexdigest()
|
|
check = json.loads((OUT / "hand_check.json").read_text())
|
|
assert (
|
|
check["package_sha256"] == digest
|
|
and check["geometry_pass"]
|
|
and check["constraints_pass"]
|
|
and check["clearance_pass"]
|
|
)
|
|
leaves = flatten(read_model())
|
|
step = OUT / "LH20_R04_exterior.step"
|
|
report = export_compatible_step(package, step)
|
|
reader = STEPControl_Reader()
|
|
assert reader.ReadFile(str(step)) == IFSelect_RetDone
|
|
reader.TransferRoots()
|
|
imported = reader.OneShape()
|
|
exp = TopExp_Explorer(imported, TopAbs_SOLID)
|
|
count = 0
|
|
while exp.More():
|
|
count += 1
|
|
exp.Next()
|
|
source_volume = sum(r["volume_mm3"] for r in check["geometry"])
|
|
error = abs(volume(imported) - source_volume) / source_volume
|
|
assert count == len(leaves) and error < 1e-5
|
|
frames = {"palm": np.eye(4)}
|
|
for f in FINGERS:
|
|
for k in range(4):
|
|
frames[f"{f.name}_{k}"] = next(
|
|
m for path, p, m in leaves if path == f"/{f.name}/link{k}"
|
|
)
|
|
groups = {}
|
|
meshdir = OUT / "meshes"
|
|
meshdir.mkdir(exist_ok=True)
|
|
for path, p, m in leaves:
|
|
tokens = path.strip("/").split("/")
|
|
owner = "palm"
|
|
if tokens[0] in {f.name for f in FINGERS} and tokens[1] != "mount":
|
|
owner = f"{tokens[0]}_{re.search(r'\d+', tokens[1]).group()}"
|
|
material = p.material.material_id
|
|
vertices, triangles = tessellate_solid(
|
|
p.body,
|
|
linear_deflection=0.12,
|
|
angular_deflection_degrees=12,
|
|
relative=False,
|
|
)
|
|
pose = np.linalg.inv(frames[owner]) @ m
|
|
vertices = (np.asarray(vertices) @ pose[:3, :3].T + pose[:3, 3]) / 1000
|
|
groups.setdefault((owner, material), []).append(
|
|
(vertices, np.asarray(triangles))
|
|
)
|
|
robot = ET.Element("robot", name="LH20_R04_exterior_only")
|
|
links = {name: sub(robot, "link", name=name) for name in frames}
|
|
for name, (_, color) in MATERIALS.items():
|
|
mat = sub(robot, "material", name=name)
|
|
sub(mat, "color", rgba=seq([*color, 1]))
|
|
files = []
|
|
for (owner, material), blocks in groups.items():
|
|
filename = f"{owner}_{material}.obj"
|
|
lines = []
|
|
offset = 0
|
|
for vertices, triangles in blocks:
|
|
lines.extend("v " + seq(v) for v in vertices)
|
|
lines.extend(
|
|
"f " + " ".join(str(int(i + offset + 1)) for i in row)
|
|
for row in triangles
|
|
)
|
|
offset += len(vertices)
|
|
(meshdir / filename).write_text("\n".join(lines) + "\n")
|
|
files.append(filename)
|
|
visual = sub(links[owner], "visual")
|
|
geometry = sub(visual, "geometry")
|
|
sub(geometry, "mesh", filename="meshes/" + filename)
|
|
sub(visual, "material", name=material)
|
|
for f in FINGERS:
|
|
for k in range(4):
|
|
parent = "palm" if k == 0 else f"{f.name}_{k - 1}"
|
|
child = f"{f.name}_{k}"
|
|
pose = np.linalg.inv(frames[parent]) @ frames[child]
|
|
joint = sub(robot, "joint", name=child + "_axis", type="revolute")
|
|
sub(joint, "parent", link=parent)
|
|
sub(joint, "child", link=child)
|
|
sub(
|
|
joint,
|
|
"origin",
|
|
xyz=seq(pose[:3, 3] / 1000),
|
|
rpy=seq(Rotation.from_matrix(pose[:3, :3]).as_euler("xyz")),
|
|
)
|
|
sub(joint, "axis", xyz="0 0 1" if AXES[k] == "z" else "1 0 0")
|
|
# Display ranges are proposed, not qualified motion limits. Zero
|
|
# effort/velocity intentionally makes no actuator performance claim.
|
|
lo, hi = (-20, 20) if k == 0 else (0, 90)
|
|
sub(
|
|
joint,
|
|
"limit",
|
|
lower=np.deg2rad(lo),
|
|
upper=np.deg2rad(hi),
|
|
effort=0,
|
|
velocity=0,
|
|
)
|
|
robot.insert(
|
|
0,
|
|
ET.Comment(
|
|
"Exterior visualization only. No inertia, collision, transmission or motor performance qualification."
|
|
),
|
|
)
|
|
ET.indent(robot, space=" ")
|
|
urdf = OUT / "LH20_R04_exterior.urdf"
|
|
ET.ElementTree(robot).write(urdf, encoding="utf-8", xml_declaration=True)
|
|
parsed = ET.parse(urdf).getroot()
|
|
assert len(parsed.findall("joint")) == 20
|
|
assert {e.attrib["name"] for e in parsed.findall("link")} == {"palm"} | {
|
|
f"{f.name}_{k}" for f in FINGERS for k in range(4)
|
|
}
|
|
assert {e.attrib["name"] for e in parsed.findall("joint")} == {
|
|
f"{f.name}_{k}_axis" for f in FINGERS for k in range(4)
|
|
}
|
|
assert all(
|
|
(OUT / e.attrib["filename"]).is_file() for e in parsed.findall(".//mesh")
|
|
)
|
|
result = dict(
|
|
package_sha256=digest,
|
|
step_occurrences=count,
|
|
step_relative_volume_error=error,
|
|
urdf_links=len(links),
|
|
urdf_joints=20,
|
|
mesh_files=len(files),
|
|
scope="Exterior STEP and visualization URDF only; dynamics and actuator integration pending",
|
|
step_descriptive_metadata="LH20_R04_exterior_metadata.json (full records; STEP keeps geometry, hierarchy and materials)",
|
|
step_sha256=hashlib.sha256(step.read_bytes()).hexdigest(),
|
|
urdf_sha256=hashlib.sha256(urdf.read_bytes()).hexdigest(),
|
|
)
|
|
(OUT / "exchange_check.json").write_text(json.dumps(result, indent=2))
|
|
print(json.dumps(result, indent=2), flush=True)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|