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 "CoverageControl/extern/tomlplusplus/toml.hpp"
31
32namespace CoverageControl {
33void Parameters::ParseParameters() {
34 std::cout << std::boolalpha;
35 std::cout << "Using config file: " << config_file_ << std::endl;
36 if (not std::filesystem::exists(config_file_)) {
37 std::cerr << "Could not find config file " << config_file_ << std::endl;
38 throw std::runtime_error("Could not open config file");
39 }
40
41 toml::table toml_config;
42 try {
43 toml_config = toml::parse_file(config_file_);
44 } catch (const std::exception& e) {
45 std::cerr << "Error parsing config file: " << e.what() << std::endl;
46 std::cerr << "Please check the config file format" << std::endl;
47 std::cerr << "File: " << config_file_ << std::endl;
48 throw std::runtime_error("Error parsing config file");
49 }
50
51 if (toml_config["NumRobots"].value<int>()) {
52 if (toml_config["NumRobots"].value<int>().value() < 1) {
53 std::cerr << "NumRobots must be greater than 0" << std::endl;
54 throw std::runtime_error("NumRobots must be greater than 0");
55 }
56 pNumRobots = toml_config["NumRobots"].value<int>().value();
57 } else {
58 std::cout << "NumRobots (default): " << pNumRobots << std::endl;
59 }
60
61 if (toml_config["NumFeatures"].value<int>()) {
62 pNumFeatures = toml_config["NumFeatures"].value<int>().value();
63 } else {
64 std::cout << "NumFeatures (default): " << pNumFeatures << std::endl;
65 }
66
67 if (toml_config["NumPolygons"].value<int>()) {
68 pNumPolygons = toml_config["NumPolygons"].value<int>().value();
69 } else {
70 std::cout << "NumPolygons (default): " << pNumPolygons << std::endl;
71 }
72
73 if (toml_config["MaxVertices"].value<int>()) {
74 pMaxVertices = toml_config["MaxVertices"].value<int>().value();
75 } else {
76 std::cout << "MaxVertices (default): " << pMaxVertices << std::endl;
77 }
78
79 if (toml_config["PolygonRadius"].value<double>()) {
80 pPolygonRadius = toml_config["PolygonRadius"].value<double>().value();
81 } else {
82 std::cout << "PolygonRadius (default): " << pPolygonRadius << std::endl;
83 }
84
85 auto toml_IO = toml_config["IO"];
86 if (toml_IO["PlotScale"].value<double>()) {
87 pPlotScale = toml_IO["PlotScale"].value<double>().value();
88 } else {
89 std::cout << "PlotScale (default): " << pPlotScale << std::endl;
90 }
91
92 auto toml_EnvironmentMaps = toml_config["Environment.Maps"];
93
94 if (toml_EnvironmentMaps) {
95 auto toml_Resolution = toml_EnvironmentMaps["Resolution"].value<double>();
96 auto toml_WorldMapSize = toml_EnvironmentMaps["WorldMapSize"].value<int>();
97 auto toml_RobotMapSize = toml_EnvironmentMaps["RobotMapSize"].value<int>();
98 auto toml_LocalMapSize = toml_EnvironmentMaps["LocalMapSize"].value<int>();
99
100 if (toml_Resolution) {
101 pResolution = toml_Resolution.value();
102 }
103
104 if (toml_WorldMapSize) {
105 pWorldMapSize = toml_WorldMapSize.value();
106 }
107 if (toml_RobotMapSize) {
108 pRobotMapSize = toml_RobotMapSize.value();
109 }
110 if (toml_LocalMapSize) {
111 pLocalMapSize = toml_LocalMapSize.value();
112 }
113
114 auto toml_EnvironmentMapsUpdateSettings =
115 toml_config["Environment.Maps.UpdateSettings"];
116
117 if (toml_EnvironmentMapsUpdateSettings) {
118 auto toml_UpdateRobotMap =
119 toml_EnvironmentMapsUpdateSettings["UpdateRobotMap"].value<bool>();
120 auto toml_UpdateSensorView =
121 toml_EnvironmentMapsUpdateSettings["UpdateSensorView"].value<bool>();
122 auto toml_UpdateExplorationMap =
123 toml_EnvironmentMapsUpdateSettings["UpdateExplorationMap"]
124 .value<bool>();
125 auto toml_UpdateSystemMap =
126 toml_EnvironmentMapsUpdateSettings["UpdateSystemMap"].value<bool>();
127
128 if (toml_UpdateRobotMap) {
129 pUpdateRobotMap = toml_UpdateRobotMap.value();
130 }
131 if (toml_UpdateSensorView) {
132 pUpdateSensorView = toml_UpdateSensorView.value();
133 }
134 if (toml_UpdateExplorationMap) {
135 pUpdateExplorationMap = toml_UpdateExplorationMap.value();
136 }
137 if (toml_UpdateSystemMap) {
138 pUpdateSystemMap = toml_UpdateSystemMap.value();
139 }
140 }
141 }
142
143 auto toml_EnvironmentIDF = toml_config["Environment.IDF"];
144
145 if (toml_EnvironmentIDF) {
146 auto toml_TruncationBND =
147 toml_EnvironmentIDF["TruncationBND"].value<double>();
148 auto toml_Norm = toml_EnvironmentIDF["Norm"].value<double>();
149 auto toml_MinSigma = toml_EnvironmentIDF["MinSigma"].value<double>();
150 auto toml_MaxSigma = toml_EnvironmentIDF["MaxSigma"].value<double>();
151 auto toml_MinPeak = toml_EnvironmentIDF["MinPeak"].value<double>();
152 auto toml_MaxPeak = toml_EnvironmentIDF["MaxPeak"].value<double>();
153 auto toml_UnknownImportance =
154 toml_EnvironmentIDF["UnknownImportance"].value<double>();
155 auto toml_RobotMapUseUnknownImportance =
156 toml_EnvironmentIDF["RobotMapUseUnknownImportance"].value<bool>();
157
158 if (toml_TruncationBND) {
159 pTruncationBND = toml_TruncationBND.value();
160 }
161 if (toml_Norm) {
162 pNorm = toml_Norm.value();
163 }
164 if (toml_MinSigma) {
165 pMinSigma = toml_MinSigma.value();
166 }
167 if (toml_MaxSigma) {
168 pMaxSigma = toml_MaxSigma.value();
169 }
170 if (toml_MinPeak) {
171 pMinPeak = toml_MinPeak.value();
172 }
173 if (toml_MaxPeak) {
174 pMaxPeak = toml_MaxPeak.value();
175 }
176 if (toml_UnknownImportance) {
177 pUnknownImportance = toml_UnknownImportance.value();
178 }
179 if (toml_RobotMapUseUnknownImportance) {
180 pRobotMapUseUnknownImportance = toml_RobotMapUseUnknownImportance.value();
181 }
182 }
183
184 auto toml_RobotModel = toml_config["RobotModel"];
185
186 if (toml_RobotModel) {
187 auto toml_SensorSize = toml_RobotModel["SensorSize"].value<int>();
188 auto toml_CommunicationRange =
189 toml_RobotModel["CommunicationRange"].value<double>();
190 auto toml_MaxRobotSpeed = toml_RobotModel["MaxRobotSpeed"].value<double>();
191 auto toml_RobotInitDist = toml_RobotModel["RobotInitDist"].value<double>();
192 auto toml_RobotPosHistorySize =
193 toml_RobotModel["RobotPosHistorySize"].value<int>();
194 auto toml_TimeStep = toml_RobotModel["TimeStep"].value<double>();
195
196 if (toml_SensorSize) {
197 pSensorSize = toml_SensorSize.value();
198 }
199 if (toml_CommunicationRange) {
200 pCommunicationRange = toml_CommunicationRange.value();
201 }
202 if (toml_MaxRobotSpeed) {
203 pMaxRobotSpeed = toml_MaxRobotSpeed.value();
204 }
205 if (toml_RobotInitDist) {
206 pRobotInitDist = toml_RobotInitDist.value();
207 }
208 if (toml_RobotPosHistorySize) {
209 pRobotPosHistorySize = toml_RobotPosHistorySize.value();
210 }
211 if (toml_TimeStep) {
212 pTimeStep = toml_TimeStep.value();
213 }
214 }
215
216 if (toml_RobotModel["AddNoise"]) {
217 auto toml_AddNoisePositions =
218 toml_RobotModel["AddNoise.AddNoisePositions"].value<bool>();
219 auto toml_PositionsNoiseSigma =
220 toml_RobotModel["AddNoise.PositionsNoiseSigma"].value<double>();
221 if (toml_AddNoisePositions) {
222 pAddNoisePositions = toml_AddNoisePositions.value();
223 }
224 if (toml_PositionsNoiseSigma) {
225 pPositionsNoiseSigma = toml_PositionsNoiseSigma.value();
226 }
227 }
228
229 auto toml_Algorithm = toml_config["Algorithm"];
230
231 if (toml_Algorithm) {
232 auto toml_EpisodeSteps = toml_Algorithm["EpisodeSteps"].value<int>();
233 if (toml_EpisodeSteps) {
234 pEpisodeSteps = toml_EpisodeSteps.value();
235 }
236 if (toml_Algorithm["CheckOscillations"].value<bool>()) {
237 pCheckOscillations =
238 toml_Algorithm["CheckOscillations"].value<bool>().value();
239 }
240
241 auto toml_LloydMaxIterations =
242 toml_Algorithm["Global-CVT.LloydMaxIterations"].value<int>();
243 auto toml_LloydNumTries =
244 toml_Algorithm["Global-CVT.LloydNumTries"].value<int>();
245 if (toml_LloydMaxIterations) {
246 pLloydMaxIterations = toml_LloydMaxIterations.value();
247 }
248 if (toml_LloydNumTries) {
249 pLloydNumTries = toml_LloydNumTries.value();
250 }
251
252 auto toml_NumFrontiers =
253 toml_Algorithm["Exploration.NumFrontiers"].value<int>();
254 if (toml_NumFrontiers) {
255 pNumFeatures = toml_NumFrontiers.value();
256 }
257 }
258}
259
260void Parameters::PrintParameters() {
261 std::cout << "NumRobots: " << pNumRobots << std::endl;
262 std::cout << "NumFeatures: " << pNumFeatures << std::endl;
263 std::cout << "NumPolygons: " << pNumPolygons << std::endl;
264 std::cout << "MaxVertices: " << pMaxVertices << std::endl;
265 std::cout << "PolygonRadius" << pPolygonRadius << std::endl;
266
267 std::cout << "PlotScale: " << pPlotScale << std::endl;
268
269 std::cout << "Resolution: " << pResolution << std::endl;
270 std::cout << "WorldMapSize: " << pWorldMapSize << std::endl;
271 std::cout << "RobotMapSize: " << pRobotMapSize << std::endl;
272 std::cout << "LocalMapSize: " << pLocalMapSize << std::endl;
273
274 std::cout << "UpdateRobotMap: " << pUpdateRobotMap << std::endl;
275 std::cout << "UpdateSensorView: " << pUpdateSensorView << std::endl;
276 std::cout << "UpdateExplorationMap: " << pUpdateExplorationMap << std::endl;
277 std::cout << "UpdateSystemMap: " << pUpdateSystemMap << std::endl;
278
279 std::cout << "TruncationBND: " << pTruncationBND << std::endl;
280 std::cout << "Norm: " << pNorm << std::endl;
281 std::cout << "MinSigma: " << pMinSigma << std::endl;
282 std::cout << "MaxSigma: " << pMaxSigma << std::endl;
283 std::cout << "MinPeak: " << pMinPeak << std::endl;
284 std::cout << "MaxPeak: " << pMaxPeak << std::endl;
285
286 std::cout << "UnknownImportance: " << pUnknownImportance << std::endl;
287 std::cout << "RobotMapUseUnknownImportance: " << pRobotMapUseUnknownImportance
288 << std::endl;
289
290 std::cout << "SensorSize: " << pSensorSize << std::endl;
291 std::cout << "CommunicationRange: " << pCommunicationRange << std::endl;
292 std::cout << "MaxRobotSpeed: " << pMaxRobotSpeed << std::endl;
293 std::cout << "RobotInitDist: " << pRobotInitDist << std::endl;
294 std::cout << "RobotPosHistorySize: " << pRobotPosHistorySize << std::endl;
295 std::cout << "TimeStep: " << pTimeStep << std::endl;
296
297 std::cout << "AddNoisePositions: " << pAddNoisePositions << std::endl;
298 std::cout << "PositionsNoiseSigma: " << pPositionsNoiseSigma << std::endl;
299
300 std::cout << "EpisodeSteps: " << pEpisodeSteps << std::endl;
301 std::cout << "CheckOscillations: " << pCheckOscillations << std::endl;
302 std::cout << "LloydMaxIterations: " << pLloydMaxIterations << std::endl;
303 std::cout << "LloydNumTries: " << pLloydNumTries << std::endl;
304 std::cout << "NumFrontiers: " << pNumFrontiers << std::endl;
305}
306} /* namespace CoverageControl */
int pRobotMapSize
Robot map saves what the robot has seen.
Definition parameters.h:85
double pTimeStep
Each time step corresponds to pTimeStep seconds.
Definition parameters.h:141
int pNumPolygons
Number of polygonal features.
Definition parameters.h:60
int pNumRobots
Number of robots.
Definition parameters.h:58
int pNumFeatures
Number of features.
Definition parameters.h:59
int pMaxVertices
Maximum number of vertices in a polygon.
Definition parameters.h:61
int pRobotPosHistorySize
Number of previous positions to store.
Definition parameters.h:140
double pCommunicationRange
Radius of communication (in meters)
Definition parameters.h:135
double pTruncationBND
Bivariate Normal Distribution truncated after pTruncationBND * sigma.
Definition parameters.h:108
Namespace for the CoverageControl library.
Contains parameters.