Skip to content
Snippets Groups Projects
Commit eb565d37 authored by Joan Vallvé Navarro's avatar Joan Vallvé Navarro
Browse files

solver autoconf accepts yaml with one level up params

parent 9f47c453
No related branches found
No related tags found
1 merge request!448Draft: Resolve "Implementation of new nodes creation"
Pipeline #21352 failed
...@@ -18,11 +18,13 @@ ...@@ -18,11 +18,13 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
// wolf core includes // wolf core includes
#include "core/common/wolf.h"
#include "core/ceres_wrapper/solver_ceres.h" #include "core/ceres_wrapper/solver_ceres.h"
#include "core/solver/factory_solver.h" #include "core/solver/factory_solver.h"
#include "core/common/wolf.h"
#include "core/capture/capture_odom_2d.h" #include "core/capture/capture_odom_2d.h"
#include "core/processor/processor_motion.h" #include "core/processor/processor_motion.h"
// hello wolf local includes
#include "capture_range_bearing.h" #include "capture_range_bearing.h"
int main() int main()
...@@ -110,22 +112,14 @@ int main() ...@@ -110,22 +112,14 @@ int main()
std::string config_file = "demos/hello_wolf/yaml/hello_wolf_config.yaml"; std::string config_file = "demos/hello_wolf/yaml/hello_wolf_config.yaml";
std::string wolf_path = _WOLF_CODE_DIR; std::string wolf_path = _WOLF_CODE_DIR;
// parse file into params node // Wolf problem: Build the Hardware branch of the wolf tree from the config yaml file
yaml_schema_cpp::YamlServer server({wolf_path}, wolf_path + "/" + config_file); ProblemPtr problem = Problem::autoSetup(wolf_path + "/" + config_file, {wolf_path});
// Wolf problem: automatically build the left branch of the wolf tree from the contents of the yaml node
ProblemPtr problem = Problem::autoSetup(server.getNode(), {wolf_path});
// Print problem to see its status before processing any sensor data // Print problem to see its status before processing any sensor data
problem->print(4, 0, 1, 0); problem->print(4, 0, 1, 0);
// Solver. Configure a Ceres solver // Wolf problem: Create a Solver Ceres from the config yaml file
SolverManagerPtr ceres = SolverManager::autoSetup(problem, server.getNode()["solver"], {wolf_path}); SolverManagerPtr ceres = SolverManager::autoSetup(problem, wolf_path + "/" + config_file, {wolf_path});
if (not ceres)
{
WOLF_ERROR("Couldn't load or validate the yaml file for the solver");
return 1;
}
// recover sensor pointers and other stuff for later use (access by sensor name) // recover sensor pointers and other stuff for later use (access by sensor name)
SensorBasePtr sensor_odo = problem->findSensor("sen odom"); SensorBasePtr sensor_odo = problem->findSensor("sen odom");
......
...@@ -72,6 +72,13 @@ SolverManagerPtr SolverManager::autoSetup(const ProblemPtr& _problem, ...@@ -72,6 +72,13 @@ SolverManagerPtr SolverManager::autoSetup(const ProblemPtr& _problem,
std::vector<std::string> _schema_folders, std::vector<std::string> _schema_folders,
bool _skip_yaml_validation) bool _skip_yaml_validation)
{ {
// recursive call if _param_node is one level up
if (_param_node["solver"])
{
WOLF_DEBUG("YAML node has 'solver' key, calling autoSetup recursively...");
return SolverManager::autoSetup(_problem, _param_node["solver"], _schema_folders, _skip_yaml_validation);
}
// VALIDATION =============================================================================== // VALIDATION ===============================================================================
if (not _skip_yaml_validation) if (not _skip_yaml_validation)
{ {
......
...@@ -130,6 +130,25 @@ TEST(SolverManagerFactories, autoSetupNode) ...@@ -130,6 +130,25 @@ TEST(SolverManagerFactories, autoSetupNode)
EXPECT_TRUE(solver_ptr->check()); EXPECT_TRUE(solver_ptr->check());
} }
TEST(SolverManagerFactories, autoSetupNodeUpperLevel)
{
auto problem = Problem::create(3);
YAML::Node params;
params["solver"]["type"] = "SolverDummy";
params["solver"]["plugin"] = "core";
params["solver"]["period"] = 0;
params["solver"]["verbose"] = 0;
params["solver"]["compute_cov"] = false;
auto solver_ptr = SolverManager::autoSetup(problem, params, {wolf_dir});
// check pointers
EXPECT_EQ(problem, solver_ptr->getProblem());
// run solver check
EXPECT_TRUE(solver_ptr->check());
}
TEST(SolverManagerFactories, autoSetupFile) TEST(SolverManagerFactories, autoSetupFile)
{ {
auto problem = Problem::create(3); auto problem = Problem::create(3);
...@@ -142,6 +161,18 @@ TEST(SolverManagerFactories, autoSetupFile) ...@@ -142,6 +161,18 @@ TEST(SolverManagerFactories, autoSetupFile)
EXPECT_TRUE(solver_ptr->check()); EXPECT_TRUE(solver_ptr->check());
} }
TEST(SolverManagerFactories, autoSetupFileUpperLevel)
{
auto problem = Problem::create(3);
auto solver_ptr = SolverManager::autoSetup(problem, wolf_dir + "/test/yaml/solver_dummy_upper.yaml", {wolf_dir});
// check pointers
EXPECT_EQ(problem, solver_ptr->getProblem());
// run solver check
EXPECT_TRUE(solver_ptr->check());
}
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
// FLOATING STATE BLOCKS // FLOATING STATE BLOCKS
TEST_F(SolverManagerTest, FloatingStateBlock_Add) TEST_F(SolverManagerTest, FloatingStateBlock_Add)
......
solver:
type: SolverDummy
plugin: core
period: 1
verbose: 2
compute_cov: false
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment