io.h
Go to the documentation of this file.
1#pragma once
2
3#include <fstream>
4#include <sstream>
5#include <stdexcept>
6#include <string>
7
9
11{
22
25 const std::string& filePath = "algorithms/astarwithorientation.cfg")
26 {
27 // We expect the file to have a line for each config parameter, in the format "key=value"
29
30 // Create full file path with ArmarX PackagePath
31 const auto fullFilePath = armarx::PackagePath("armarx_navigation", filePath).toSystemPath();
32 std::ifstream file(fullFilePath);
33 if (!file.is_open())
34 {
35 throw std::runtime_error("Could not open config file: " + fullFilePath.string());
36 }
37 std::string line;
38 while (std::getline(file, line))
39 {
40 std::istringstream iss(line);
41 std::string key;
42 if (std::getline(iss, key, '='))
43 {
44 std::string value;
45 if (std::getline(iss, value))
46 {
47 try
48 {
49 if (key == "maxObstacleDistance")
50 {
51 params.maxObstacleDistance = std::stof(value);
52 }
53 else if (key == "obstacleDistanceWeightFactor")
54 {
55 params.obstacleDistanceWeightFactor = std::stof(value);
56 }
57 else if (key == "obstacleDistanceContinuousWeightFactor")
58 {
59 params.obstacleDistanceContinuousWeightFactor = std::stof(value);
60 }
61 else if (key == "orientationWeightFactor")
62 {
63 params.orientationWeightFactor = std::stof(value);
64 }
65 else if (key == "forwardWeightFactor")
66 {
67 params.forwardWeightFactor = std::stof(value);
68 }
69 else if (key == "smoothnessWeightFactor")
70 {
71 params.smoothnessWeightFactor = std::stof(value);
72 }
73 }
74 catch (const std::invalid_argument& e)
75 {
76 throw std::runtime_error("Invalid value for key " + key + ": " + value);
77 }
78 }
79 }
80 }
81
82 return params;
83 }
84
85} // namespace armarx::navigation::algorithms::orientation_aware::io
static std::filesystem::path toSystemPath(const data::PackagePath &pp)
AStarWithOrientationParams loadAStarWithOrientationParams(const std::string &filePath="algorithms/astarwithorientation.cfg")
Definition io.h:24