"""Draw the geometry, contact-to-point calculation and recorded loading sequence.""" from pathlib import Path import json import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt from matplotlib.patches import FancyBboxPatch import numpy as np ROOT = Path(__file__).resolve().parents[1] OUTPUT = ROOT / 'renders/tactile' plt.rcParams.update({'font.size': 11, 'axes.spines.top': False, 'axes.spines.right': False}) config = json.loads((ROOT / 'sensors/paxini_m3025/config/m3025.json').read_text(encoding='utf-8')) points = np.asarray(config['positions_m']) * 1000 normals = np.asarray(config['outward_normals_sensor']) data = np.load(ROOT / 'validation/tactile/gripper_newton.npz') time = data['time_s'] index = int(np.argmin(abs(time - 1.95))) force = data['forces_sensor_n'][index, 0] compression = data['normal_compression_n'][index, 0] fig = plt.figure(figsize=(14, 8.5), dpi=160, facecolor='#f4f7fb') grid = fig.add_gridspec(2, 3, left=.055, right=.955, top=.82, bottom=.12, wspace=.36, hspace=.56) ax = fig.add_subplot(grid[0, 0], projection='3d') ax.scatter(*points.T, c=normals[:, 2], cmap='Blues', s=26, vmin=-.2, vmax=1) ax.quiver(*points[::5].T, *normals[::5].T, length=3, color='#2476a7', linewidth=.6) ax.set(xlabel='x (mm)', ylabel='y (mm)', zlabel='z (mm)', title='Vendor geometry and 77 sensing positions') ax.view_init(elev=27, azim=-66) ax.set_box_aspect([25, 31, 10]) ax = fig.add_subplot(grid[0, 1]) ax.axis('off') ax.text(0, .92, 'Rigid-body contact solver', fontsize=15, weight='bold') ax.text(0, .72, 'MuJoCo / Isaac PhysX / Isaac Newton', fontsize=11) ax.text(0, .58, 'Per contact:\nposition + outward normal\nnormal force + friction force', fontsize=12, linespacing=1.6, va='top') ax.text(0, .04, 'Newton uses actual MuJoCo Warp\ncontact forces on the CUDA device.', fontsize=11, color='#496278') ax = fig.add_subplot(grid[0, 2]) scatter = ax.scatter(points[:, 0], points[:, 1], c=compression, s=85, cmap='viridis', edgecolors='#556677', lw=.4) ax.quiver(points[:, 0], points[:, 1], force[:, 0], force[:, 1], color='#d45d34', angles='xy', scale_units='xy', scale=.02, width=.008) ax.set(xlabel='Sensor x (mm)', ylabel='Sensor y (mm)', title='Left array: recorded Newton contact', aspect='equal') fig.colorbar(scatter, ax=ax, label='Local compression (N)', fraction=.05, pad=.04) ax = fig.add_subplot(grid[1, :2]) ax.axis('off') ax.text(0, 1, 'Contact-to-point observation model', fontsize=15, weight='bold') ax.text(0, .71, r'$w_i = \frac{\exp[-\|\mathbf{p}_i-\mathbf{p}_c\|^2/(2\sigma^2)]\,a_i^2}' r'{\sum_j \exp[-\|\mathbf{p}_j-\mathbf{p}_c\|^2/(2\sigma^2)]\,a_j^2}$', fontsize=19) ax.text(0, .43, r'$a_i=\max(\mathbf{n}_i\cdot\mathbf{n}_c,0),\qquad\mathbf{f}_i=\sum_c w_{ic}\mathbf{f}_c$', fontsize=17) ax.text(0, .14, 'Spatial width = 2.5 mm; acceptance distance = 4 mm. Both are uncalibrated.\n' 'Only aligned points within four spatial widths receive force.\n' 'Accepted total force is conserved; distributed point moments are not conserved.', fontsize=10, linespacing=1.5) ax = fig.add_subplot(grid[1, 2]) for side, color in enumerate(['#1676b9', '#dd682b']): ax.plot(time, -data['contact_wrench_sensor'][:, side, 2], color=color, label=['Left', 'Right'][side], lw=1.2) ax.axvspan(2.1, 2.7, color='#e0e7ee', label='Block translation') ax.set(xlabel='Time (s)', ylabel='Compression -Fz (N)', title='Close, hold, translate and release') ax.grid(alpha=.2) ax.legend(fontsize=9, loc='upper right') fig.suptitle('M3025 contact observation for the complete custom gripper', x=.055, ha='left', y=.96, fontsize=22, weight='bold', color='#17394c') fig.text(.055, .89, 'Simulation contact data are transformed into each sensor frame, then distributed over the vendor point coordinates.', fontsize=12, color='#496278') fig.text(.055, .035, 'Reference: OpenTac separates contact mechanics and sensor readout. This implementation uses a separate, uncalibrated model.\n' 'No continuous elastic layer, magnetic field, Hall electronics or measured hardware accuracy is simulated.', fontsize=10, color='#496278') fig.savefig(OUTPUT / 'm3025_contact_method.png') plt.close(fig) fig, axes = plt.subplots(3, 4, figsize=(12, 10), dpi=160, sharex=True, sharey=True) for row, engine in enumerate(['mujoco', 'physx', 'newton']): d = np.load(ROOT / 'validation/tactile' / f'gripper_{engine}.npz') for column, target in enumerate([.2, 1.95, 2.8, 4.1]): sample = np.argmin(abs(d['time_s'] - target)) ax = axes[row, column] sc = ax.scatter(points[:, 0], points[:, 1], c=d['normal_compression_n'][sample, 0], s=45, cmap='viridis', vmin=0, vmax=.4, edgecolors='#556677', lw=.25) ax.set_aspect('equal') if row == 0: ax.set_title(['Open', 'Hold contact', 'After translation', 'Released'][column]) if column == 0: ax.set_ylabel(engine+'\nSensor y (mm)') if row == 2: ax.set_xlabel('Sensor x (mm)') ax.text(.03, .97, f"{d['time_s'][sample]:.3f} s", transform=ax.transAxes, va='top', fontsize=9, bbox={'facecolor':'white','alpha':.85,'edgecolor':'none','pad':1}) fig.subplots_adjust(right=.89, top=.9, bottom=.08, wspace=.28, hspace=.25) cax = fig.add_axes([.92, .2, .013, .55]) fig.colorbar(sc, cax=cax, label='Local compression (N); values above 0.4 N use the top colour', extend='max') fig.suptitle('Left M3025 array: unfiltered recorded force distributions\nSame 77 vendor positions and colour scale in all three environments', fontsize=15) fig.savefig(OUTPUT / 'gripper_three_environment_sequence.png') plt.close(fig)