io.cpp
Go to the documentation of this file.
1#include "io.h"
2
3#include <fstream>
4#include <sstream>
5#include <stdexcept>
6
8
10{
11
13 loadAStarWithOrientationParams(const std::string& filePath)
14 {
16
17 const auto fullFilePath = armarx::PackagePath("armarx_navigation", filePath).toSystemPath();
18 std::ifstream file(fullFilePath);
19 if (!file.is_open())
20 {
21 throw std::runtime_error("Could not open config file: " + fullFilePath.string());
22 }
23
24 std::string line;
25 while (std::getline(file, line))
26 {
27 std::istringstream iss(line);
28 std::string key;
29 if (std::getline(iss, key, '='))
30 {
31 std::string value;
32 if (std::getline(iss, value))
33 {
34 try
35 {
36 if (key == "maxObstacleDistance")
37 {
38 params.maxObstacleDistance = std::stof(value);
39 }
40 else if (key == "obstacleDistanceWeightFactor")
41 {
42 params.obstacleDistanceWeightFactor = std::stof(value);
43 }
44 else if (key == "obstacleDistanceContinuousWeightFactor")
45 {
46 params.obstacleDistanceContinuousWeightFactor = std::stof(value);
47 }
48 else if (key == "orientationWeightFactor")
49 {
50 params.orientationWeightFactor = std::stof(value);
51 }
52 else if (key == "forwardWeightFactor")
53 {
54 params.forwardWeightFactor = std::stof(value);
55 }
56 else if (key == "smoothnessWeightFactor")
57 {
58 params.smoothnessWeightFactor = std::stof(value);
59 }
60 }
61 catch (const std::invalid_argument&)
62 {
63 throw std::runtime_error("Invalid value for key " + key + ": " + value);
64 }
65 }
66 }
67 }
68
69 return params;
70 }
71
72} // namespace armarx::navigation::algorithms::orientation_aware::io
static std::filesystem::path toSystemPath(const data::PackagePath &pp)
AStarWithOrientationParams loadAStarWithOrientationParams(const std::string &filePath)
Definition io.cpp:13