Skip to content

Commit

Permalink
Merged in allow_static_models_without_links (pull request gazebosim#626)
Browse files Browse the repository at this point in the history
Allow static models without links

Approved-by: Ian Chen <ichen@osrfoundation.org>
Approved-by: Eric Cousineau <eacousineau@gmail.com>
Approved-by: Addisu Z. Taddese <addisu@openrobotics.org>
  • Loading branch information
scpeters committed Dec 6, 2019
2 parents 5bd9639 + 678330b commit 4fa3f81
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
1. sdf 1.7: add `//model/@canonical_link` attribute and require models to have at least one link.
* [Pull request 601](https://bitbucket.org/osrf/sdformat/pull-requests/601)

1. Static models: allow them to have no links and skip building FrameAttachedToGraph.
* [Pull request 626](https://bitbucket.org/osrf/sdformat/pull-requests/626)

1. sdf 1.7: add `//frame/attached_to`, only allow frames in model and world, add Frame DOM.
* [pull request 603](https://bitbucket.org/osrf/sdformat/pull-requests/603)

Expand Down
6 changes: 4 additions & 2 deletions Migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ but with improved human-readability..
1. **model.sdf** `//model/@canonical_link` attribute
+ description: The name of the canonical link in this model to which the
model's implicit frame is attached. This implies that a model must have
at least one link, which is also stated in the Modifications section.
at least one link (unless it is static), which is also stated in the
Modifications section.
+ type: string
+ default: ""
+ required: 0
Expand All @@ -210,9 +211,10 @@ but with improved human-readability..

### Modifications

1. A model must have at least one link, as specified in the
1. A non-static model must have at least one link, as specified in the
[proposal](http://sdformat.org/tutorials?tut=pose_frame_semantics_proposal&cat=pose_semantics_docs&#2-model-frame-and-canonical-link).
+ [pull request 601](https://bitbucket.org/osrf/sdformat/pull-requests/601)
+ [pull request 626](https://bitbucket.org/osrf/sdformat/pull-requests/626)

1. Unique names for all sibling elements:
+ As described in the [proposal](http://sdformat.org/tutorials?tut=pose_frame_semantics_proposal&cat=pose_semantics_docs&#3-2-unique-names-for-all-sibling-elements),
Expand Down
37 changes: 23 additions & 14 deletions src/Model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,10 @@ Errors Model::Load(ElementPtr _sdf)
frameNames.insert(link.Name());
}

// If the model is not static:
// Require at least one link so the implicit model frame can be attached to
// something.
if (this->dataPtr->links.empty())
if (!this->Static() && this->dataPtr->links.empty())
{
errors.push_back({ErrorCode::MODEL_WITHOUT_LINK,
"A model must have at least one link."});
Expand Down Expand Up @@ -320,21 +321,29 @@ Errors Model::Load(ElementPtr _sdf)
}

// Build the graphs.
this->dataPtr->frameAttachedToGraph
= std::make_shared<FrameAttachedToGraph>();
Errors frameAttachedToGraphErrors =
buildFrameAttachedToGraph(*this->dataPtr->frameAttachedToGraph, this);
errors.insert(errors.end(), frameAttachedToGraphErrors.begin(),
frameAttachedToGraphErrors.end());
Errors validateFrameAttachedGraphErrors =
validateFrameAttachedToGraph(*this->dataPtr->frameAttachedToGraph);
errors.insert(errors.end(), validateFrameAttachedGraphErrors.begin(),
validateFrameAttachedGraphErrors.end());
for (auto &frame : this->dataPtr->frames)
{
frame.SetFrameAttachedToGraph(this->dataPtr->frameAttachedToGraph);

// Build the FrameAttachedToGraph if the model is not static.
// Re-enable this when the buildFrameAttachedToGraph implementation handles
// static models.
if (!this->Static())
{
this->dataPtr->frameAttachedToGraph
= std::make_shared<FrameAttachedToGraph>();
Errors frameAttachedToGraphErrors =
buildFrameAttachedToGraph(*this->dataPtr->frameAttachedToGraph, this);
errors.insert(errors.end(), frameAttachedToGraphErrors.begin(),
frameAttachedToGraphErrors.end());
Errors validateFrameAttachedGraphErrors =
validateFrameAttachedToGraph(*this->dataPtr->frameAttachedToGraph);
errors.insert(errors.end(), validateFrameAttachedGraphErrors.begin(),
validateFrameAttachedGraphErrors.end());
for (auto &frame : this->dataPtr->frames)
{
frame.SetFrameAttachedToGraph(this->dataPtr->frameAttachedToGraph);
}
}

// Build the PoseRelativeToGraph
this->dataPtr->poseGraph = std::make_shared<PoseRelativeToGraph>();
Errors poseGraphErrors =
buildPoseRelativeToGraph(*this->dataPtr->poseGraph, this);
Expand Down
2 changes: 1 addition & 1 deletion test/sdf/root_multiple_models.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<link name="link"/>
</model>
<model name="last_robot">
<link name="link"/>
<static>true</static>
</model>
</sdf>

0 comments on commit 4fa3f81

Please sign in to comment.