4545// See https://github.com/dartsim/dart/pull/1626 and
4646// https://github.com/gazebo-forks/dart/pull/22 for more info.
4747#define DART_HAS_UPSTREAM_FRICTION_VARIABLE_NAMES
48+ // There's a sign difference between our fork and upstream dart in the
49+ // implementation of surface velocities. Here, we assume that 6.13 is the
50+ // upstream version. There's a potential that a user might update our fork to
51+ // version 6.13.0 or later. To support that case, we'll assume
52+ // DART_HAS_POSITIVE_CONTACT_SURFACE_MOTION_VELOCITY will be defined in the
53+ // fork. Note, if we simply check for
54+ // `DART_HAS_POSITIVE_CONTACT_SURFACE_MOTION_VELOCITY ` without the 6.13
55+ // condition above, we might break users that are building with our 6.10 fork
56+ // without updating or adding the
57+ // DART_HAS_POSITIVE_CONTACT_SURFACE_MOTION_VELOCITY define in their version of
58+ // dart.
59+ #ifndef DART_HAS_POSITIVE_CONTACT_SURFACE_MOTION_VELOCITY
60+ #define DART_HAS_NEGATIVE_CONTACT_SURFACE_MOTION_VELOCITY
61+ #endif
4862#endif
4963
5064namespace gz {
@@ -257,6 +271,17 @@ dart::constraint::ContactSurfaceParams GzContactSurfaceHandler::createParams(
257271 typedef FeaturePolicy3d P;
258272 typename F::ContactSurfaceParams<P> pGz;
259273
274+ auto convertMotionVelocity = [](Eigen::Vector3d _input) {
275+ #ifdef DART_HAS_NEGATIVE_CONTACT_SURFACE_MOTION_VELOCITY
276+ // The y and z components correspond to the velocities in the first and
277+ // second friction directions. These have to be inverted in the upstream
278+ // version of DART. https://github.com/gazebo-forks/dart/pull/33
279+ _input.y () = -_input.y ();
280+ _input.z () = -_input.z ();
281+ #endif
282+ return _input;
283+ };
284+
260285#ifdef DART_HAS_UPSTREAM_FRICTION_VARIABLE_NAMES
261286 pGz.frictionCoeff = pDart.mPrimaryFrictionCoeff ;
262287#else
@@ -271,7 +296,8 @@ dart::constraint::ContactSurfaceParams GzContactSurfaceHandler::createParams(
271296 pGz.secondarySlipCompliance = pDart.mSecondarySlipCompliance ;
272297 pGz.restitutionCoeff = pDart.mRestitutionCoeff ;
273298 pGz.firstFrictionalDirection = pDart.mFirstFrictionalDirection ;
274- pGz.contactSurfaceMotionVelocity = pDart.mContactSurfaceMotionVelocity ;
299+ pGz.contactSurfaceMotionVelocity =
300+ convertMotionVelocity (pDart.mContactSurfaceMotionVelocity );
275301
276302 auto contactInternal = this ->convertContact (_contact);
277303 if (contactInternal)
@@ -304,8 +330,10 @@ dart::constraint::ContactSurfaceParams GzContactSurfaceHandler::createParams(
304330 if (pGz.firstFrictionalDirection )
305331 pDart.mFirstFrictionalDirection = pGz.firstFrictionalDirection .value ();
306332 if (pGz.contactSurfaceMotionVelocity )
333+ {
307334 pDart.mContactSurfaceMotionVelocity =
308- pGz.contactSurfaceMotionVelocity .value ();
335+ convertMotionVelocity (pGz.contactSurfaceMotionVelocity .value ());
336+ }
309337
310338 static bool warnedRollingFrictionCoeff = false ;
311339 if (!warnedRollingFrictionCoeff && pGz.rollingFrictionCoeff )
0 commit comments