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 loadSmoothingParams(const std::string& filePath)
14 {
15 SmoothingParams params;
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 == "weightBoundary")
37 {
38 params.w_boundary = std::stof(value);
39 }
40 else if (key == "weightPoseSmooth")
41 {
42 params.w_pose_smooth = std::stof(value);
43 }
44 else if (key == "weightPoseSmoothOrientation")
45 {
46 params.w_pose_smooth_ori = std::stof(value);
47 }
48 else if (key == "weightVelocitySmooth")
49 {
50 params.w_vel_smooth = std::stof(value);
51 }
52 else if (key == "weightPoseJerk")
53 {
54 params.w_pose_jerk = std::stof(value);
55 }
56 else if (key == "weightRobotSmooth")
57 {
58 params.w_robot_smooth = std::stof(value);
59 }
60 else if (key == "weightObstacle")
61 {
62 params.w_obs = std::stof(value);
63 }
64 else if (key == "weightTracking")
65 {
66 params.w_track = std::stof(value);
67 }
68 else if (key == "weightVelocityLimit")
69 {
70 params.w_vel_limit = std::stof(value);
71 }
72 else if (key == "weightSpacing")
73 {
74 params.w_spacing = std::stof(value);
75 }
76 else if (key == "clearance")
77 {
78 params.clearance = std::stof(value);
79 }
80 else if (key == "obsCollisionResidual")
81 {
82 params.obsCollisionResidual = std::stof(value);
83 }
84 else if (key == "obsMaxDistance")
85 {
86 params.obsMaxDistance = std::stof(value);
87 }
88 else if (key == "vmax")
89 {
90 params.vmax = std::stof(value);
91 }
92 else if (key == "useTracking")
93 {
94 params.use_tracking = (value == "true");
95 }
96 else if (key == "useRobotSmooth")
97 {
98 params.use_robot_smooth = (value == "true");
99 }
100 else if (key == "useJerk")
101 {
102 params.use_jerk = (value == "true");
103 }
104 else if (key == "useObstacle")
105 {
106 params.use_obs = (value == "true");
107 }
108 else if (key == "maxIterations")
109 {
110 params.max_iterations = std::stoi(value);
111 }
112 else if (key == "numThreads")
113 {
114 params.num_threads = std::stoi(value);
115 }
116 }
117 catch (const std::invalid_argument&)
118 {
119 throw std::runtime_error("Invalid value for key " + key + ": " + value);
120 }
121 }
122 }
123 }
124
125 return params;
126 }
127
128} // namespace armarx::navigation::algorithms::orientation_aware::smoothing::io
static std::filesystem::path toSystemPath(const data::PackagePath &pp)
SmoothingParams loadSmoothingParams(const std::string &filePath)
Definition io.cpp:13