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

Automatically load required plugins for DriveToPoseController #2773

Open
sauk2 opened this issue Feb 13, 2025 · 0 comments
Open

Automatically load required plugins for DriveToPoseController #2773

sauk2 opened this issue Feb 13, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@sauk2
Copy link
Contributor

sauk2 commented Feb 13, 2025

Desired behavior

The DriveToPoseController system plugin (#2679) currently requires the DiffDrive and OdometryPublisher plugins to be manually attached to the model entity. The controller fails to function without these.

To improve usability, these dependencies should be loaded automatically if they are missing.

Alternatives considered

The current implementation verifies the existence of required publishers/subscribers and logs an error message if they are unavailable before exiting from the Configure callback and shutting down initialization.

Implementation suggestion

Two possible approaches to automatically load the required plugins:

  1. Using gz-transport: Send a request to the /entity/system/add service to load missing plugins dynamically, as shown in the following example implementation.

auto worldName = nameComp->Data();
msgs::EntityPlugin_V req;
req.mutable_entity()->set_id(world);
auto plugin = req.add_plugins();
plugin->set_name(preload_plugin_name);
plugin->set_filename(preload_plugin_filename);
plugin->set_innerxml("");
msgs::Boolean res;
bool result;
const unsigned int timeout = 5000;
const auto service = transport::TopicUtils::AsValidTopic(
"/world/" + worldName + "/entity/system/add");
if (service.empty())
{
gzerr << "Unable to request " << service << std::endl;
return;
}
if (this->dataPtr->node.Request(service, req, timeout, res, result))
{
gzdbg << "Added plugin successfully" << std::endl;
}
else
{
gzerr << "Failed to load plugin" << std::endl;
}

  1. Using LoadSdfPlugins event: Create entities for the missing plugins and use the ParentEntity component to attach them to the model entity.

/// \brief Event used to load plugins for an entity into simulation.
/// Pass in the entity which will own the plugins, and an SDF element for
/// the entity, which may contain multiple `<plugin>` tags.
/// Makre sure that you don't also connect to the LoadPlugins event.
using LoadSdfPlugins = common::EventT<void(Entity, sdf::Plugins),
struct LoadPluginsTag>;

Additional context

Refer to this conversation for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Inbox
Development

No branches or pull requests

1 participant