Skip to content

Commit

Permalink
Define verbose macros for dart version check
Browse files Browse the repository at this point in the history
Define DART_HAS_EACH_SHAPE_NODE_API and
DART_HAS_UPSTREAM_FRICTION_VARIABLE_NAMES so the
ifdef logic is more clear and readable.

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
  • Loading branch information
scpeters committed Jan 4, 2023
1 parent 1b9d528 commit 51a7fed
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
9 changes: 8 additions & 1 deletion dartsim/src/Base.hh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
#include <gz/common/Console.hh>
#include <gz/physics/Implements.hh>

#if DART_VERSION_AT_LEAST(6, 13, 0)
// The BodyNode::getShapeNodes method was deprecated in dart 6.13.0
// in favor of an iterator approach with BodyNode::eachShapeNode
// See https://github.com/dartsim/dart/pull/1644 for more info
#define DART_HAS_EACH_SHAPE_NODE_API
#endif

namespace ignition {
namespace physics {
namespace dartsim {
Expand Down Expand Up @@ -339,7 +346,7 @@ class Base : public Implements3d<FeatureList<Feature>>
}
for (auto &bn : skel->getBodyNodes())
{
#if DART_VERSION_AT_LEAST(6, 13, 0)
#ifdef DART_HAS_EACH_SHAPE_NODE_API
bn->eachShapeNode([this](dart::dynamics::ShapeNode *_sn)
{
this->shapes.RemoveEntity(_sn);
Expand Down
17 changes: 13 additions & 4 deletions dartsim/src/SimulationFeatures.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@
#include "gz/common/Profiler.hh"
#include "gz/physics/GetContacts.hh"

#if DART_VERSION_AT_LEAST(6, 13, 0)
// The ContactSurfaceParams class was first added to version 6.10 of our fork
// of dart, and then merged upstream and released in version 6.13.0 with
// different public member variable names.
// See https://github.com/dartsim/dart/pull/1626 and
// https://github.com/gazebo-forks/dart/pull/22 for more info.
#define DART_HAS_UPSTREAM_FRICTION_VARIABLE_NAMES
#endif

namespace ignition {
namespace physics {
namespace dartsim {
Expand Down Expand Up @@ -170,13 +179,13 @@ dart::constraint::ContactSurfaceParams IgnContactSurfaceHandler::createParams(
typedef FeaturePolicy3d P;
typename F::ContactSurfaceParams<P> pIgn;

#if DART_VERSION_AT_LEAST(6, 13, 0)
#ifdef DART_HAS_UPSTREAM_FRICTION_VARIABLE_NAMES
pIgn.frictionCoeff = pDart.mPrimaryFrictionCoeff;
#else
pIgn.frictionCoeff = pDart.mFrictionCoeff;
#endif
pIgn.secondaryFrictionCoeff = pDart.mSecondaryFrictionCoeff;
#if DART_VERSION_AT_LEAST(6, 13, 0)
#ifdef DART_HAS_UPSTREAM_FRICTION_VARIABLE_NAMES
pIgn.slipCompliance = pDart.mPrimarySlipCompliance;
#else
pIgn.slipCompliance = pDart.mSlipCompliance;
Expand All @@ -194,7 +203,7 @@ dart::constraint::ContactSurfaceParams IgnContactSurfaceHandler::createParams(

if (pIgn.frictionCoeff)
{
#if DART_VERSION_AT_LEAST(6, 13, 0)
#ifdef DART_HAS_UPSTREAM_FRICTION_VARIABLE_NAMES
pDart.mPrimaryFrictionCoeff = pIgn.frictionCoeff.value();
#else
pDart.mFrictionCoeff = pIgn.frictionCoeff.value();
Expand All @@ -204,7 +213,7 @@ dart::constraint::ContactSurfaceParams IgnContactSurfaceHandler::createParams(
pDart.mSecondaryFrictionCoeff = pIgn.secondaryFrictionCoeff.value();
if (pIgn.slipCompliance)
{
#if DART_VERSION_AT_LEAST(6, 13, 0)
#ifdef DART_HAS_UPSTREAM_FRICTION_VARIABLE_NAMES
pDart.mPrimarySlipCompliance = pIgn.slipCompliance.value();
#else
pDart.mSlipCompliance = pIgn.slipCompliance.value();
Expand Down

0 comments on commit 51a7fed

Please sign in to comment.