Skip to content

Commit

Permalink
Merge pull request #370 from marip8/update/task-composer-factory-cons…
Browse files Browse the repository at this point in the history
…tructor

Add new task composer plugin factory constructor
  • Loading branch information
marip8 authored Sep 22, 2023
2 parents 129694d + 7369172 commit 762398f
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/add_sources.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#! /bin/bash
apt update -qq
apt install -y --no-install-recommends software-properties-common
add-apt-repository -y ppa:ros-industrial/ppa
apt update -qq
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ class TaskComposerPluginFactory
TaskComposerPluginFactory(TaskComposerPluginFactory&&) = default;
TaskComposerPluginFactory& operator=(TaskComposerPluginFactory&&) = default;

/**
* @brief Load plugins from a configuration object
* @param config The config object
*/
TaskComposerPluginFactory(const tesseract_common::TaskComposerPluginInfo& config);

/**
* @brief Load plugins from yaml node
* @param config The config node
Expand All @@ -113,6 +119,12 @@ class TaskComposerPluginFactory
*/
TaskComposerPluginFactory(const std::string& config);

/**
* @brief Loads plugins from a configuration object
* @param config the config object
*/
void loadConfig(const tesseract_common::TaskComposerPluginInfo& config);

/**
* @brief Load plugins from yaml node
* @param config The config node
Expand Down
19 changes: 19 additions & 0 deletions tesseract_task_composer/core/src/task_composer_plugin_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ TaskComposerPluginFactory::TaskComposerPluginFactory()
boost::token_compress_on);
}

TaskComposerPluginFactory::TaskComposerPluginFactory(const tesseract_common::TaskComposerPluginInfo& config)
: TaskComposerPluginFactory()
{
loadConfig(config);
}

TaskComposerPluginFactory::TaskComposerPluginFactory(const YAML::Node& config) : TaskComposerPluginFactory()
{
loadConfig(config);
Expand All @@ -69,6 +75,19 @@ TaskComposerPluginFactory::TaskComposerPluginFactory(const std::string& config)
// If not the forward declare of PluginLoader cause compiler error.
TaskComposerPluginFactory::~TaskComposerPluginFactory() = default;

void TaskComposerPluginFactory::loadConfig(const tesseract_common::TaskComposerPluginInfo& config)
{
plugin_loader_.search_libraries.insert(config.search_libraries.begin(), config.search_libraries.end());
plugin_loader_.search_paths.insert(config.search_paths.begin(), config.search_paths.end());

executor_plugin_info_.plugins.insert(config.executor_plugin_infos.plugins.begin(),
config.executor_plugin_infos.plugins.end());
executor_plugin_info_.default_plugin = config.executor_plugin_infos.default_plugin;

task_plugin_info_.plugins.insert(config.task_plugin_infos.plugins.begin(), config.task_plugin_infos.plugins.end());
task_plugin_info_.default_plugin = config.task_plugin_infos.default_plugin;
}

void TaskComposerPluginFactory::loadConfig(const YAML::Node& config)
{
if (const YAML::Node& plugin_info = config[tesseract_common::TaskComposerPluginInfo::CONFIG_KEY])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ TESSERACT_COMMON_IGNORE_WARNINGS_POP
#include <tesseract_task_composer/core/task_composer_plugin_factory.h>
#include <tesseract_common/utils.h>
#include <tesseract_common/types.h>
#include <tesseract_common/yaml_utils.h>

using namespace tesseract_planning;

Expand Down Expand Up @@ -157,6 +158,32 @@ TEST(TesseractTaskComposerFactoryUnit, LoadAndExportPluginTest) // NOLINT
TaskComposerPluginFactory check_factory(export_config_path);
runTaskComposerFactoryTest(check_factory, plugin_config);
}

// TaskComposerPluginInfo Constructor
{
tesseract_common::fs::path config_path(std::string(TESSERACT_TASK_COMPOSER_DIR) + "/config/"
"task_composer_plugins.yaml");

YAML::Node plugin_config = YAML::LoadFile(config_path.string());
const YAML::Node& plugins = plugin_config[tesseract_common::TaskComposerPluginInfo::CONFIG_KEY];
const auto search_paths = plugins["search_paths"].as<std::vector<std::string>>();
const auto search_libraries = plugins["search_libraries"].as<std::vector<std::string>>();

tesseract_common::TaskComposerPluginInfo info;
info.search_paths.insert(search_paths.begin(), search_paths.end());
info.search_libraries.insert(search_libraries.begin(), search_libraries.end());
info.task_plugin_infos.plugins = plugins["tasks"]["plugins"].as<tesseract_common::PluginInfoMap>();
info.executor_plugin_infos.plugins = plugins["executors"]["plugins"].as<tesseract_common::PluginInfoMap>();
info.executor_plugin_infos.default_plugin = plugins["executors"]["default"].as<std::string>();

TaskComposerPluginFactory factory(info);
runTaskComposerFactoryTest(factory, plugin_config);

auto export_config_path = tesseract_common::fs::path(tesseract_common::getTempPath()) / "task_composer_plugins_"
"export.yaml";
TaskComposerPluginFactory check_factory(export_config_path);
runTaskComposerFactoryTest(check_factory, plugin_config);
}
}

TEST(TesseractTaskComposerFactoryUnit, PluginFactorAPIUnit) // NOLINT
Expand Down

0 comments on commit 762398f

Please sign in to comment.