Skip to content

Commit a428e2a

Browse files
authored
Add Link::ResolveInertial API (#1012)
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]>
1 parent a978ade commit a428e2a

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

include/sdf/Link.hh

+10
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,16 @@ namespace sdf
192192
/// \sa const ignition::math::Inertiald &Inertial() const
193193
public: bool SetInertial(const ignition::math::Inertiald &_inertial);
194194

195+
/// \brief Resolve the Inertial to a specified frame.
196+
/// If there are any errors resolving the Inertial, the output will not
197+
/// be modified.
198+
/// \param[out] _inertial The resolved Inertial.
199+
/// \param[in] _resolveTo The Inertial will be resolved with respect to this
200+
/// frame. If unset or empty, the default resolve-to frame will be used.
201+
/// \return Errors in resolving pose.
202+
public: Errors ResolveInertial(ignition::math::Inertiald &_inertial,
203+
const std::string &_resolveTo = "") const;
204+
195205
/// \brief Get the pose of the link. This is the pose of the link
196206
/// as specified in SDF (<link> <pose> ... </pose></link>).
197207
/// \return The pose of the link.

src/Link.cc

+15
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,21 @@ bool Link::SetInertial(const ignition::math::Inertiald &_inertial)
349349
return _inertial.MassMatrix().IsValid();
350350
}
351351

352+
/////////////////////////////////////////////////
353+
Errors Link::ResolveInertial(
354+
ignition::math::Inertiald &_inertial,
355+
const std::string &_resolveTo) const
356+
{
357+
ignition::math::Pose3d linkPose;
358+
auto errors = this->SemanticPose().Resolve(linkPose, _resolveTo);
359+
if (errors.empty())
360+
{
361+
_inertial = this->dataPtr->inertial;
362+
_inertial.SetPose(linkPose * _inertial.Pose());
363+
}
364+
return errors;
365+
}
366+
352367
/////////////////////////////////////////////////
353368
const ignition::math::Pose3d &Link::Pose() const
354369
{

src/ign.cc

+2-6
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,9 @@ extern "C" SDFORMAT_VISIBLE int cmdInertialStats(
204204

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

211-
auto currentLinkInertial = model->LinkByIndex(i)->Inertial();
212-
currentLinkInertial.SetPose(linkPoseRelativeToModel *
213-
currentLinkInertial.Pose());
214210
totalInertial += currentLinkInertial;
215211
}
216212

0 commit comments

Comments
 (0)