Instructions to use Lyndow/ExoWrist_Smolvla with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Piper
How to use Lyndow/ExoWrist_Smolvla with Piper:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
File size: 4,508 Bytes
e302b11 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | #!/usr/bin/env python3
"""Create an offline HTML trajectory viewer from the frame-aligned Piper CSV.
Only C_PiperForwardKinematics is instantiated; no CAN, camera or robot interface.
"""
from __future__ import annotations
import argparse
import csv
from importlib.metadata import version
import json
import math
from pathlib import Path
from piper_sdk.kinematics.piper_fk import C_PiperForwardKinematics
def numeric(row, key):
value = float(row[key])
if not math.isfinite(value):
raise ValueError(f"nonfinite value: {key}")
return value
def load_samples(source, dh_offset):
fk = C_PiperForwardKinematics(dh_is_offset=dh_offset)
samples = []
with source.open(newline="", encoding="utf-8") as file:
for row in csv.DictReader(file):
t = numeric(row, "time_sec")
if samples and t <= samples[-1]["t"]:
raise ValueError("time_sec must strictly increase")
q = ([numeric(row, f"feedback_j{j}_deg") for j in range(1, 7)]
if row["feedback_valid"] == "1" else None)
target = ([numeric(row, f"target_j{j}_deg") for j in range(1, 7)]
if row.get("target_valid") == "1" else None)
links = fk.CalFK([math.radians(angle) for angle in q]) if q is not None else None
samples.append({"t": t, "frame": int(row["video_frame_index"]), "q": q, "target": target,
"links": ([[0, 0, 0]] + [[round(x, 3) for x in link[:3]] for link in links])
if links is not None else None,
"grip": numeric(row, "feedback_gripper_opening_mm")
if row.get("feedback_gripper_valid") == "1" else None})
if len(samples) < 2 or not any(s["q"] is not None for s in samples):
raise ValueError("need at least two rows and some valid actual feedback")
return samples
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("capture", type=Path, help="capture directory containing aligned_60hz.csv")
parser.add_argument("--dh-offset", type=int, choices=(0, 1), default=1)
parser.add_argument("--output", type=Path, help="new output directory; existing paths are refused")
args = parser.parse_args()
capture = args.capture.resolve()
source = capture / "aligned_60hz.csv"
samples = load_samples(source, args.dh_offset)
output = args.output.resolve() if args.output else capture / "visualization"
output.mkdir(parents=True, exist_ok=False)
valid = [s for s in samples if s["links"] is not None]
tips = [s["links"][-1] for s in valid]
path_mm = sum(math.dist(a["links"][-1], b["links"][-1]) for a, b in zip(samples, samples[1:])
if a["links"] and b["links"] and b["t"]-a["t"] <= 0.1)
summary = {"input_csv": str(source), "samples": len(samples), "valid_feedback": len(valid),
"duration_sec": samples[-1]["t"] - samples[0]["t"], "sdk_version": version("piper_sdk"),
"dh_offset": args.dh_offset, "estimated_tip_path_length_mm": path_mm,
"tip_range_mm": {axis: [min(p[j] for p in tips), max(p[j] for p in tips)]
for j, axis in enumerate("xyz")},
"limits": "SDK link-6 frame in arm base coordinates, not calibrated gripper TCP or world coordinates. "
"DH offset is an assumption; no hardware queried. Path length includes measurement jitter."}
payload = {"summary": summary, "samples": samples}
template = Path(__file__).with_name("piper_trajectory_viewer.html").read_text(encoding="utf-8")
encoded = json.dumps(payload, ensure_ascii=False, allow_nan=False, separators=(",", ":")).replace("<", "\\u003c")
(output / "trajectory.html").write_text(template.replace("__TRAJECTORY_DATA__", encoded), encoding="utf-8")
(output / "summary.json").write_text(json.dumps(summary, indent=2) + "\n", encoding="utf-8")
with (output / "estimated_endpoint.csv").open("x", newline="") as file:
writer = csv.writer(file)
writer.writerow(["video_frame_index", "time_sec", "feedback_valid", "x_mm", "y_mm", "z_mm"])
writer.writerows([s["frame"], s["t"], int(s["links"] is not None),
*(s["links"][-1] if s["links"] else [None]*3)] for s in samples)
print(json.dumps({"html": str(output / "trajectory.html"), **summary}, indent=2))
if __name__ == "__main__":
main()
|