29#include "CoverageControl/extern/tomlplusplus/toml.hpp"
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");
41 toml::table toml_config;
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");
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");
56 pNumRobots = toml_config[
"NumRobots"].value<
int>().value();
58 std::cout <<
"NumRobots (default): " <<
pNumRobots << std::endl;
61 if (toml_config[
"NumFeatures"].value<int>()) {
62 pNumFeatures = toml_config[
"NumFeatures"].value<
int>().value();
64 std::cout <<
"NumFeatures (default): " <<
pNumFeatures << std::endl;
67 if (toml_config[
"NumPolygons"].value<int>()) {
68 pNumPolygons = toml_config[
"NumPolygons"].value<
int>().value();
70 std::cout <<
"NumPolygons (default): " <<
pNumPolygons << std::endl;
73 if (toml_config[
"MaxVertices"].value<int>()) {
74 pMaxVertices = toml_config[
"MaxVertices"].value<
int>().value();
76 std::cout <<
"MaxVertices (default): " <<
pMaxVertices << std::endl;
79 if (toml_config[
"PolygonRadius"].value<double>()) {
80 pPolygonRadius = toml_config[
"PolygonRadius"].value<
double>().value();
82 std::cout <<
"PolygonRadius (default): " << pPolygonRadius << std::endl;
85 auto toml_IO = toml_config[
"IO"];
86 if (toml_IO[
"PlotScale"].value<double>()) {
87 pPlotScale = toml_IO[
"PlotScale"].value<
double>().value();
89 std::cout <<
"PlotScale (default): " <<
pPlotScale << std::endl;
92 auto toml_EnvironmentMaps = toml_config[
"Environment.Maps"];
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>();
100 if (toml_Resolution) {
104 if (toml_WorldMapSize) {
107 if (toml_RobotMapSize) {
110 if (toml_LocalMapSize) {
114 auto toml_EnvironmentMapsUpdateSettings =
115 toml_config[
"Environment.Maps.UpdateSettings"];
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"]
125 auto toml_UpdateSystemMap =
126 toml_EnvironmentMapsUpdateSettings[
"UpdateSystemMap"].value<
bool>();
128 if (toml_UpdateRobotMap) {
129 pUpdateRobotMap = toml_UpdateRobotMap.value();
131 if (toml_UpdateSensorView) {
132 pUpdateSensorView = toml_UpdateSensorView.value();
134 if (toml_UpdateExplorationMap) {
135 pUpdateExplorationMap = toml_UpdateExplorationMap.value();
137 if (toml_UpdateSystemMap) {
138 pUpdateSystemMap = toml_UpdateSystemMap.value();
143 auto toml_EnvironmentIDF = toml_config[
"Environment.IDF"];
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>();
158 if (toml_TruncationBND) {
162 pNorm = toml_Norm.value();
165 pMinSigma = toml_MinSigma.value();
168 pMaxSigma = toml_MaxSigma.value();
171 pMinPeak = toml_MinPeak.value();
174 pMaxPeak = toml_MaxPeak.value();
176 if (toml_UnknownImportance) {
177 pUnknownImportance = toml_UnknownImportance.value();
179 if (toml_RobotMapUseUnknownImportance) {
180 pRobotMapUseUnknownImportance = toml_RobotMapUseUnknownImportance.value();
184 auto toml_RobotModel = toml_config[
"RobotModel"];
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>();
196 if (toml_SensorSize) {
197 pSensorSize = toml_SensorSize.value();
199 if (toml_CommunicationRange) {
202 if (toml_MaxRobotSpeed) {
203 pMaxRobotSpeed = toml_MaxRobotSpeed.value();
205 if (toml_RobotInitDist) {
208 if (toml_RobotPosHistorySize) {
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();
224 if (toml_PositionsNoiseSigma) {
225 pPositionsNoiseSigma = toml_PositionsNoiseSigma.value();
229 auto toml_Algorithm = toml_config[
"Algorithm"];
231 if (toml_Algorithm) {
232 auto toml_EpisodeSteps = toml_Algorithm[
"EpisodeSteps"].value<
int>();
233 if (toml_EpisodeSteps) {
234 pEpisodeSteps = toml_EpisodeSteps.value();
236 if (toml_Algorithm[
"CheckOscillations"].value<bool>()) {
238 toml_Algorithm[
"CheckOscillations"].value<
bool>().value();
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();
248 if (toml_LloydNumTries) {
249 pLloydNumTries = toml_LloydNumTries.value();
252 auto toml_NumFrontiers =
253 toml_Algorithm[
"Exploration.NumFrontiers"].value<
int>();
254 if (toml_NumFrontiers) {
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;
267 std::cout <<
"PlotScale: " <<
pPlotScale << std::endl;
269 std::cout <<
"Resolution: " <<
pResolution << std::endl;
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;
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;
286 std::cout <<
"UnknownImportance: " << pUnknownImportance << std::endl;
287 std::cout <<
"RobotMapUseUnknownImportance: " << pRobotMapUseUnknownImportance
290 std::cout <<
"SensorSize: " << pSensorSize << std::endl;
292 std::cout <<
"MaxRobotSpeed: " << pMaxRobotSpeed << std::endl;
295 std::cout <<
"TimeStep: " <<
pTimeStep << std::endl;
297 std::cout <<
"AddNoisePositions: " << pAddNoisePositions << std::endl;
298 std::cout <<
"PositionsNoiseSigma: " << pPositionsNoiseSigma << std::endl;
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;
int pRobotMapSize
Robot map saves what the robot has seen.
double pTimeStep
Each time step corresponds to pTimeStep seconds.
int pNumPolygons
Number of polygonal features.
int pNumRobots
Number of robots.
int pNumFeatures
Number of features.
int pMaxVertices
Maximum number of vertices in a polygon.
int pRobotPosHistorySize
Number of previous positions to store.
double pCommunicationRange
Radius of communication (in meters)
double pTruncationBND
Bivariate Normal Distribution truncated after pTruncationBND * sigma.
Namespace for the CoverageControl library.