diff --git a/include/core/problem/problem.h b/include/core/problem/problem.h index 45aef3cff473969bbb6df23fadbe64b43a486ded..a751022705f891fdaf1d8bbdb3419732c6e0019d 100644 --- a/include/core/problem/problem.h +++ b/include/core/problem/problem.h @@ -168,6 +168,21 @@ class Problem : public std::enable_shared_from_this<Problem> const std::string& _corresponding_sensor_name, const std::string& _params_yaml_filename, const std::vector<std::string>& _folders_schema); + + /** \brief Factory method to install (create, and add to sensor) processors only from its properties + * + * This method creates a Processor, and adds it to the specified sensor's list of processors + * + * This method is a helper wrapper around the version accepting a sensor pointer instead of a sensor name. + * \param _prc_type type of processor + * \param _corresponding_sensor corresponding sensor pointer, used to bind the processor to the particular instance of the sensor + * \param _params_yaml_filename name of formatted yaml file defining the processor parameters. + * \param _folders_schema a vector of paths where the schema files (to validate the YAML file) are placed + */ + ProcessorBasePtr installProcessor(const std::string& _prc_type, + SensorBasePtr& _corresponding_sensor, + const std::string& _params_yaml_filename, + const std::vector<std::string>& _folders_schema); /** \brief get a sensor pointer by its name * \param _sensor_name The sensor name, as it was installed with installSensor() diff --git a/src/problem/problem.cpp b/src/problem/problem.cpp index 14337d60b8b9b463cd806f871ccbec639094607d..7feb7c5c32483e1740bef2e3a078bc8fd1a09155 100644 --- a/src/problem/problem.cpp +++ b/src/problem/problem.cpp @@ -313,6 +313,17 @@ ProcessorBasePtr Problem::installProcessor(const std::string& _prc_type, SensorBasePtr sen_ptr = findSensor(_corresponding_sensor_name); if (sen_ptr == nullptr) throw std::runtime_error("Cannot bind processor. Reason: Sensor \"" + _corresponding_sensor_name + "\" not found. Check sensor name, it must match in sensor and processor!"); + + return installProcessor(_prc_type, sen_ptr, _params_yaml_filename, _folders_schema); +} + +ProcessorBasePtr Problem::installProcessor(const std::string& _prc_type, + SensorBasePtr& _corresponding_sensor, + const std::string& _params_yaml_filename, + const std::vector<std::string>& _folders_schema) +{ + if (_corresponding_sensor == nullptr) + throw std::runtime_error("Cannot install processor: Null sensor pointer"); if (not file_exists(_params_yaml_filename)) throw std::runtime_error("Cannot install processor: parameters' YAML file does not exist: " + _params_yaml_filename); @@ -331,8 +342,8 @@ ProcessorBasePtr Problem::installProcessor(const std::string& _prc_type, } // add processor - prc_ptr->configure(sen_ptr); - prc_ptr->link(sen_ptr); + prc_ptr->configure(_corresponding_sensor); + prc_ptr->link(_corresponding_sensor); } return prc_ptr; } diff --git a/test/gtest_problem.cpp b/test/gtest_problem.cpp index a70aa857d186b66859f34c9b76b7ed6707d81d9f..b7e7f0cbb44d7cc2c38df60f8de42bca03ac17fb 100644 --- a/test/gtest_problem.cpp +++ b/test/gtest_problem.cpp @@ -116,7 +116,7 @@ TEST(Problem, Installers) // install processor tracker (dummy installation under an Odometry sensor -- it's OK for this test) auto pt = P->installProcessor("ProcessorTrackerFeatureDummy", - S->getName(), + S, wolf_root + "/test/yaml/processor_tracker_feature_dummy.yaml", {wolf_root}); @@ -125,7 +125,7 @@ TEST(Problem, Installers) // install processor motion ProcessorBasePtr pm = P->installProcessor("ProcessorOdom3d", - S->getName(), + S, wolf_root + "/test/yaml/processor_odom_3d.yaml", {wolf_root}); @@ -325,11 +325,11 @@ TEST(Problem, StateBlocks) ASSERT_EQ(P->getStateBlockNotificationMapSize(), (SizeStd) 2); auto pt = P->installProcessor("ProcessorTrackerFeatureDummy", - Sm->getName(), + Sm, wolf_root + "/test/yaml/processor_tracker_feature_dummy.yaml", {wolf_root}); auto pm = P->installProcessor("ProcessorOdom3d", - Sm->getName(), + Sm, wolf_root + "/test/yaml/processor_odom_3d.yaml", {wolf_root}); @@ -394,11 +394,11 @@ TEST(Problem, Covariances) auto pt = P->installProcessor("ProcessorTrackerFeatureDummy", - Sm->getName(), + Sm, wolf_root + "/test/yaml/processor_tracker_feature_dummy.yaml", {wolf_root}); auto pm = P->installProcessor("ProcessorOdom3d", - St->getName(), + St, wolf_root + "/test/yaml/processor_odom_3d.yaml", {wolf_root});