File size: 2,235 Bytes
d513eb2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Scientific playback of native rod poses, explicitly a material fixture."""
import argparse,json
from pathlib import Path
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation,PillowWriter

p=argparse.ArgumentParser();p.add_argument('result',type=Path);a=p.parse_args();root=a.result
r=json.loads((root/'report.json').read_text());d=np.load(root/'replay.npz');rows=json.loads((root/'trajectory.json').read_text())
assert r['status']=='completed';q=d['body_q'];ids=r['rod_bodies'];times=d['times']
fig=plt.figure(figsize=(11.5,5.3));ax=fig.add_subplot(121,projection='3d');chart=fig.add_subplot(122)
fig.subplots_adjust(left=.035,right=.98,bottom=.17,top=.89,wspace=.32)
ax.set(xlim=(-.2,.2),ylim=(-.2,.2),zlim=(0,.45),xlabel='x (m)',ylabel='y (m)',zlabel='z (m)')
ax.view_init(elev=22,azim=-65);ax.set_box_aspect((1,1,1.1));line,=ax.plot([],[],[],lw=2,color='#346d88');point,=ax.plot([],[],[],'o',color='#c56c36')
chart.plot([x['time'] for x in rows],[x['tip_z_m'] for x in rows],label='Measured upper endpoint height',color='#346d88')
chart.axvline(r['release_time_s'],ls='--',color='#c56c36',label='Fixture force removed');marker=chart.axvline(0,color='#263644',alpha=.5)
chart.set(xlabel='Simulation time (s)',ylabel='Endpoint height (m)',ylim=(0,.45));chart.legend(fontsize=8);chart.grid(alpha=.2)
label=fig.suptitle('');fig.text(.5,.025,'Native rod poses. Boundary-fixture diagnostic: no cloth, straps or robot. NOT a completed basket benchmark.',ha='center',fontsize=9)
def update(i):
    pts=q[i,ids,:3];line.set_data_3d(pts[:,0],pts[:,1],pts[:,2]);tip=q[i,r['tip_body'],:3];point.set_data_3d([tip[0]],[tip[1]],[tip[2]])
    marker.set_xdata([times[i],times[i]]);label.set_text(f"PL03 coil probe | gravity={r['args'].get('gravity',-9.81):g} m/s² | t={times[i]:.2f}s")
    return line,point,marker,label
indices=range(0,len(times),2);ani=FuncAnimation(fig,update,frames=indices,interval=40,blit=False)
ani.save(root/'mechanism_diagnostic.gif',writer=PillowWriter(fps=25));update(min(range(len(times)),key=lambda i:abs(times[i]-1.65)))
fig.savefig(root/'mechanism_diagnostic.png',dpi=160);plt.close(fig)
print(root/'mechanism_diagnostic.gif')