robotology / gz-sim-yarp-plugins

YARP plugins for Modern Gazebo (gz-sim).
BSD 3-Clause "New" or "Revised" License
8 stars 2 forks source link

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

Open traversaro opened 5 months ago

traversaro commented 5 months ago

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

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 commented 5 months ago

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