Skip to content

Commit

Permalink
Finish gz-sim-yarp-plugins-check-model
Browse files Browse the repository at this point in the history
  • Loading branch information
traversaro committed Aug 11, 2024
1 parent a86536f commit 81d3510
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/apt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
# YARP dependencies
sudo apt-get install git build-essential cmake ninja-build libace-dev libeigen3-dev libopencv-dev libtinyxml-dev
# gz-sim-yarp-plugins dependencies
sudo apt-get install gz-${{ matrix.gazebo_distro }}
sudo apt-get install gz-${{ matrix.gazebo_distro }} libcli11-dev
# Test dependencies
sudo apt-get install libgtest-dev
Expand Down
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ set(GZ_PLUGIN_VER ${gz-plugin2_VERSION_MAJOR})
gz_find_package(gz-sim8 REQUIRED)
set(GZ_SIM_VER ${gz-sim8_VERSION_MAJOR})

option(GZ_SIM_YARP_PLUGINS_BUILD_TOOLS "If enabled, build command line helper tools" ON)

if(GZ_SIM_YARP_PLUGINS_BUILD_TOOLS)
find_package(CLI11 REQUIRED)
endif()

# Defines the CMAKE_INSTALL_LIBDIR, CMAKE_INSTALL_BINDIR and many other useful macros.
# See https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html
include(GNUInstallDirs)
Expand Down
1 change: 1 addition & 0 deletions ci_env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ dependencies:
- yarp
- gtest
- cmake-package-check
- cli11
2 changes: 1 addition & 1 deletion docs/build-from-source.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ If you are using an apt-based distribution such as Ubuntu and you want to use ap

```bash
sudo apt-get update
sudo apt-get install lsb-release wget gnupg cmake pkg-config ninja-build build-essential libgtest-dev
sudo apt-get install lsb-release wget gnupg cmake pkg-config ninja-build build-essential libcli11-dev libgtest-dev
```

and then install Gazebo Harmonic:
Expand Down
4 changes: 2 additions & 2 deletions tests/gz-sim-yarp-plugins-check-model/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
macro(gsyp_add_tutorial_model_check tutorialname tutorialfolder worldname)
add_test(NAME gz-sim-yarp-plugins-check-model-tutorial-${tutorialname}
COMMAND gz-sim-yarp-plugins-check-model ./${worldname}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/tutorial/${tutorialfolder})
COMMAND gz-sim-yarp-plugins-check-model --world-file ./tutorial/${tutorialfolder}/${worldname}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
set(_env_vars)
list(APPEND _env_vars
"GZ_SIM_SYSTEM_PLUGIN_PATH=$<TARGET_FILE_DIR:gz-sim-yarp-device-registry>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,32 @@

#include <yarp/os/Network.h>

#include <CLI/CLI.hpp>

#include <DeviceRegistry.hh>


/////////////////////////////////////////////////
int main(int argc, char *argv[])
{
if (argc != 2)
{
std::cerr << "Usage: " << argv[0] << " ./path/to/world.sdf" << std::endl;
return EXIT_FAILURE;
}
CLI::App app{"gz-sim-yarp-plugins-check-models"};

std::string world_file;
std::string model_uri;

auto world_option = app.add_option("--world-file", world_file, "Path to the world file (for example ./path/world.sdf)");
auto model_option = app.add_option("--model-uri", model_uri, "URI to the model (for example model://ergoCub/robots/ergoCubGazeboV1_2)");

app.callback([&]() {
if (world_option->count() == 0 && model_option->count() == 0) {
throw CLI::ValidationError("You must specify either --world-file or --model-uri");
}
if (world_option->count() > 0 && model_option->count() > 0) {
throw CLI::ValidationError("You cannot specify both --world-file and --model-uri");
}
});

CLI11_PARSE(app, argc, argv);

// In case the modules include YARP devices that are YARP's Network Wrapper Server devices
// (i.e. devices that need to read or write from YARP ports), let's select local mode so
Expand All @@ -29,14 +44,25 @@ int main(int argc, char *argv[])
gz::sim::ServerConfig serverConfig;

// Populate with some configuration, for example, the SDF file to load
serverConfig.SetSdfFile(std::string(argv[1]));
if (world_option->count() > 0) {
// It seems that SetSdfFile prever absolute paths
serverConfig.SetSdfFile(world_file);
} else if (model_option->count() > 0) {
// Here we build an empty world with just the inclusion of the specified model
}

// Instantiate server
gz::sim::Server server(serverConfig);

// Run the server paused for 1 iterations blocking to see if the model loads correctly,
server.Run(true /*blocking*/, /*iterations*/ 1, /*paused*/false);

// If there were no iteration, then the server did not load correctly
if (server.IterationCount() != 1)
{
return EXIT_FAILURE;
}

// At this point. we run the server for one iteration, and we need to know if some plugin failed.
// As we own this process, we know that there was only one gz-sim server, so we can just check from the gzyarp::DeviceRegistry if there was any device that
// failed
Expand Down

0 comments on commit 81d3510

Please sign in to comment.