Skip to content

Commit 2f14e8b

Browse files
authored
dartsim: Fix sign convention error with contact surface motion velocities (#556)
* dartsim: Fix sign convention error with contact surface motion velocities This also enables a test that wasn't running due to a missing define. * Update to pre4 --------- Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
1 parent cc90439 commit 2f14e8b

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ find_package(gz-cmake3 REQUIRED)
1616
set(CMAKE_CXX_STANDARD 17)
1717
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1818

19-
gz_configure_project(VERSION_SUFFIX pre3)
19+
gz_configure_project(VERSION_SUFFIX pre4)
2020

2121
#============================================================================
2222
# Set project-specific options

dartsim/src/SimulationFeatures.cc

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@
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

5064
namespace 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)

test/common_test/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ foreach(test ${tests})
6767
"GZ_PHYSICS_RESOURCE_DIR=\"${GZ_PHYSICS_RESOURCE_DIR}\""
6868
)
6969

70+
if (DART_HAS_CONTACT_SURFACE_HEADER)
71+
target_compile_definitions(${test_executable} PRIVATE DART_HAS_CONTACT_SURFACE)
72+
endif()
73+
7074
install(TARGETS ${test_executable} DESTINATION ${TEST_INSTALL_DIR})
7175

7276
configure_common_test("bullet" ${test_executable})

test/common_test/simulation_features.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
#include "gz/physics/BoxShape.hh"
3838
#include <gz/physics/GetContacts.hh>
39+
#include "gz/physics/ContactProperties.hh"
3940
#include "gz/physics/CylinderShape.hh"
4041
#include "gz/physics/CapsuleShape.hh"
4142
#include "gz/physics/EllipsoidShape.hh"

0 commit comments

Comments
 (0)