by John Lauer
ZLTECH ZLLG16ASM800 V2.0: 16 inch (398 mm) 48 V direct drive hub servo motor, 17 N m rated, 51 N m peak, 150 rpm, 20 pole pairs, 4096-line encoder with Halls and thermistor. 3D model, dimensions and wiring.
main
John Lauer
Add README, license and 3D model provenance
22bfcfd
import json,struct
def load(p):
b=open(p,'rb').read()
assert b[:4]==b'glTF'
off=12; js=None; bn=b''
while off<len(b):
ln,ty=struct.unpack_from('<II',b,off); data=b[off+8:off+8+ln]; off+=8+ln
if ty==0x4E4F534A: js=json.loads(data)
elif ty==0x004E4942: bn=data
return js,bn
def save(p,js,bn):
j=json.dumps(js,separators=(',',':'),ensure_ascii=False).encode('utf-8')
j+=b' '*((4-len(j)%4)%4); bn=bn+b'\0'*((4-len(bn)%4)%4)
out=struct.pack('<4sII',b'glTF',2,12+8+len(j)+8+len(bn))+struct.pack('<II',len(j),0x4E4F534A)+j+struct.pack('<II',len(bn),0x004E4942)+bn
open(p,'wb').write(out)
import numpy as np
CT={5120:('i1',127.0),5121:('u1',255.0),5122:('<i2',32767.0),5123:('<u2',65535.0),5125:('<u4',None),5126:('<f4',None)}
NC={'SCALAR':1,'VEC2':2,'VEC3':3,'VEC4':4,'MAT4':16}
def acc(js,bn,i):
a=js['accessors'][i]; bv=js['bufferViews'][a['bufferView']]
dt,norm=CT[a['componentType']]; n=NC[a['type']]
off=bv.get('byteOffset',0)+a.get('byteOffset',0); stride=bv.get('byteStride')
isz=np.dtype(dt).itemsize*n
if stride and stride!=isz:
raw=np.frombuffer(bn,dtype=np.uint8,count=stride*(a['count']-1)+isz,offset=off)
idx=(np.arange(a['count'])[:,None]*stride+np.arange(isz)[None,:])
arr=np.frombuffer(raw[idx].tobytes(),dtype=dt).reshape(a['count'],n)
else:
arr=np.frombuffer(bn,dtype=dt,count=a['count']*n,offset=off).reshape(a['count'],n)
arr=arr.astype(np.float64)
if a.get('normalized'): arr=np.maximum(arr/norm,-1.0) if dt[-2]=='i' else arr/norm
return arr
def local(n):
if 'matrix' in n: return np.array(n['matrix'],float).reshape(4,4).T
t=n.get('translation',[0,0,0]); r=n.get('rotation',[0,0,0,1]); s=n.get('scale',[1,1,1])
x,y,z,w=r
R=np.array([[1-2*(y*y+z*z),2*(x*y-z*w),2*(x*z+y*w)],[2*(x*y+z*w),1-2*(x*x+z*z),2*(y*z-x*w)],[2*(x*z-y*w),2*(y*z+x*w),1-2*(x*x+y*y)]])
M=np.eye(4); M[:3,:3][email protected](s); M[:3,3]=t; return M
def world(js):
W={}
def rec(i,P):
M=P@local(js['nodes'][i]); W[i]=M
for c in js['nodes'][i].get('children',[]): rec(c,M)
for r in js['scenes'][js.get('scene',0)]['nodes']: rec(r,np.eye(4))
return W
def mesh_points(js,bn,ni,W):
out=[]
for p in js['meshes'][js['nodes'][ni]['mesh']]['primitives']:
v=acc(js,bn,p['attributes']['POSITION'])
out.append((W[ni]@np.c_[v,np.ones(len(v))].T).T[:,:3])
return out