Skip to content

Commit

Permalink
Add Link::ResolveInertial API (#1012)
Browse files Browse the repository at this point in the history
The Link::Inertial() method returns an Inertial object with a Pose
specified relative to the link frame. This adds a new method for
resolving the Inertial's Pose to a specified frame. The method
is demonstrated in the `ign sdf --inertial-states` command code.

Fixed #935.

Signed-off-by: Steve Peters <[email protected]>
  • Loading branch information
scpeters authored May 23, 2022
1 parent a978ade commit a428e2a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
10 changes: 10 additions & 0 deletions include/sdf/Link.hh
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,16 @@ namespace sdf
/// \sa const ignition::math::Inertiald &Inertial() const
public: bool SetInertial(const ignition::math::Inertiald &_inertial);

/// \brief Resolve the Inertial to a specified frame.
/// If there are any errors resolving the Inertial, the output will not
/// be modified.
/// \param[out] _inertial The resolved Inertial.
/// \param[in] _resolveTo The Inertial will be resolved with respect to this
/// frame. If unset or empty, the default resolve-to frame will be used.
/// \return Errors in resolving pose.
public: Errors ResolveInertial(ignition::math::Inertiald &_inertial,
const std::string &_resolveTo = "") const;

/// \brief Get the pose of the link. This is the pose of the link
/// as specified in SDF (<link> <pose> ... </pose></link>).
/// \return The pose of the link.
Expand Down
15 changes: 15 additions & 0 deletions src/Link.cc
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,21 @@ bool Link::SetInertial(const ignition::math::Inertiald &_inertial)
return _inertial.MassMatrix().IsValid();
}

/////////////////////////////////////////////////
Errors Link::ResolveInertial(
ignition::math::Inertiald &_inertial,
const std::string &_resolveTo) const
{
ignition::math::Pose3d linkPose;
auto errors = this->SemanticPose().Resolve(linkPose, _resolveTo);
if (errors.empty())
{
_inertial = this->dataPtr->inertial;
_inertial.SetPose(linkPose * _inertial.Pose());
}
return errors;
}

/////////////////////////////////////////////////
const ignition::math::Pose3d &Link::Pose() const
{
Expand Down
8 changes: 2 additions & 6 deletions src/ign.cc
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,9 @@ extern "C" SDFORMAT_VISIBLE int cmdInertialStats(

for (uint64_t i = 0; i < model->LinkCount(); i++)
{
ignition::math::Pose3d linkPoseRelativeToModel;
errors = model->LinkByIndex(i)->SemanticPose().
Resolve(linkPoseRelativeToModel, "__model__");
ignition::math::Inertiald currentLinkInertial;
model->LinkByIndex(i)->ResolveInertial(currentLinkInertial, "__model__");

auto currentLinkInertial = model->LinkByIndex(i)->Inertial();
currentLinkInertial.SetPose(linkPoseRelativeToModel *
currentLinkInertial.Pose());
totalInertial += currentLinkInertial;
}

Expand Down

0 comments on commit a428e2a

Please sign in to comment.