Skip to content

Commit e232265

Browse files
quaglacopybara-github
authored andcommitted
Tidy up of touch stress plugin.
PiperOrigin-RevId: 784186240 Change-Id: I47298ff2b7676a540781561817670c5f00c1b63a
1 parent bca5d0c commit e232265

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

plugin/sensor/touch_stress.cc

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,6 @@ void BinEdges(mjtNum* x_edges, mjtNum* y_edges, int size[2], mjtNum fov[2],
9696
mju_scl(y_edges, y_edges, fov[1]*mjPI / 180, size[1] + 1);
9797
}
9898

99-
// Permute 3-vector from 0,1,2 to 2,0,1.
100-
static void xyz2zxy(mjtNum* x) {
101-
mjtNum z = x[2];
102-
x[2] = x[1];
103-
x[1] = x[0];
104-
x[0] = z;
105-
}
106-
10799
// Transform spherical (azimuth, elevation, radius) to Cartesian (x,y,z).
108100
void SphericalToCartesian(const mjtNum aer[3], mjtNum xyz[3]) {
109101
mjtNum a = aer[0], e = aer[1], r = aer[2];
@@ -372,21 +364,17 @@ void TouchStress::Compute(const mjModel* m, mjData* d, int instance) {
372364
mju_sub3(vel_rel, vel_sensor+3, vel_other+3);
373365

374366
// Get contact force/torque, rotate into node frame.
375-
mjtNum force[3];
376-
mjtNum tmp_force[3], normal[3];
367+
mjtNum frc[3];
368+
mjtNum normal[3];
377369
mjtNum kMaxDepth = 0.05;
378370
mjtNum pressure = 1 / (kMaxDepth - depth) - 1 / kMaxDepth;
379371
mjc_gradient(m, d, &sensor_sdf, normal, pos);
380-
mju_scl3(tmp_force, normal, pressure);
381-
mju_mulMatTVec3(force, mat, tmp_force);
382-
force[0] = mju_abs(mju_dot3(vel_rel, mat + 0));
383-
force[1] = mju_abs(mju_dot3(vel_rel, mat + 3));
384-
385-
// Permute forces from x,y,z to z,x,y (normal, tangent, tangent)
386-
xyz2zxy(force);
387-
forcesT[0*ncon + node] = force[0];
388-
forcesT[1*ncon + node] = force[1];
389-
forcesT[2*ncon + node] = force[2];
372+
mju_scl3(frc, normal, pressure);
373+
374+
// one row of mat^T * force
375+
forcesT[0*ncon + node] = mat[2]*frc[0] + mat[5]*frc[1] + mat[8]*frc[2];
376+
forcesT[1*ncon + node] = mju_abs(mju_dot3(vel_rel, mat + 0));
377+
forcesT[2*ncon + node] = mju_abs(mju_dot3(vel_rel, mat + 3));
390378
node++;
391379
}
392380
}

0 commit comments

Comments
 (0)