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

Add Model::CanonicalLink getter #1594

Merged
merged 1 commit into from
Jul 15, 2022
Merged
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
6 changes: 6 additions & 0 deletions include/ignition/gazebo/Model.hh
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ namespace ignition
public: void SetWorldPoseCmd(EntityComponentManager &_ecm,
const math::Pose3d &_pose);

/// \brief Get the model's canonical link entity.
/// \param[in] _ecm Entity-component manager.
/// \return Link entity.
public: gazebo::Entity CanonicalLink(
const EntityComponentManager &_ecm) const;

/// \brief Pointer to private data.
private: std::unique_ptr<ModelPrivate> dataPtr;
};
Expand Down
8 changes: 8 additions & 0 deletions src/Model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*
*/

#include "ignition/gazebo/components/CanonicalLink.hh"
#include "ignition/gazebo/components/Joint.hh"
#include "ignition/gazebo/components/Link.hh"
#include "ignition/gazebo/components/Model.hh"
Expand Down Expand Up @@ -193,3 +194,10 @@ void Model::SetWorldPoseCmd(EntityComponentManager &_ecm,
}
}

//////////////////////////////////////////////////
Entity Model::CanonicalLink(const EntityComponentManager &_ecm) const
{
return _ecm.EntityByComponents(
components::ParentEntity(this->dataPtr->id),
components::CanonicalLink());
}
30 changes: 30 additions & 0 deletions test/integration/model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <ignition/gazebo/EntityComponentManager.hh>
#include <ignition/gazebo/Model.hh>
#include <ignition/gazebo/components/CanonicalLink.hh>
#include <ignition/gazebo/components/Joint.hh>
#include <ignition/gazebo/components/Link.hh>
#include <ignition/gazebo/components/Model.hh>
Expand Down Expand Up @@ -232,3 +233,32 @@ TEST_F(ModelIntegrationTest, SetWorldPoseCmd)
EXPECT_TRUE(ecm.HasOneTimeComponentChanges());
}

//////////////////////////////////////////////////
TEST_F(ModelIntegrationTest, CanonicalLink)
{
EntityComponentManager ecm;

// Model
auto eModel = ecm.CreateEntity();
Model model(eModel);
EXPECT_EQ(eModel, model.Entity());
EXPECT_EQ(0u, model.LinkCount(ecm));

// Links
auto canonicalLink = ecm.CreateEntity();
ecm.CreateComponent(canonicalLink, components::Link());
ecm.CreateComponent(canonicalLink, components::CanonicalLink());
ecm.CreateComponent(canonicalLink,
components::ParentEntity(eModel));
ecm.CreateComponent(canonicalLink, components::Name("canonical"));

auto anotherLink = ecm.CreateEntity();
ecm.CreateComponent(anotherLink, components::Link());
ecm.CreateComponent(anotherLink, components::ParentEntity(eModel));
ecm.CreateComponent(anotherLink, components::Name("another"));

// Check model
EXPECT_EQ(canonicalLink, model.CanonicalLink(ecm));
EXPECT_EQ(2u, model.LinkCount(ecm));
}