YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
FakeLaser_ParamsParser.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
6
7// Generated by yarpDeviceParamParserGenerator (2.0)
8// This is an automatically generated file. Please do not edit it.
9// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON.
10
11// Generated on: Thu May 22 11:32:33 2025
12
13
15#include <yarp/os/LogStream.h>
16#include <yarp/os/Value.h>
17
18namespace {
19 YARP_LOG_COMPONENT(FakeLaserParamsCOMPONENT, "yarp.device.FakeLaser")
20}
21
22
26
27
28std::vector<std::string> FakeLaser_ParamsParser::getListOfParams() const
29{
30 std::vector<std::string> params;
31 params.push_back("test");
32 params.push_back("localization_port");
33 params.push_back("localization_server");
34 params.push_back("localization_client");
35 params.push_back("localization_device");
36 params.push_back("MAP_MODE::map_file");
37 params.push_back("MAP_MODE::map_context");
38 params.push_back("clip_max");
39 params.push_back("clip_min");
40 params.push_back("GENERAL::period");
41 params.push_back("CONSTANT_MODE::const_distance");
42 return params;
43}
44
45
46bool FakeLaser_ParamsParser::getParamValue(const std::string& paramName, std::string& paramValue) const
47{
48 if (paramName =="test")
49 {
50 paramValue = m_test;
51 return true;
52 }
53 if (paramName =="localization_port")
54 {
55 paramValue = m_localization_port;
56 return true;
57 }
58 if (paramName =="localization_server")
59 {
60 paramValue = m_localization_server;
61 return true;
62 }
63 if (paramName =="localization_client")
64 {
65 paramValue = m_localization_client;
66 return true;
67 }
68 if (paramName =="localization_device")
69 {
70 paramValue = m_localization_device;
71 return true;
72 }
73 if (paramName =="MAP_MODE::map_file")
74 {
75 paramValue = m_MAP_MODE_map_file;
76 return true;
77 }
78 if (paramName =="MAP_MODE::map_context")
79 {
80 paramValue = m_MAP_MODE_map_context;
81 return true;
82 }
83 if (paramName =="clip_max")
84 {
85 paramValue = std::to_string(m_clip_max);
86 return true;
87 }
88 if (paramName =="clip_min")
89 {
90 paramValue = std::to_string(m_clip_min);
91 return true;
92 }
93 if (paramName =="GENERAL::period")
94 {
95 paramValue = std::to_string(m_GENERAL_period);
96 return true;
97 }
98 if (paramName =="CONSTANT_MODE::const_distance")
99 {
100 paramValue = std::to_string(m_CONSTANT_MODE_const_distance);
101 return true;
102 }
103
104 yError() <<"parameter '" << paramName << "' was not found";
105 return false;
106
107}
108
109
111{
112 //This is a sub-optimal solution.
113 //Ideally getConfiguration() should return all parameters but it is currently
114 //returning only user provided parameters (excluding default values)
115 //This behaviour will be fixed in the near future.
116 std::string s_cfg = m_provided_configuration;
117 return s_cfg;
118}
119
121{
122 //Check for --help option
123 if (config.check("help"))
124 {
125 yCInfo(FakeLaserParamsCOMPONENT) << getDocumentationOfDeviceParams();
126 }
127
130 //Parser of parameter test
131 {
132 if (config.check("test"))
133 {
134 m_test = config.find("test").asString();
135 yCInfo(FakeLaserParamsCOMPONENT) << "Parameter 'test' using value:" << m_test;
136 }
137 else
138 {
139 yCError(FakeLaserParamsCOMPONENT) << "Mandatory parameter 'test' not found!";
140 yCError(FakeLaserParamsCOMPONENT) << "Description of the parameter: Choose the modality";
141 return false;
142 }
143 prop_check.unput("test");
144 }
145
146 //Parser of parameter localization_port
147 {
148 if (config.check("localization_port"))
149 {
150 m_localization_port = config.find("localization_port").asString();
151 yCInfo(FakeLaserParamsCOMPONENT) << "Parameter 'localization_port' using value:" << m_localization_port;
152 }
153 else
154 {
155 yCInfo(FakeLaserParamsCOMPONENT) << "Parameter 'localization_port' using DEFAULT value:" << m_localization_port;
156 }
157 prop_check.unput("localization_port");
158 }
159
160 //Parser of parameter localization_server
161 {
162 if (config.check("localization_server"))
163 {
164 m_localization_server = config.find("localization_server").asString();
165 yCInfo(FakeLaserParamsCOMPONENT) << "Parameter 'localization_server' using value:" << m_localization_server;
166 }
167 else
168 {
169 yCInfo(FakeLaserParamsCOMPONENT) << "Parameter 'localization_server' using DEFAULT value:" << m_localization_server;
170 }
171 prop_check.unput("localization_server");
172 }
173
174 //Parser of parameter localization_client
175 {
176 if (config.check("localization_client"))
177 {
178 m_localization_client = config.find("localization_client").asString();
179 yCInfo(FakeLaserParamsCOMPONENT) << "Parameter 'localization_client' using value:" << m_localization_client;
180 }
181 else
182 {
183 yCInfo(FakeLaserParamsCOMPONENT) << "Parameter 'localization_client' using DEFAULT value:" << m_localization_client;
184 }
185 prop_check.unput("localization_client");
186 }
187
188 //Parser of parameter localization_device
189 {
190 if (config.check("localization_device"))
191 {
192 m_localization_device = config.find("localization_device").asString();
193 yCInfo(FakeLaserParamsCOMPONENT) << "Parameter 'localization_device' using value:" << m_localization_device;
194 }
195 else
196 {
197 yCInfo(FakeLaserParamsCOMPONENT) << "Parameter 'localization_device' using DEFAULT value:" << m_localization_device;
198 }
199 prop_check.unput("localization_device");
200 }
201
202 //Parser of parameter MAP_MODE::map_file
203 {
204 yarp::os::Bottle sectionp;
205 sectionp = config.findGroup("MAP_MODE");
206 if (sectionp.check("map_file"))
207 {
208 m_MAP_MODE_map_file = sectionp.find("map_file").asString();
209 yCInfo(FakeLaserParamsCOMPONENT) << "Parameter 'MAP_MODE::map_file' using value:" << m_MAP_MODE_map_file;
210 }
211 else
212 {
213 yCInfo(FakeLaserParamsCOMPONENT) << "Parameter 'MAP_MODE::map_file' using DEFAULT value:" << m_MAP_MODE_map_file;
214 }
215 prop_check.unput("MAP_MODE::map_file");
216 }
217
218 //Parser of parameter MAP_MODE::map_context
219 {
220 yarp::os::Bottle sectionp;
221 sectionp = config.findGroup("MAP_MODE");
222 if (sectionp.check("map_context"))
223 {
224 m_MAP_MODE_map_context = sectionp.find("map_context").asString();
225 yCInfo(FakeLaserParamsCOMPONENT) << "Parameter 'MAP_MODE::map_context' using value:" << m_MAP_MODE_map_context;
226 }
227 else
228 {
229 yCInfo(FakeLaserParamsCOMPONENT) << "Parameter 'MAP_MODE::map_context' using DEFAULT value:" << m_MAP_MODE_map_context;
230 }
231 prop_check.unput("MAP_MODE::map_context");
232 }
233
234 //Parser of parameter clip_max
235 {
236 if (config.check("clip_max"))
237 {
238 m_clip_max = config.find("clip_max").asFloat64();
239 yCInfo(FakeLaserParamsCOMPONENT) << "Parameter 'clip_max' using value:" << m_clip_max;
240 }
241 else
242 {
243 yCInfo(FakeLaserParamsCOMPONENT) << "Parameter 'clip_max' using DEFAULT value:" << m_clip_max;
244 }
245 prop_check.unput("clip_max");
246 }
247
248 //Parser of parameter clip_min
249 {
250 if (config.check("clip_min"))
251 {
252 m_clip_min = config.find("clip_min").asFloat64();
253 yCInfo(FakeLaserParamsCOMPONENT) << "Parameter 'clip_min' using value:" << m_clip_min;
254 }
255 else
256 {
257 yCInfo(FakeLaserParamsCOMPONENT) << "Parameter 'clip_min' using DEFAULT value:" << m_clip_min;
258 }
259 prop_check.unput("clip_min");
260 }
261
262 //Parser of parameter GENERAL::period
263 {
264 yarp::os::Bottle sectionp;
265 sectionp = config.findGroup("GENERAL");
266 if (sectionp.check("period"))
267 {
268 m_GENERAL_period = sectionp.find("period").asFloat64();
269 yCInfo(FakeLaserParamsCOMPONENT) << "Parameter 'GENERAL::period' using value:" << m_GENERAL_period;
270 }
271 else
272 {
273 yCInfo(FakeLaserParamsCOMPONENT) << "Parameter 'GENERAL::period' using DEFAULT value:" << m_GENERAL_period;
274 }
275 prop_check.unput("GENERAL::period");
276 }
277
278 //Parser of parameter CONSTANT_MODE::const_distance
279 {
280 yarp::os::Bottle sectionp;
281 sectionp = config.findGroup("CONSTANT_MODE");
282 if (sectionp.check("const_distance"))
283 {
284 m_CONSTANT_MODE_const_distance = sectionp.find("const_distance").asFloat64();
285 yCInfo(FakeLaserParamsCOMPONENT) << "Parameter 'CONSTANT_MODE::const_distance' using value:" << m_CONSTANT_MODE_const_distance;
286 }
287 else
288 {
289 yCInfo(FakeLaserParamsCOMPONENT) << "Parameter 'CONSTANT_MODE::const_distance' using DEFAULT value:" << m_CONSTANT_MODE_const_distance;
290 }
291 prop_check.unput("CONSTANT_MODE::const_distance");
292 }
293
294 /*
295 //This code check if the user set some parameter which are not check by the parser
296 //If the parser is set in strict mode, this will generate an error
297 if (prop_check.size() > 0)
298 {
299 bool extra_params_found = false;
300 for (auto it=prop_check.begin(); it!=prop_check.end(); it++)
301 {
302 if (m_parser_is_strict)
303 {
304 yCError(FakeLaserParamsCOMPONENT) << "User asking for parameter: "<<it->name <<" which is unknown to this parser!";
305 extra_params_found = true;
306 }
307 else
308 {
309 yCWarning(FakeLaserParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!";
310 }
311 }
312
313 if (m_parser_is_strict && extra_params_found)
314 {
315 return false;
316 }
317 }
318 */
319 return true;
320}
321
322
324{
325 std::string doc;
326 doc = doc + std::string("\n=============================================\n");
327 doc = doc + std::string("This is the help for device: FakeLaser\n");
328 doc = doc + std::string("\n");
329 doc = doc + std::string("This is the list of the parameters accepted by the device:\n");
330 doc = doc + std::string("'test': Choose the modality\n");
331 doc = doc + std::string("'localization_port': Full name of the port to which device connects to receive the localization data\n");
332 doc = doc + std::string("'localization_server': Full name of the port to which device connects to receive the localization data\n");
333 doc = doc + std::string("'localization_client': Full name of the local transformClient opened by the device\n");
334 doc = doc + std::string("'localization_device': Type of localization device, e.g. localization2DClient, localization2D_nwc_yarp\n");
335 doc = doc + std::string("'MAP_MODE::map_file': Full path to a .map file\n");
336 doc = doc + std::string("'MAP_MODE::map_context': Full path to a .map file\n");
337 doc = doc + std::string("'clip_max': Maximum detectable distance for an obstacle\n");
338 doc = doc + std::string("'clip_min': Minimum detectable distance for an obstacle\n");
339 doc = doc + std::string("'GENERAL::period': Thread period\n");
340 doc = doc + std::string("'CONSTANT_MODE::const_distance': Default const distance for mode use_constant\n");
341 doc = doc + std::string("\n");
342 doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n");
343 doc = doc + " yarpdev --device fakeLaser --test use_pattern --localization_port /fakeLaser/location:i --localization_server /localizationServer --localization_client /fakeLaser/localizationClient --localization_device localization2DClient --MAP_MODE::map_file <optional_value> --MAP_MODE::map_context <optional_value> --clip_max 3.5 --clip_min 0.1 --GENERAL::period 0.02 --CONSTANT_MODE::const_distance 1\n";
344 doc = doc + std::string("Using only mandatory params:\n");
345 doc = doc + " yarpdev --device fakeLaser --test use_pattern\n";
346 doc = doc + std::string("=============================================\n\n"); return doc;
347}
#define yError(...)
Definition Log.h:361
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
bool getParamValue(const std::string &paramName, std::string &paramValue) const override
Return the value (represented as a string) of the requested parameter.
std::vector< std::string > getListOfParams() const override
Return a list of all params used by the device.
std::string getDocumentationOfDeviceParams() const override
Get the documentation of the DeviceDriver's parameters.
std::string getConfiguration() const override
Return the configuration of the device.
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Definition Bottle.cpp:277
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
Definition Bottle.cpp:287
A class for storing options and configuration information.
Definition Property.h:33
void unput(const std::string &key)
Remove the association from the given key to a value, if present.
A base class for nested structures that can be searched.
Definition Searchable.h:31
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
virtual Bottle & findGroup(const std::string &key) const =0
Gets a list corresponding to a given keyword.
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
Definition Value.cpp:222
virtual std::string asString() const
Get string value.
Definition Value.cpp:234
#define yCInfo(component,...)
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)