Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dart soft box #3052

Open
wants to merge 2 commits into
base: gazebo11
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions gazebo/physics/dart/DARTBoxShape.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ void DARTBoxShape::Init()
this->dataPtr->CreateShape(bodyNode);
_collisionParent->SetDARTCollisionShapeNode(
this->dataPtr->ShapeNode(), false);

this->isSoftBody = _collisionParent->IsSoftBody();

BoxShape::Init();
}
Expand Down Expand Up @@ -97,6 +99,12 @@ void DARTBoxShape::SetSize(const ignition::math::Vector3d &_size)

BoxShape::SetSize(size);

// Rigid Bone at the core of the soft body which is 0.6 times smaller
if(this->isSoftBody)
{
size *= 0.6;
}

GZ_ASSERT(this->dataPtr->Shape(),
"Box shape node or shape itself is NULL");
this->dataPtr->Shape()->setSize(DARTTypes::ConvVec3(size));
Expand Down
3 changes: 3 additions & 0 deletions gazebo/physics/dart/DARTBoxShape.hh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ namespace gazebo
/// \internal
/// \brief Pointer to private data
private: DARTBoxShapePrivate *dataPtr;

/// \brief True if this link is soft body.
private: bool isSoftBody;
};
/// \}
}
Expand Down
6 changes: 6 additions & 0 deletions gazebo/physics/dart/DARTCollision.cc
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ dart::dynamics::BodyNode *DARTCollision::DARTBodyNode() const
return boost::static_pointer_cast<DARTLink>(this->link)->DARTBodyNode();
}

//////////////////////////////////////////////////
bool DARTCollision::IsSoftBody() const
{
return boost::static_pointer_cast<DARTLink>(this->link)->IsSoftBody();
}

//////////////////////////////////////////////////
void DARTCollision::SetDARTCollisionShapeNode(
dart::dynamics::ShapeNodePtr _shape,
Expand Down
4 changes: 4 additions & 0 deletions gazebo/physics/dart/DARTCollision.hh
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ namespace gazebo
/// \return Pointer to the dart BodyNode.
public: dart::dynamics::BodyNode *DARTBodyNode() const;

/// \brief Check is DART body is SoftBodyNode
/// \return True if this link is soft body.
public: bool IsSoftBody() const;

/// \brief Set DART collision shape.
/// \param[in] _shape DART Collision shape
/// \param[in] _placeable True to make the object movable.
Expand Down
22 changes: 17 additions & 5 deletions gazebo/physics/dart/DARTLink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,9 @@ void DARTLink::Load(sdf::ElementPtr _sdf)
if (softGeomElem->HasElement("box"))
{
sdf::ElementPtr boxEle = softGeomElem->GetElement("box");
Eigen::Vector3d size =
DARTTypes::ConvVec3(boxEle->Get<ignition::math::Vector3d>("size"));
Eigen::Vector3d boxSize = DARTTypes::ConvVec3(boxEle->Get<ignition::math::Vector3d>("size"));
softProperties = dart::dynamics::SoftBodyNodeHelper::makeBoxProperties(
size, T, fleshMassFraction, boneAttachment, stiffness, damping);
boxSize, T, Eigen::Vector3i(4, 4, 4), fleshMassFraction, boneAttachment, stiffness, damping);
}
// else if (geomElem->HasElement("ellipsoid"))
// {
Expand All @@ -167,13 +166,18 @@ void DARTLink::Load(sdf::ElementPtr _sdf)
gzerr << "Unknown soft shape" << std::endl;
}

softProperties.mKv = boneAttachment;
softProperties.mKe = stiffness;
softProperties.mDampCoeff = damping;

// Create DART SoftBodyNode properties
dart::dynamics::BodyNode::AspectProperties properties(bodyName);
this->dataPtr->dtProperties.reset(
new dart::dynamics::SoftBodyNode::Properties(
properties, softProperties));

this->dataPtr->isSoftBody;
this->dataPtr->isSoftBody = true;
this->dataPtr->fleshMass = fleshMassFraction;
}
else
{
Expand Down Expand Up @@ -268,8 +272,14 @@ void DARTLink::UpdateMass()
{
double nFragments = 1.0 + this->dataPtr->dtSlaveNodes.size();
double mass = this->inertial->Mass()/nFragments;
this->dataPtr->dtBodyNode->setMass(mass);

// Update mass of the underlying BodyNode
if(this->dataPtr->isSoftBody)
{
mass -= this->dataPtr->fleshMass;
}

this->dataPtr->dtBodyNode->setMass(mass);
const ignition::math::Quaterniond R_inertial = this->inertial->Pose().Rot();

const ignition::math::Matrix3d I_link =
Expand All @@ -278,6 +288,8 @@ void DARTLink::UpdateMass()
*ignition::math::Matrix3d(R_inertial.Inverse())
*(1.0/nFragments);

// Need to potentially update the objects inertia
// (as for box shape the body node is 0.6 times smaller)
this->dataPtr->dtBodyNode->setMomentOfInertia(
I_link(0, 0), I_link(1, 1), I_link(2, 2),
I_link(0, 1), I_link(0, 2), I_link(1, 2));
Expand Down
1 change: 1 addition & 0 deletions gazebo/physics/dart/DARTLink.hh
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ namespace gazebo
/// \brief Set pointer to DART BodyNode associated with this link.
/// \param[in] Pointer to DART BodyNode.
public: void SetDARTBodyNode(dart::dynamics::BodyNode *_dtBodyNode);
public: void SetDARTBodyNode(dart::dynamics::SoftBodyNode *_dtBodyNode);

/// \brief Add pointer to a BodyNode representing a fragment of this link.
/// \param[in] Pointer to DART BodyNode.
Expand Down
3 changes: 3 additions & 0 deletions gazebo/physics/dart/DARTLinkPrivate.hh
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ namespace gazebo
/// \brief True if this link is soft body.
public: bool isSoftBody;

/// \brief Mass of the softBody that envelopes the rigid bone.
public: double fleshMass;

/// \brief If true, freeze link to world (inertial) frame.
public: bool staticLink;

Expand Down
5 changes: 5 additions & 0 deletions gazebo/physics/dart/DARTModelPrivate.hh
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ namespace gazebo
_skeleton, _parent, jointType, jointProperties,
static_cast<const dart::dynamics::SoftBodyNode::Properties&>(
*(dartLink->DARTProperties())));

dart::dynamics::Inertia inertia;
inertia.setMoment(1e-8*Eigen::Matrix3d::Identity());
inertia.setMass(1e-8);
pair.second->setInertia(inertia);
}
else
{
Expand Down