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{
13 {
14 double w_boundary = 10.0;
15 double w_pose_smooth = 10.0;
16 double w_pose_smooth_ori = 100.0;
17 double w_vel_smooth = 0.0;
18 double w_pose_jerk = 0.0;
19 double w_robot_smooth = 0.0;
20 double w_obs = 2000.0;
21 double w_track = 0.05;
22 double w_vel_limit = 0.0;
23 double w_spacing = 1.0;
24 double clearance = 50.0;
25 double obsCollisionResidual = 1000.0;
26 double obsMaxDistance = 500.0;
27 double vmax = 1.0;
28 bool use_tracking = true;
29 bool use_robot_smooth = true;
30 bool use_jerk = false;
31 bool use_obs = true;
33 int num_threads = 4;
34 };
35
37 loadSmoothingParams(const std::string& filePath = "algorithms/orientation-aware-smoothing.cfg")
38 {
39 // We expect the file to have a line for each config parameter, in the format "key=value"
40 SmoothingParams params;
41
42 // Create full file path with ArmarX PackagePath
43 const auto fullFilePath = armarx::PackagePath("armarx_navigation", filePath).toSystemPath();
44 std::ifstream file(fullFilePath);
45 if (!file.is_open())
46 {
47 throw std::runtime_error("Could not open config file: " + fullFilePath.string());
48 }
49 std::string line;
50 while (std::getline(file, line))
51 {
52 std::istringstream iss(line);
53 std::string key;
54 if (std::getline(iss, key, '='))
55 {
56 std::string value;
57 if (std::getline(iss, value))
58 {
59 try
60 {
61 // add all keys
62 if (key == "weightBoundary")
63 {
64 params.w_boundary = std::stof(value);
65 }
66 else if (key == "weightPoseSmooth")
67 {
68 params.w_pose_smooth = std::stof(value);
69 }
70 else if (key == "weightPoseSmoothOrientation")
71 {
72 params.w_pose_smooth_ori = std::stof(value);
73 }
74 else if (key == "weightVelocitySmooth")
75 {
76 params.w_vel_smooth = std::stof(value);
77 }
78 else if (key == "weightPoseJerk")
79 {
80 params.w_pose_jerk = std::stof(value);
81 }
82 else if (key == "weightRobotSmooth")
83 {
84 params.w_robot_smooth = std::stof(value);
85 }
86 else if (key == "weightObstacle")
87 {
88 params.w_obs = std::stof(value);
89 }
90 else if (key == "weightTracking")
91 {
92 params.w_track = std::stof(value);
93 }
94 else if (key == "weightVelocityLimit")
95 {
96 params.w_vel_limit = std::stof(value);
97 }
98 else if (key == "weightSpacing")
99 {
100 params.w_spacing = std::stof(value);
101 }
102 else if (key == "clearance")
103 {
104 params.clearance = std::stof(value);
105 }
106 else if (key == "obsCollisionResidual")
107 {
108 params.obsCollisionResidual = std::stof(value);
109 }
110 else if (key == "obsMaxDistance")
111 {
112 params.obsMaxDistance = std::stof(value);
113 }
114 else if (key == "vmax")
115 {
116 params.vmax = std::stof(value);
117 }
118 else if (key == "useTracking")
119 {
120 params.use_tracking = (value == "true");
121 }
122 else if (key == "useRobotSmooth")
123 {
124 params.use_robot_smooth = (value == "true");
125 }
126 else if (key == "useJerk")
127 {
128 params.use_jerk = (value == "true");
129 }
130 else if (key == "useObstacle")
131 {
132 params.use_obs = (value == "true");
133 }
134 else if (key == "maxIterations")
135 {
136 params.max_iterations = std::stoi(value);
137 }
138 else if (key == "numThreads")
139 {
140 params.num_threads = std::stoi(value);
141 }
142 }
143 catch (const std::invalid_argument& e)
144 {
145 throw std::runtime_error("Invalid value for key " + key + ": " + value);
146 }
147 }
148 }
149 }
150
151 return params;
152 }
153
154} // namespace armarx::navigation::algorithms::orientation_aware::smoothing::io
static std::filesystem::path toSystemPath(const data::PackagePath &pp)
SmoothingParams loadSmoothingParams(const std::string &filePath="algorithms/orientation-aware-smoothing.cfg")
Definition io.h:37