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

Nkoenig/3 to 4 20210113 #554

Merged
merged 5 commits into from
Jan 13, 2021
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
20 changes: 19 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,25 @@

## Ignition Gazebo 3.x

### Ignition Gazebo 3.X.X (20XX-XX-XX)
### Ignition Gazebo 3.7.0 (2021-01-13)

1. Fix examples in migration plugins tutorial.
* [Pull Request 543](https://github.com/ignitionrobotics/ign-gazebo/pull/543)

1. Added missing namespace in `detail/EntityComponentManager.hh`.
* [Pull Request 541](https://github.com/ignitionrobotics/ign-gazebo/pull/541)

1. Automatically load a subset of world plugins.
* [Pull Request 281](https://github.com/ignitionrobotics/ign-gazebo/pull/281)

1. Update gtest to 1.10.0 for Windows compilation.
* [Pull Request 506](https://github.com/ignitionrobotics/ign-gazebo/pull/506)

1. Updates to ardupilot migration tutorial.
* [Pull Request 525](https://github.com/ignitionrobotics/ign-gazebo/pull/525)

1. Don't make docs on macOS.
* [Pull Request 528](https://github.com/ignitionrobotics/ign-gazebo/pull/528)

### Ignition Gazebo 3.6.0 (2020-12-30)

Expand Down
3 changes: 3 additions & 0 deletions include/ignition/gazebo/detail/EntityComponentManager.hh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ namespace ignition
{
namespace gazebo
{
// Inline bracket to help doxygen filtering.
inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {
//////////////////////////////////////////////////
namespace traits
{
Expand Down Expand Up @@ -547,5 +549,6 @@ bool EntityComponentManager::RemoveComponent(Entity _entity)
}
}
}
}

#endif
66 changes: 40 additions & 26 deletions tutorials/migration_plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ On Ignition Gazebo, that would be implemented as follows:
#include <ignition/gazebo/Model.hh>
#include <ignition/gazebo/Util.hh>
#include <ignition/gazebo/System.hh>
#include <ignition/plugin/Register.hh>
using namespace ignition;
using namespace gazebo;
using namespace systems;
// Inherit from System and 2 extra interfaces:
// ISystemConfigure and ISystemPostUpdate
Expand All @@ -113,25 +118,25 @@ class MyPlugin
{
// Implement Configure callback, provided by ISystemConfigure
// and called once at startup.
void MyPlugin::Configure(const Entity &_entity,
const std::shared_ptr<const sdf::Element> &_sdf,
EntityComponentManager &_ecm,
EventManager &/*_eventMgr*/)
virtual void Configure(const Entity &_entity,
const std::shared_ptr<const sdf::Element> &_sdf,
EntityComponentManager &_ecm,
EventManager &/*_eventMgr*/) override
{
// Read property from SDF
auto linkName = _sdf->Get<std::string>("link_name");
// Create model object, to access convenient functions
// Create model object to access convenient functions
auto model = Model(_entity);
// Get link entity
auto linkEntity = model->LinkByName(_ecm, linkName);
this->linkEntity = model.LinkByName(_ecm, linkName);
}
// Implement PostUpdate callback, provided by ISystemPostUpdate
// and called at every iteration, after physics is done
void MyPlugin::PostUpdate(const UpdateInfo &/*_info*/,
const EntityComponentManager &_ecm)
virtual void PostUpdate(const UpdateInfo &/*_info*/,
const EntityComponentManager &_ecm) override
{
// Get link pose and print it
std::cout << worldPose(this->linkEntity, _ecm) << std::endl;
Expand All @@ -149,7 +154,7 @@ IGNITION_ADD_PLUGIN(MyPlugin,
// Add plugin alias so that we can refer to the plugin without the version
// namespace
IGNITION_ADD_PLUGIN_ALIAS(MyPlugin,"ignition::gazebo::systems::MyPlugin")
IGNITION_ADD_PLUGIN_ALIAS(MyPlugin, "ignition::gazebo::systems::MyPlugin")
```

The example above uses headers like `Model.hh` and `Util.hh`, which offer
Expand All @@ -161,6 +166,15 @@ the ECM's API:
```cpp
#include <ignition/gazebo/EntityComponentManager.hh>
#include <ignition/gazebo/System.hh>
#include <ignition/gazebo/components/Link.hh>
#include <ignition/gazebo/components/Name.hh>
#include <ignition/gazebo/components/ParentEntity.hh>
#include <ignition/gazebo/components/Pose.hh>
#include <ignition/plugin/Register.hh>

using namespace ignition;
using namespace gazebo;
using namespace systems;

// Inherit from System and 2 extra interfaces:
// ISystemConfigure and ISystemPostUpdate
Expand All @@ -169,43 +183,43 @@ class MyPlugin
public ISystemConfigure,
public ISystemPostUpdate
{
void MyPlugin::Configure(const Entity &_entity,
const std::shared_ptr<const sdf::Element> &_sdf,
EntityComponentManager &_ecm,
EventManager &/*_eventMgr*/)
virtual void Configure(const Entity &_entity,
const std::shared_ptr<const sdf::Element> &_sdf,
EntityComponentManager &_ecm,
EventManager &/*_eventMgr*/) override
{
// Read property from SDF
auto linkName = _sdf->Get<std::string>("link_name");

// Create link entity by querying for an entity that has a specific set of
// Get link entity by querying for an entity that has a specific set of
// components
this->linkEntity = _ecm.EntityByComponents(
components::ParentEntity(this->dataPtr->id),
components::Name(_name),
components::Link());
components::ParentEntity(_entity),
components::Name(linkName), components::Link());
}

void MyPlugin::PostUpdate(const UpdateInfo &/*_info*/,
const EntityComponentManager &_ecm)
virtual void PostUpdate(const UpdateInfo &/*_info*/,
const EntityComponentManager &_ecm) override
{
// Get link's local pose
auto pose = _ecm.Component<components::Pose>(this->linkEntity)->Data();

// Get link's parent entity
auto p = _ecm.Component<components::ParentEntity>(this->linkEntity);
auto parent = _ecm.Component<components::ParentEntity>(this->linkEntity);

// Iterate over parents until world is reached
while (p)
while (parent)
{
// Get parent entity's pose
auto parentPose = _ecm.Component<components::Pose>(p->Data());
auto parentPose = _ecm.Component<components::Pose>(parent->Data());
if (!parentPose)
break;

// Add pose
pose = pose + parentPose->Data();
pose = parentPose->Data() * pose;

// keep going up the tree
p = _ecm.Component<components::ParentEntity>(p->Data());
parent = _ecm.Component<components::ParentEntity>(parent->Data());
}

std::cout << pose << std::endl;
Expand All @@ -220,7 +234,7 @@ IGNITION_ADD_PLUGIN(MyPlugin,
MyPlugin::ISystemConfigure,
MyPlugin::ISystemPostUpdate)

IGNITION_ADD_PLUGIN_ALIAS(MyPlugin,"ignition::gazebo::systems::MyPlugin")
IGNITION_ADD_PLUGIN_ALIAS(MyPlugin, "ignition::gazebo::systems::MyPlugin")
```
In summary, the key differences between Gazebo Classic and Ignition Gazebo are:
Expand All @@ -234,7 +248,7 @@ In summary, the key differences between Gazebo Classic and Ignition Gazebo are:
* Plugins don't have direct access to physics objects such as `physics::Model`.
Instead, they can either deal directly with entities and their components by
calling functions in the ECM, or using convenient objects such as
calling functions of the ECM, or use convenient objects such as
`ignition::gazebo::Model` which wrap the ECM interface.
All these changes are meant to give plugin developers more flexibility to
Expand Down