Coverage Control Library
Loading...
Searching...
No Matches
parameters.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the CoverageControl library
3 *
4 * Author: Saurav Agarwal
5 * Contact: sauravag@seas.upenn.edu, agr.saurav1@gmail.com
6 * Repository: https://github.com/KumarRobotics/CoverageControl
7 *
8 * Copyright (c) 2024, Saurav Agarwal
9 *
10 * The CoverageControl library is free software: you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or (at your
13 * option) any later version.
14 *
15 * The CoverageControl library is distributed in the hope that it will be
16 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
18 * Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along with
21 * CoverageControl library. If not, see <https://www.gnu.org/licenses/>.
22 */
23
29#include <filesystem>
30#include <iostream>
31
32#include "CoverageControl/extern/tomlplusplus/toml.hpp"
34
35namespace CoverageControl {
36void Parameters::ParseParameters() {
37 std::cout << std::boolalpha;
38 std::cout << "Using config file: " << config_file_ << std::endl;
39 if (not std::filesystem::exists(config_file_)) {
40 std::cerr << "Could not find config file " << config_file_ << std::endl;
41 throw std::runtime_error("Could not open config file");
42 }
43
44 toml::table toml_config;
45 try {
46 toml_config = toml::parse_file(config_file_);
47 } catch (const std::exception& e) {
48 std::cerr << "Error parsing config file: " << e.what() << std::endl;
49 std::cerr << "Please check the config file format" << std::endl;
50 std::cerr << "File: " << config_file_ << std::endl;
51 throw std::runtime_error("Error parsing config file");
52 }
53
54 if (toml_config["NumRobots"].value<int>()) {
55 if (toml_config["NumRobots"].value<int>().value() < 1) {
56 std::cerr << "NumRobots must be greater than 0" << std::endl;
57 throw std::runtime_error("NumRobots must be greater than 0");
58 }
59 pNumRobots = toml_config["NumRobots"].value<int>().value();
60 } else {
61 std::cout << "NumRobots (default): " << pNumRobots << std::endl;
62 }
63
64 auto toml_IO = toml_config["IO"];
65 if (toml_IO["PlotScale"].value<double>()) {
66 pPlotScale = toml_IO["PlotScale"].value<double>().value();
67 } else {
68 std::cout << "PlotScale (default): " << pPlotScale << std::endl;
69 }
70
71 auto toml_EnvironmentMaps = toml_config["Environment"]["Maps"];
72
73 if (toml_EnvironmentMaps) {
74 auto toml_Resolution = toml_EnvironmentMaps["Resolution"].value<double>();
75 auto toml_WorldMapSize = toml_EnvironmentMaps["WorldMapSize"].value<int>();
76 auto toml_RobotMapSize = toml_EnvironmentMaps["RobotMapSize"].value<int>();
77 auto toml_LocalMapSize = toml_EnvironmentMaps["LocalMapSize"].value<int>();
78
79 if (toml_Resolution) {
80 pResolution = toml_Resolution.value();
81 }
82
83 if (toml_WorldMapSize) {
84 pWorldMapSize = toml_WorldMapSize.value();
85 }
86 if (toml_RobotMapSize) {
87 pRobotMapSize = toml_RobotMapSize.value();
88 }
89 if (toml_LocalMapSize) {
90 pLocalMapSize = toml_LocalMapSize.value();
91 }
92
93 auto toml_EnvironmentMapsUpdateSettings =
94 toml_EnvironmentMaps["UpdateSettings"];
95
96 if (toml_EnvironmentMapsUpdateSettings) {
97 auto toml_UpdateRobotMap =
98 toml_EnvironmentMapsUpdateSettings["UpdateRobotMap"].value<bool>();
99 auto toml_UpdateSensorView =
100 toml_EnvironmentMapsUpdateSettings["UpdateSensorView"].value<bool>();
101 auto toml_UpdateExplorationMap =
102 toml_EnvironmentMapsUpdateSettings["UpdateExplorationMap"]
103 .value<bool>();
104 auto toml_UpdateSystemMap =
105 toml_EnvironmentMapsUpdateSettings["UpdateSystemMap"].value<bool>();
106
107 if (toml_UpdateRobotMap) {
108 pUpdateRobotMap = toml_UpdateRobotMap.value();
109 }
110 if (toml_UpdateSensorView) {
111 pUpdateSensorView = toml_UpdateSensorView.value();
112 }
113 if (toml_UpdateExplorationMap) {
114 pUpdateExplorationMap = toml_UpdateExplorationMap.value();
115 }
116 if (toml_UpdateSystemMap) {
117 pUpdateSystemMap = toml_UpdateSystemMap.value();
118 }
119 }
120 }
121
122 auto toml_EnvironmentIDF = toml_config["Environment"]["IDF"];
123
124 if (toml_EnvironmentIDF) {
125 if (toml_EnvironmentIDF["NumGaussianFeatures"].value<int>()) {
126 pNumGaussianFeatures = toml_EnvironmentIDF["NumGaussianFeatures"].value<int>().value();
127 } else {
128 std::cout << "NumGaussianFeatures (default): " << pNumGaussianFeatures << std::endl;
129 }
130 auto toml_TruncationBND =
131 toml_EnvironmentIDF["TruncationBND"].value<double>();
132 auto toml_Norm = toml_EnvironmentIDF["Norm"].value<double>();
133 auto toml_MinSigma = toml_EnvironmentIDF["MinSigma"].value<double>();
134 auto toml_MaxSigma = toml_EnvironmentIDF["MaxSigma"].value<double>();
135 auto toml_MinPeak = toml_EnvironmentIDF["MinPeak"].value<double>();
136 auto toml_MaxPeak = toml_EnvironmentIDF["MaxPeak"].value<double>();
137 auto toml_UnknownImportance =
138 toml_EnvironmentIDF["UnknownImportance"].value<double>();
139 auto toml_RobotMapUseUnknownImportance =
140 toml_EnvironmentIDF["RobotMapUseUnknownImportance"].value<bool>();
141
142 if (toml_TruncationBND) {
143 pTruncationBND = toml_TruncationBND.value();
144 }
145 if (toml_Norm) {
146 pNorm = toml_Norm.value();
147 }
148 if (toml_MinSigma) {
149 pMinSigma = toml_MinSigma.value();
150 }
151 if (toml_MaxSigma) {
152 pMaxSigma = toml_MaxSigma.value();
153 }
154 if (toml_MinPeak) {
155 pMinPeak = toml_MinPeak.value();
156 }
157 if (toml_MaxPeak) {
158 pMaxPeak = toml_MaxPeak.value();
159 }
160
161 if (toml_EnvironmentIDF["NumPolygons"].value<int>()) {
162 pNumPolygons = toml_EnvironmentIDF["NumPolygons"].value<int>().value();
163 } else {
164 std::cout << "NumPolygons (default): " << pNumPolygons << std::endl;
165 }
166
167 if (toml_EnvironmentIDF["MaxVertices"].value<int>()) {
168 pMaxVertices = toml_EnvironmentIDF["MaxVertices"].value<int>().value();
169 } else {
170 std::cout << "MaxVertices (default): " << pMaxVertices << std::endl;
171 }
172
173 if (toml_EnvironmentIDF["PolygonRadius"].value<double>()) {
174 pPolygonRadius = toml_EnvironmentIDF["PolygonRadius"].value<double>().value();
175 } else {
176 std::cout << "PolygonRadius (default): " << pPolygonRadius << std::endl;
177 }
178
179 if (toml_UnknownImportance) {
180 pUnknownImportance = toml_UnknownImportance.value();
181 }
182 if (toml_RobotMapUseUnknownImportance) {
183 pRobotMapUseUnknownImportance = toml_RobotMapUseUnknownImportance.value();
184 }
185 }
186
187 auto toml_RobotModel = toml_config["RobotModel"];
188
189 if (toml_RobotModel) {
190 auto toml_SensorSize = toml_RobotModel["SensorSize"].value<int>();
191 auto toml_CommunicationRange =
192 toml_RobotModel["CommunicationRange"].value<double>();
193 auto toml_MaxRobotSpeed = toml_RobotModel["MaxRobotSpeed"].value<double>();
194 auto toml_RobotInitDist = toml_RobotModel["RobotInitDist"].value<double>();
195 auto toml_RobotPosHistorySize =
196 toml_RobotModel["RobotPosHistorySize"].value<int>();
197 auto toml_TimeStep = toml_RobotModel["TimeStep"].value<double>();
198
199 if (toml_SensorSize) {
200 pSensorSize = toml_SensorSize.value();
201 }
202 if (toml_CommunicationRange) {
203 pCommunicationRange = toml_CommunicationRange.value();
204 }
205 if (toml_MaxRobotSpeed) {
206 pMaxRobotSpeed = toml_MaxRobotSpeed.value();
207 }
208 if (toml_RobotInitDist) {
209 pRobotInitDist = toml_RobotInitDist.value();
210 }
211 if (toml_RobotPosHistorySize) {
212 pRobotPosHistorySize = toml_RobotPosHistorySize.value();
213 }
214 if (toml_TimeStep) {
215 pTimeStep = toml_TimeStep.value();
216 }
217 }
218
219 if (toml_RobotModel["AddNoise"]) {
220 auto toml_AddNoisePositions =
221 toml_RobotModel["AddNoise"]["AddNoisePositions"].value<bool>();
222 auto toml_PositionsNoiseSigma =
223 toml_RobotModel["AddNoise"]["PositionsNoiseSigma"].value<double>();
224 if (toml_AddNoisePositions) {
225 pAddNoisePositions = toml_AddNoisePositions.value();
226 }
227 if (toml_PositionsNoiseSigma) {
228 pPositionsNoiseSigma = toml_PositionsNoiseSigma.value();
229 }
230 }
231
232 auto toml_Algorithm = toml_config["Algorithm"];
233
234 if (toml_Algorithm) {
235 auto toml_EpisodeSteps = toml_Algorithm["EpisodeSteps"].value<int>();
236 if (toml_EpisodeSteps) {
237 pEpisodeSteps = toml_EpisodeSteps.value();
238 }
239 if (toml_Algorithm["CheckOscillations"].value<bool>()) {
241 toml_Algorithm["CheckOscillations"].value<bool>().value();
242 }
243
244 auto toml_LloydMaxIterations =
245 toml_Algorithm["Global-CVT"]["LloydMaxIterations"].value<int>();
246 auto toml_LloydNumTries =
247 toml_Algorithm["Global-CVT"]["LloydNumTries"].value<int>();
248 if (toml_LloydMaxIterations) {
249 pLloydMaxIterations = toml_LloydMaxIterations.value();
250 }
251 if (toml_LloydNumTries) {
252 pLloydNumTries = toml_LloydNumTries.value();
253 }
254
255 auto toml_NumFrontiers =
256 toml_Algorithm["Exploration"]["NumFrontiers"].value<int>();
257 if (toml_NumFrontiers) {
258 pNumFrontiers = toml_NumFrontiers.value();
259 }
260 }
261}
262
264 std::cout << "NumRobots: " << pNumRobots << std::endl;
265 std::cout << "NumPolygons: " << pNumPolygons << std::endl;
266 std::cout << "MaxVertices: " << pMaxVertices << std::endl;
267 std::cout << "PolygonRadius: " << pPolygonRadius << std::endl;
268
269 std::cout << "PlotScale: " << pPlotScale << std::endl;
270
271 std::cout << "Resolution: " << pResolution << std::endl;
272 std::cout << "WorldMapSize: " << pWorldMapSize << std::endl;
273 std::cout << "RobotMapSize: " << pRobotMapSize << std::endl;
274 std::cout << "LocalMapSize: " << pLocalMapSize << std::endl;
275
276 std::cout << "UpdateRobotMap: " << pUpdateRobotMap << std::endl;
277 std::cout << "UpdateSensorView: " << pUpdateSensorView << std::endl;
278 std::cout << "UpdateExplorationMap: " << pUpdateExplorationMap << std::endl;
279 std::cout << "UpdateSystemMap: " << pUpdateSystemMap << std::endl;
280
281 std::cout << "NumGaussianFeatures: " << pNumGaussianFeatures << std::endl;
282 std::cout << "TruncationBND: " << pTruncationBND << std::endl;
283 std::cout << "Norm: " << pNorm << std::endl;
284 std::cout << "MinSigma: " << pMinSigma << std::endl;
285 std::cout << "MaxSigma: " << pMaxSigma << std::endl;
286 std::cout << "MinPeak: " << pMinPeak << std::endl;
287 std::cout << "MaxPeak: " << pMaxPeak << std::endl;
288
289 std::cout << "pNumPolygons: " << pNumPolygons << std::endl;
290 std::cout << "pMaxVertices: " << pMaxVertices << std::endl;
291 std::cout << "pPolygonRadius: " << pPolygonRadius << std::endl;
292
293 std::cout << "UnknownImportance: " << pUnknownImportance << std::endl;
294 std::cout << "RobotMapUseUnknownImportance: " << pRobotMapUseUnknownImportance
295 << std::endl;
296
297 std::cout << "SensorSize: " << pSensorSize << std::endl;
298 std::cout << "CommunicationRange: " << pCommunicationRange << std::endl;
299 std::cout << "MaxRobotSpeed: " << pMaxRobotSpeed << std::endl;
300 std::cout << "RobotInitDist: " << pRobotInitDist << std::endl;
301 std::cout << "RobotPosHistorySize: " << pRobotPosHistorySize << std::endl;
302 std::cout << "TimeStep: " << pTimeStep << std::endl;
303
304 std::cout << "AddNoisePositions: " << pAddNoisePositions << std::endl;
305 std::cout << "PositionsNoiseSigma: " << pPositionsNoiseSigma << std::endl;
306
307 std::cout << "EpisodeSteps: " << pEpisodeSteps << std::endl;
308 std::cout << "CheckOscillations: " << pCheckOscillations << std::endl;
309 std::cout << "LloydMaxIterations: " << pLloydMaxIterations << std::endl;
310 std::cout << "LloydNumTries: " << pLloydNumTries << std::endl;
311 std::cout << "NumFrontiers: " << pNumFrontiers << std::endl;
312}
313} /* namespace CoverageControl */
int pRobotMapSize
Robot map saves what the robot has seen.
Definition parameters.h:79
double pTimeStep
Each time step corresponds to pTimeStep seconds.
Definition parameters.h:140
int pNumPolygons
Number of polygonal features.
Definition parameters.h:114
int pNumRobots
Number of robots.
Definition parameters.h:56
int pNumGaussianFeatures
Bivariate Normal Distribution truncated after pTruncationBND * sigma.
Definition parameters.h:102
int pMaxVertices
Maximum number of vertices in a polygon.
Definition parameters.h:115
int pRobotPosHistorySize
Number of previous positions to store.
Definition parameters.h:139
double pCommunicationRange
Radius of communication (in meters)
Definition parameters.h:134
Namespace for the CoverageControl library.
Contains parameters.