Download code/work/graphvla_stack_v1_20261104/robot_fk.py from yuuu94/GraphVLA-StackBowls-V7-4k: direct link, hf CLI and curl.
- Browser
- Download file 2.63 kB
-
https://huggingface.co/yuuu94/GraphVLA-StackBowls-V7-4k/resolve/main/code/work/graphvla_stack_v1_20261104/robot_fk.py
- Command line
-
hf download hf://yuuu94/GraphVLA-StackBowls-V7-4k/code/work/graphvla_stack_v1_20261104/robot_fk.py
-
curl -L -o robot_fk.py https://huggingface.co/yuuu94/GraphVLA-StackBowls-V7-4k/resolve/main/code/work/graphvla_stack_v1_20261104/robot_fk.py
2.63 kB
| import json | |
| from pathlib import Path | |
| import xml.etree.ElementTree as ET | |
| import numpy as np | |
| from scipy.spatial.transform import Rotation | |
| def origin(xyz='0 0 0',rpy='0 0 0'): | |
| t=np.eye(4);t[:3,:3]=Rotation.from_euler('xyz',np.fromstring(rpy,sep=' ')).as_matrix();t[:3,3]=np.fromstring(xyz,sep=' ');return t | |
| class RobotVisualFK: | |
| def __init__(self,assets): | |
| self.assets=Path(assets);root=ET.parse(self.assets/'robot.urdf').getroot();self.joints={} | |
| for j in root.findall('joint'): | |
| o=j.find('origin');a=j.find('axis') | |
| self.joints[j.find('child').get('link')]=dict(name=j.get('name'),parent=j.find('parent').get('link'),kind=j.get('type'),T=origin(o.get('xyz','0 0 0'),o.get('rpy','0 0 0')) if o is not None else np.eye(4),axis=np.fromstring(a.get('xyz') if a is not None else '1 0 0',sep=' ')) | |
| self.visuals=json.loads((self.assets/'manifest.json').read_text())['meshes'];self.meshes={x['mesh']:dict(np.load(self.assets/x['mesh'])) for x in self.visuals} | |
| def poses(self,q): | |
| q=np.asarray(q);assert q.shape==(14,) | |
| scale=(np.pi/180)/.017444;values={} | |
| for prefix,offset in [('fl_',0),('fr_',7)]: | |
| for i in range(6):values[prefix+f'joint{i+1}']=q[offset+i]*scale | |
| # Driver gripper field is aperture in metres. Symmetric jaws split aperture. | |
| aperture=float(q[offset+6]) | |
| if not np.isfinite(aperture):raise ValueError('Nonfinite gripper aperture') | |
| # Do not silently clamp recorded widths to stale URDF limits. | |
| # Diagnostic extrapolation only; calibration gate remains unverified. | |
| values[prefix+'joint7']=max(0,aperture)/2 | |
| values[prefix+'joint8']=-max(0,aperture)/2 | |
| cache={} | |
| def pose(link): | |
| if link not in cache: | |
| if link not in self.joints:cache[link]=np.eye(4) | |
| else: | |
| j=self.joints[link];t=j['T'].copy() | |
| if j['kind']!='fixed': | |
| v=values[j['name']];m=np.eye(4) | |
| if j['kind']=='prismatic':m[:3,3]=j['axis']*v | |
| else:m[:3,:3]=Rotation.from_rotvec(j['axis']*v).as_matrix() | |
| t=t@m | |
| cache[link]=pose(j['parent'])@t | |
| return cache[link] | |
| base=pose('footprint');inv=np.linalg.inv(base) | |
| return {v['link']:inv@pose(v['link']) for v in self.visuals} | |
| def __call__(self,q,T_camera_footprint): | |
| poses=self.poses(q);out=[] | |
| for v in self.visuals: | |
| m=self.meshes[v['mesh']];t=np.asarray(T_camera_footprint)@poses[v['link']]@origin(v['xyz'],v['rpy']) | |
| xyz=m['vertices']*np.fromstring(v['scale'],sep=' ') | |
| xyz=xyz@t[:3,:3].T+t[:3,3] | |
| link=v['link'];side='left' if link.startswith('fl_') else 'right' | |
| owner=side+'_fingers' if link.endswith(('link7','link8')) else 'robot' | |
| out.append(dict(vertices_camera=xyz,faces=m['faces'],owner=owner)) | |
| return out | |