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

Write example on how to link to gzyarp::DeviceRegistry #162

Open
traversaro opened this issue Apr 12, 2024 · 1 comment
Open

Write example on how to link to gzyarp::DeviceRegistry #162

traversaro opened this issue Apr 12, 2024 · 1 comment

Comments

@traversaro
Copy link
Member

traversaro commented Apr 12, 2024

External projects may want to be able to use the gzyarp::DeviceRegistry class, mainly for:

  • Get a pointer to the YARP devices created by gz-sim-yarp-plugins
  • Add new YARP devices to the gzyarp::DeviceRegistry singleton, so that devices added by plugins written in the style of gz-sim-yarp-plugins but mantained in downstream repos can create devices that then can be accessed by gz-sim-yarp-robotinterface-system .

The example can be something like:

CMakeLists.txt

cmake_minimum_required(VERSION 3.16)
project(gzyarp-deviceregistry-example)

# Find gz-sim-yarp-plugins package
find_package(gz-sim-yarp-plugins REQUIRED)

add_executable(my_executable example.cpp)

target_link_libraries(my_executable PRIVATE gz-sim-yarp-plugins::gz-sim-yarp-device-registry)

example.cpp:

#include <iostream>
#include <gzyarp/DeviceRegistry.h>

int main() 
{
    std::vector<std::string> modelScopedNames;

    // This functions does no exist at the moment
    gzyarp::DeviceRegistry::getHandler()->getModelScopedNames(modelScopedNames);

    // Perform some operations with gzyarp::DeviceRegistry
    // For example, print the number of devices
    std::cout << "Number of models for which registered devices exist: " << modelScopedNames.size() << std::endl;

    return 0;
}
@traversaro
Copy link
Member Author

No need to do this know, but I wanted show to @xela-95 how then the library is consumed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant