diff --git a/README.md b/README.md index c1e960469ccdcaf2b9918905b7e10536c9e9af59..a8b2a0c1217e69fb4c70ecadab2eea4eceb08c1f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -WOLF - Windowed Localization Frames -=================================== +WOLF - Modular estimation framework for robotics based on factor graphs +======================================================================= -For installation guide and code documentation, please visit the [documentation website](http://mobile_robotics.pages.iri.upc-csic.es/wolf_projects/wolf_lib/wolf-doc-sphinx/). \ No newline at end of file +For installation guide and code documentation, please visit the [documentation website](http://www.iri.upc.edu/wolf). diff --git a/src/problem/problem.cpp b/src/problem/problem.cpp index a3981d2f9e1a8e2b08a25f290ee2e7cf60ffd6be..1e5c88a2db6cf68a2032c8be1b50dbbe3c2206d9 100644 --- a/src/problem/problem.cpp +++ b/src/problem/problem.cpp @@ -147,31 +147,6 @@ ProblemPtr Problem::autoSetup(ParamsServer &_server) loaders.push_back(l); } - // load Packages for subscribers and publishers - std::string packages_path; - try - { - packages_path = _server.getParam<std::string>("packages_path"); - } - catch (MissingValueException& e) { - WOLF_WARN(e.what()); - WOLF_WARN("Support for subscribers disabled..."); - } - for (auto subscriber_name : _server.getParam<std::vector<std::string>>("packages_subscriber")) { - std::string subscriber = packages_path + "/libsubscriber_" + subscriber_name + lib_extension; - WOLF_TRACE("Loading subscriber " + subscriber_name + " via " + subscriber); - auto l = std::make_shared<LoaderRaw>(subscriber); - l->load(); - loaders.push_back(l); - } - for (auto publisher_name : _server.getParam<std::vector<std::string>>("packages_publisher")) { - std::string publisher = packages_path + "/libpublisher_" + publisher_name + lib_extension; - WOLF_TRACE("Loading publisher " + publisher_name + " via " + publisher); - auto l = std::make_shared<LoaderRaw>(publisher); - l->load(); - loaders.push_back(l); - } - // load raw libs std::vector<std::string> raw_libs; try @@ -219,14 +194,7 @@ ProblemPtr Problem::autoSetup(ParamsServer &_server) map_plugin = "core"; } WOLF_TRACE("Map Type: ", map_type, " in plugin ", map_plugin); - if (map_plugin != "core" and map_plugin != "wolf") - { - std::string plugin = plugins_path + "libwolf" + map_plugin + lib_extension; - WOLF_TRACE("Loading plugin " + plugin); - auto l = std::make_shared<LoaderRaw>(plugin); - l->load(); - loaders.push_back(l); - } + auto map = AutoConfFactoryMap::create(map_type, _server); map->setProblem(problem); problem->setMap(map); @@ -235,18 +203,7 @@ ProblemPtr Problem::autoSetup(ParamsServer &_server) std::string tree_manager_type = _server.getParam<std::string>("problem/tree_manager/type"); WOLF_TRACE("Tree Manager Type: ", tree_manager_type); if (tree_manager_type != "None" and tree_manager_type != "none") - { - std::string tm_plugin = _server.getParam<std::string>("problem/tree_manager/plugin"); - if (tm_plugin != "core" and tm_plugin != "wolf") - { - std::string plugin = plugins_path + "libwolf" + tm_plugin + lib_extension; - WOLF_TRACE("Loading plugin " + plugin); - auto l = std::make_shared<LoaderRaw>(plugin); - l->load(); - loaders.push_back(l); - } problem->setTreeManager(AutoConfFactoryTreeManager::create(tree_manager_type, "tree manager", _server)); - } // Set problem prior -- first keyframe std::string prior_mode = _server.getParam<std::string>("problem/prior/mode"); diff --git a/src/yaml/parser_yaml.cpp b/src/yaml/parser_yaml.cpp index b4c830bd547b7b07e288cb406027deab95751db3..a813f71b2246d53d0056bb8ab26ec1f9db5ee000 100644 --- a/src/yaml/parser_yaml.cpp +++ b/src/yaml/parser_yaml.cpp @@ -517,12 +517,10 @@ void ParserYaml::parse() tags.push_back("ROS publisher"); walkTreeR(it.n_, tags, "ROS publisher/" + it.type_ + " - " + it.topic_); } - std::list<std::string> plugins; - std::list<std::string> packages_subscriber, packages_publisher; - for (const auto& it : paramsSens_) - plugins.push_back(it.plugin_); - for (const auto& it : paramsProc_) - plugins.push_back(it.plugin_); + std::list<std::string> plugins, packages_subscriber, packages_publisher; + for (auto pair : params_) + if (pair.first.find("plugin") != std::string::npos and pair.first != "plugins") + plugins.push_back(pair.second); for (const auto& it : subscriber_managers_) packages_subscriber.push_back(it.package_); for (const auto& it : publisher_managers_) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9479b901549a8777580ab7455507a4f9a83a9567..dd7732c47dbffb1e1e7e2502d0ecc78c60e9f926 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -34,6 +34,7 @@ target_link_libraries(gtest_example ${PLUGIN_NAME}) # set(SRC_DUMMY dummy/processor_tracker_feature_dummy.cpp dummy/processor_tracker_landmark_dummy.cpp + dummy/dummy_object_derived.cpp ) add_library(dummy SHARED ${SRC_DUMMY}) target_link_libraries(dummy ${PLUGIN_NAME}) @@ -64,6 +65,10 @@ target_link_libraries(gtest_factor_base ${PLUGIN_NAME}) wolf_add_gtest(gtest_factor_autodiff gtest_factor_autodiff.cpp) target_link_libraries(gtest_factor_autodiff ${PLUGIN_NAME}) +# Factory test +wolf_add_gtest(gtest_factory gtest_factory.cpp) +target_link_libraries(gtest_factory ${PLUGIN_NAME} dummy) + # FactoryStateBlock factory test wolf_add_gtest(gtest_factory_state_block gtest_factory_state_block.cpp) target_link_libraries(gtest_factory_state_block ${PLUGIN_NAME}) diff --git a/test/dummy/dummy_object.h b/test/dummy/dummy_object.h new file mode 100644 index 0000000000000000000000000000000000000000..ab865a1449ac6a8610129cd8e1f8427bf02d22ec --- /dev/null +++ b/test/dummy/dummy_object.h @@ -0,0 +1,115 @@ +//--------LICENSE_START-------- +// +// Copyright (C) 2020,2021,2022 Institut de Robòtica i Informà tica Industrial, CSIC-UPC. +// Authors: Joan Solà Ortega (jsola@iri.upc.edu) +// All rights reserved. +// +// This file is part of WOLF +// WOLF is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// +//--------LICENSE_END-------- +#ifndef WOLF_DUMMY_OBJECT_H_ +#define WOLF_DUMMY_OBJECT_H_ + +/************************** + * WOLF includes * + **************************/ +#include "core/common/wolf.h" +#include <core/utils/params_server.h> +#include "factory_dummy_object.h" + +namespace wolf { +WOLF_PTR_TYPEDEFS(DummyObject); + +/* + * Macro for defining Autoconf DummyObject creator for WOLF's high level API. + * + * Place a call to this macro inside your class declaration (in the DummyObject_class.h file), + * preferably just after the constructors. + * + * In order to use this macro, the derived DummyObject class, DummyObjectClass, + * must have a constructor available with the API: + * + * DummyObjectClass(const std::string& _unique_name, + * const ParamsServer& _server); + */ +#define WOLF_DUMMY_OBJECT_CREATE(DummyObjectClass) \ +static DummyObjectPtr create(const std::string& _unique_name, \ + const ParamsServer& _server) \ +{ \ + DummyObjectPtr sub = std::make_shared<DummyObjectClass>(_unique_name, _server); \ + return sub; \ +} \ + +class DummyObject +{ + protected: + //wolf + std::string prefix_; + std::string name_; + std::string topic_; + + public: + DummyObject(const std::string& _unique_name, + const ParamsServer& _server) : + prefix_("ROS DummyObject/" + _unique_name), + name_(_unique_name) + { + //topic_ = _server.getParam<std::string>(prefix_ + "/topic"); + } + + virtual ~DummyObject(){}; + + //std::string getTopic() const; + + std::string getName() const; + + virtual void print() const = 0; + + protected: + + template<typename T> + T getParamWithDefault(const ParamsServer &_server, + const std::string &_param_name, + const T _default_value) const; +}; + +// inline std::string DummyObject::getTopic() const +// { +// return topic_; +// } + +inline std::string DummyObject::getName() const +{ + return name_; +} + +// template<typename T> +// inline T DummyObject::getParamWithDefault(const ParamsServer &_server, +// const std::string &_param_name, +// const T _default_value) const +// { +// try +// { +// return _server.getParam<T>(_param_name); +// } +// catch (...) +// { +// WOLF_INFO("DummyObject: Parameter ", _param_name, " is missing. Taking default value: ", _default_value); +// return _default_value; +// } +// } + +} +#endif diff --git a/test/dummy/dummy_object_derived.cpp b/test/dummy/dummy_object_derived.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4bd2b708743baaa712987e0c2eb32ebc238c604d --- /dev/null +++ b/test/dummy/dummy_object_derived.cpp @@ -0,0 +1,38 @@ +//--------LICENSE_START-------- +// +// Copyright (C) 2020,2021,2022 Institut de Robòtica i Informà tica Industrial, CSIC-UPC. +// Authors: Joan Solà Ortega (jsola@iri.upc.edu) +// All rights reserved. +// +// This file is part of WOLF +// WOLF is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// +//--------LICENSE_END-------- +#include "dummy_object_derived.h" + +namespace wolf +{ + +DummyObjectDerived::DummyObjectDerived(const std::string& _unique_name, + const ParamsServer& _server) ://, + DummyObject(_unique_name, _server) +{ +} + +void DummyObjectDerived::print() const +{ + WOLF_INFO("DummyObjectDerived::print()"); +} + +} \ No newline at end of file diff --git a/test/dummy/dummy_object_derived.h b/test/dummy/dummy_object_derived.h new file mode 100644 index 0000000000000000000000000000000000000000..78bf5079fe99a57965f60dd2d6d9c5b67af09a7b --- /dev/null +++ b/test/dummy/dummy_object_derived.h @@ -0,0 +1,49 @@ +//--------LICENSE_START-------- +// +// Copyright (C) 2020,2021,2022 Institut de Robòtica i Informà tica Industrial, CSIC-UPC. +// Authors: Joan Solà Ortega (jsola@iri.upc.edu) +// All rights reserved. +// +// This file is part of WOLF +// WOLF is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// +//--------LICENSE_END-------- +#ifndef DUMMY_OBJECT_DERIVED_H_ +#define DUMMY_OBJECT_DERIVED_H_ + +/************************** + * WOLF includes * + **************************/ +#include "core/common/wolf.h" + +#include "dummy_object.h" + +namespace wolf { + +class DummyObjectDerived : public DummyObject +{ + public: + DummyObjectDerived(const std::string& _unique_name, + const ParamsServer& _server); + WOLF_DUMMY_OBJECT_CREATE(DummyObjectDerived); + + void print() const override; + + virtual ~DummyObjectDerived(){}; +}; + +WOLF_REGISTER_DUMMY_OBJECT(DummyObjectDerived) +} + +#endif \ No newline at end of file diff --git a/test/dummy/factory_dummy_object.h b/test/dummy/factory_dummy_object.h new file mode 100644 index 0000000000000000000000000000000000000000..34a215963d94f3837cf77724b0859ce99ea49c0b --- /dev/null +++ b/test/dummy/factory_dummy_object.h @@ -0,0 +1,48 @@ +//--------LICENSE_START-------- +// +// Copyright (C) 2020,2021,2022 Institut de Robòtica i Informà tica Industrial, CSIC-UPC. +// Authors: Joan Solà Ortega (jsola@iri.upc.edu) +// All rights reserved. +// +// This file is part of WOLF +// WOLF is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// +//--------LICENSE_END-------- +#ifndef FACTORY_DUMMY_OBJECT_H_ +#define FACTORY_DUMMY_OBJECT_H_ + +// wolf +#include <core/common/factory.h> +#include <core/utils/params_server.h> + +namespace wolf +{ + +class DummyObject; +typedef Factory<DummyObject, + const std::string&, + const ParamsServer&> FactoryDummyObject; +template<> +inline std::string FactoryDummyObject::getClass() const +{ + return "FactoryDummyObject"; +} + + +#define WOLF_REGISTER_DUMMY_OBJECT(DummyObjectType) \ + namespace{ const bool WOLF_UNUSED DummyObjectType##Registered = \ + wolf::FactoryDummyObject::registerCreator(#DummyObjectType, DummyObjectType::create); } \ + +} /* namespace wolf */ +#endif /* FACTORY_DUMMY_OBJECT_H_ */ diff --git a/test/gtest_factory.cpp b/test/gtest_factory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f46ee75069a4611a1fdb45be399c852b527517b0 --- /dev/null +++ b/test/gtest_factory.cpp @@ -0,0 +1,53 @@ +//--------LICENSE_START-------- +// +// Copyright (C) 2020,2021,2022 Institut de Robòtica i Informà tica Industrial, CSIC-UPC. +// Authors: Joan Solà Ortega (jsola@iri.upc.edu) +// All rights reserved. +// +// This file is part of WOLF +// WOLF is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// +//--------LICENSE_END-------- +#include "core/utils/utils_gtest.h" +#include "dummy/factory_dummy_object.h" +#include "dummy/dummy_object.h" +#include "dummy/dummy_object_derived.h" +#include "core/yaml/parser_yaml.h" +#include "core/utils/params_server.h" + +using namespace wolf; + +std::string wolf_root = _WOLF_ROOT_DIR; + +TEST(TestFactory, DummyObjectFactory) +{ + ParserYaml parser = ParserYaml("test/yaml/params_basic.yaml", wolf_root); + ParamsServer server = ParamsServer(parser.getParams()); + + auto object = FactoryDummyObject::create("DummyObjectDerived","ACoolDummyObject", server); + + object->getName(); + object->print(); + + // FORCE LOADING + DummyObjectDerived obj_derived = DummyObjectDerived("AnotherCoolDummyObject", server); +} + +int main(int argc, char **argv) +{ + testing::InitGoogleTest(&argc, argv); + //::testing::GTEST_FLAG(filter) = "TestTest.DummyTestExample"; // Test only this one + //::testing::GTEST_FLAG(filter) = "TestTest.*"; // Test only the tests in this group + return RUN_ALL_TESTS(); +}