YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
FakeMotionControl_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.2)
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_GENERATION is ON.
10
11// Generated on: Tue Jul 28 23:33:16 2026
12
13
15#include <yarp/os/LogStream.h>
16#include <yarp/os/Value.h>
17
18namespace {
19 YARP_LOG_COMPONENT(FakeMotionControlParamsCOMPONENT, "yarp.device.FakeMotionControl")
20}
21
22
26
27
29{
30 std::vector<std::string> params;
31 params.push_back("GENERAL::Joints");
32 params.push_back("GENERAL::AxisMap");
33 params.push_back("GENERAL::AxisName");
34 params.push_back("GENERAL::AxisType");
35 params.push_back("GENERAL::ampsToSensor");
36 params.push_back("GENERAL::fullscalePWM");
37 params.push_back("GENERAL::Encoder");
38 params.push_back("LIMITS::Max");
39 params.push_back("LIMITS::Min");
40 return params;
41}
42
43
44bool FakeMotionControl_ParamsParser::getParamValue(const std::string& paramName, std::string& paramValue) const
45{
46 if (paramName =="GENERAL::Joints")
47 {
48 paramValue = std::to_string(m_GENERAL_Joints);
49 return true;
50 }
51 if (paramName =="GENERAL::AxisMap")
52 {
53 std::ostringstream oss;
54 oss << "( ";
55 for (auto x : m_GENERAL_AxisMap)
56 {
57 oss << x << " ";
58 }
59 oss << " )";
60 paramValue = oss.str();
61 return true;
62 }
63 if (paramName =="GENERAL::AxisName")
64 {
65 std::ostringstream oss;
66 oss << "( ";
67 for (auto x : m_GENERAL_AxisName)
68 {
69 oss << x << " ";
70 }
71 oss << " )";
72 paramValue = oss.str();
73 return true;
74 }
75 if (paramName =="GENERAL::AxisType")
76 {
77 std::ostringstream oss;
78 oss << "( ";
79 for (auto x : m_GENERAL_AxisType)
80 {
81 oss << x << " ";
82 }
83 oss << " )";
84 paramValue = oss.str();
85 return true;
86 }
87 if (paramName =="GENERAL::ampsToSensor")
88 {
89 std::ostringstream oss;
90 oss << "( ";
91 for (auto x : m_GENERAL_ampsToSensor)
92 {
93 oss << x << " ";
94 }
95 oss << " )";
96 paramValue = oss.str();
97 return true;
98 }
99 if (paramName =="GENERAL::fullscalePWM")
100 {
101 std::ostringstream oss;
102 oss << "( ";
103 for (auto x : m_GENERAL_fullscalePWM)
104 {
105 oss << x << " ";
106 }
107 oss << " )";
108 paramValue = oss.str();
109 return true;
110 }
111 if (paramName =="GENERAL::Encoder")
112 {
113 std::ostringstream oss;
114 oss << "( ";
115 for (auto x : m_GENERAL_Encoder)
116 {
117 oss << x << " ";
118 }
119 oss << " )";
120 paramValue = oss.str();
121 return true;
122 }
123 if (paramName =="LIMITS::Max")
124 {
125 std::ostringstream oss;
126 oss << "( ";
127 for (auto x : m_LIMITS_Max)
128 {
129 oss << x << " ";
130 }
131 oss << " )";
132 paramValue = oss.str();
133 return true;
134 }
135 if (paramName =="LIMITS::Min")
136 {
137 std::ostringstream oss;
138 oss << "( ";
139 for (auto x : m_LIMITS_Min)
140 {
141 oss << x << " ";
142 }
143 oss << " )";
144 paramValue = oss.str();
145 return true;
146 }
147
148 yError() <<"parameter '" << paramName << "' was not found";
149 return false;
150
151}
152
153
155{
156 //This is a sub-optimal solution.
157 //Ideally getConfiguration() should return all parameters but it is currently
158 //returning only user provided parameters (excluding default values)
159 //This behaviour will be fixed in the near future.
160 std::string s_cfg = m_provided_configuration;
161 return s_cfg;
162}
163
165{
166 //Check for --help option
167 if (config.check("help"))
168 {
169 yCInfo(FakeMotionControlParamsCOMPONENT) << getDocumentationOfDeviceParams();
170 }
171
174 //Parser of parameter GENERAL::Joints
175 {
176 yarp::os::Bottle sectionp;
177 sectionp = config.findGroup("GENERAL");
178 if (sectionp.check("Joints"))
179 {
180 m_GENERAL_Joints = sectionp.find("Joints").asInt64();
181 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'GENERAL::Joints' using value:" << m_GENERAL_Joints;
182 }
183 else
184 {
185 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'GENERAL::Joints' using DEFAULT value:" << m_GENERAL_Joints;
186 }
187 prop_check.unput("GENERAL::Joints");
188 }
189
190 //Parser of parameter GENERAL::AxisMap
191 {
192 yarp::os::Bottle sectionp;
193 sectionp = config.findGroup("GENERAL");
194 if (sectionp.check("AxisMap"))
195 {
196 {
197 m_GENERAL_AxisMap.clear();
198 yarp::os::Bottle* tempBot = sectionp.find("AxisMap").asList();
199 if (tempBot)
200 {
201 std::string tempBots = tempBot->toString();
202 for (size_t i=0; i<tempBot->size(); i++)
203 {
204 m_GENERAL_AxisMap.push_back(tempBot->get(i).asInt64());
205 }
206 }
207 else
208 {
209 yCError(FakeMotionControlParamsCOMPONENT) <<"parameter 'GENERAL_AxisMap' is not a properly formatted bottle";
210 }
211 }
212 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'GENERAL::AxisMap' using value:" << m_GENERAL_AxisMap;
213 }
214 else
215 {
216 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'GENERAL::AxisMap' using DEFAULT value:" << m_GENERAL_AxisMap;
217 }
218 prop_check.unput("GENERAL::AxisMap");
219 }
220
221 //Parser of parameter GENERAL::AxisName
222 {
223 yarp::os::Bottle sectionp;
224 sectionp = config.findGroup("GENERAL");
225 if (sectionp.check("AxisName"))
226 {
227 {
228 m_GENERAL_AxisName.clear();
229 yarp::os::Bottle* tempBot = sectionp.find("AxisName").asList();
230 if (tempBot)
231 {
232 std::string tempBots = tempBot->toString();
233 for (size_t i=0; i<tempBot->size(); i++)
234 {
235 m_GENERAL_AxisName.push_back(tempBot->get(i).asString());
236 }
237 }
238 else
239 {
240 yCError(FakeMotionControlParamsCOMPONENT) <<"parameter 'GENERAL_AxisName' is not a properly formatted bottle";
241 }
242 }
243 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'GENERAL::AxisName' using value:" << m_GENERAL_AxisName;
244 }
245 else
246 {
247 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'GENERAL::AxisName' using DEFAULT value:" << m_GENERAL_AxisName;
248 }
249 prop_check.unput("GENERAL::AxisName");
250 }
251
252 //Parser of parameter GENERAL::AxisType
253 {
254 yarp::os::Bottle sectionp;
255 sectionp = config.findGroup("GENERAL");
256 if (sectionp.check("AxisType"))
257 {
258 {
259 m_GENERAL_AxisType.clear();
260 yarp::os::Bottle* tempBot = sectionp.find("AxisType").asList();
261 if (tempBot)
262 {
263 std::string tempBots = tempBot->toString();
264 for (size_t i=0; i<tempBot->size(); i++)
265 {
266 m_GENERAL_AxisType.push_back(tempBot->get(i).asString());
267 }
268 }
269 else
270 {
271 yCError(FakeMotionControlParamsCOMPONENT) <<"parameter 'GENERAL_AxisType' is not a properly formatted bottle";
272 }
273 }
274 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'GENERAL::AxisType' using value:" << m_GENERAL_AxisType;
275 }
276 else
277 {
278 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'GENERAL::AxisType' using DEFAULT value:" << m_GENERAL_AxisType;
279 }
280 prop_check.unput("GENERAL::AxisType");
281 }
282
283 //Parser of parameter GENERAL::ampsToSensor
284 {
285 yarp::os::Bottle sectionp;
286 sectionp = config.findGroup("GENERAL");
287 if (sectionp.check("ampsToSensor"))
288 {
289 {
291 yarp::os::Bottle* tempBot = sectionp.find("ampsToSensor").asList();
292 if (tempBot)
293 {
294 std::string tempBots = tempBot->toString();
295 for (size_t i=0; i<tempBot->size(); i++)
296 {
297 m_GENERAL_ampsToSensor.push_back(tempBot->get(i).asFloat64());
298 }
299 }
300 else
301 {
302 yCError(FakeMotionControlParamsCOMPONENT) <<"parameter 'GENERAL_ampsToSensor' is not a properly formatted bottle";
303 }
304 }
305 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'GENERAL::ampsToSensor' using value:" << m_GENERAL_ampsToSensor;
306 }
307 else
308 {
309 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'GENERAL::ampsToSensor' using DEFAULT value:" << m_GENERAL_ampsToSensor;
310 }
311 prop_check.unput("GENERAL::ampsToSensor");
312 }
313
314 //Parser of parameter GENERAL::fullscalePWM
315 {
316 yarp::os::Bottle sectionp;
317 sectionp = config.findGroup("GENERAL");
318 if (sectionp.check("fullscalePWM"))
319 {
320 {
322 yarp::os::Bottle* tempBot = sectionp.find("fullscalePWM").asList();
323 if (tempBot)
324 {
325 std::string tempBots = tempBot->toString();
326 for (size_t i=0; i<tempBot->size(); i++)
327 {
328 m_GENERAL_fullscalePWM.push_back(tempBot->get(i).asFloat64());
329 }
330 }
331 else
332 {
333 yCError(FakeMotionControlParamsCOMPONENT) <<"parameter 'GENERAL_fullscalePWM' is not a properly formatted bottle";
334 }
335 }
336 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'GENERAL::fullscalePWM' using value:" << m_GENERAL_fullscalePWM;
337 }
338 else
339 {
340 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'GENERAL::fullscalePWM' using DEFAULT value:" << m_GENERAL_fullscalePWM;
341 }
342 prop_check.unput("GENERAL::fullscalePWM");
343 }
344
345 //Parser of parameter GENERAL::Encoder
346 {
347 yarp::os::Bottle sectionp;
348 sectionp = config.findGroup("GENERAL");
349 if (sectionp.check("Encoder"))
350 {
351 {
352 m_GENERAL_Encoder.clear();
353 yarp::os::Bottle* tempBot = sectionp.find("Encoder").asList();
354 if (tempBot)
355 {
356 std::string tempBots = tempBot->toString();
357 for (size_t i=0; i<tempBot->size(); i++)
358 {
359 m_GENERAL_Encoder.push_back(tempBot->get(i).asInt64());
360 }
361 }
362 else
363 {
364 yCError(FakeMotionControlParamsCOMPONENT) <<"parameter 'GENERAL_Encoder' is not a properly formatted bottle";
365 }
366 }
367 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'GENERAL::Encoder' using value:" << m_GENERAL_Encoder;
368 }
369 else
370 {
371 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'GENERAL::Encoder' using DEFAULT value:" << m_GENERAL_Encoder;
372 }
373 prop_check.unput("GENERAL::Encoder");
374 }
375
376 //Parser of parameter LIMITS::Max
377 {
378 yarp::os::Bottle sectionp;
379 sectionp = config.findGroup("LIMITS");
380 if (sectionp.check("Max"))
381 {
382 {
383 m_LIMITS_Max.clear();
384 yarp::os::Bottle* tempBot = sectionp.find("Max").asList();
385 if (tempBot)
386 {
387 std::string tempBots = tempBot->toString();
388 for (size_t i=0; i<tempBot->size(); i++)
389 {
390 m_LIMITS_Max.push_back(tempBot->get(i).asFloat64());
391 }
392 }
393 else
394 {
395 yCError(FakeMotionControlParamsCOMPONENT) <<"parameter 'LIMITS_Max' is not a properly formatted bottle";
396 }
397 }
398 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'LIMITS::Max' using value:" << m_LIMITS_Max;
399 }
400 else
401 {
402 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'LIMITS::Max' using DEFAULT value:" << m_LIMITS_Max;
403 }
404 prop_check.unput("LIMITS::Max");
405 }
406
407 //Parser of parameter LIMITS::Min
408 {
409 yarp::os::Bottle sectionp;
410 sectionp = config.findGroup("LIMITS");
411 if (sectionp.check("Min"))
412 {
413 {
414 m_LIMITS_Min.clear();
415 yarp::os::Bottle* tempBot = sectionp.find("Min").asList();
416 if (tempBot)
417 {
418 std::string tempBots = tempBot->toString();
419 for (size_t i=0; i<tempBot->size(); i++)
420 {
421 m_LIMITS_Min.push_back(tempBot->get(i).asFloat64());
422 }
423 }
424 else
425 {
426 yCError(FakeMotionControlParamsCOMPONENT) <<"parameter 'LIMITS_Min' is not a properly formatted bottle";
427 }
428 }
429 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'LIMITS::Min' using value:" << m_LIMITS_Min;
430 }
431 else
432 {
433 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'LIMITS::Min' using DEFAULT value:" << m_LIMITS_Min;
434 }
435 prop_check.unput("LIMITS::Min");
436 }
437
438 /*
439 //This code check if the user set some parameter which are not check by the parser
440 //If the parser is set in strict mode, this will generate an error
441 if (prop_check.size() > 0)
442 {
443 bool extra_params_found = false;
444 for (auto it=prop_check.begin(); it!=prop_check.end(); it++)
445 {
446 if (m_parser_is_strict)
447 {
448 yCError(FakeMotionControlParamsCOMPONENT) << "User asking for parameter: "<<it->name <<" which is unknown to this parser!";
449 extra_params_found = true;
450 }
451 else
452 {
453 yCWarning(FakeMotionControlParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!";
454 }
455 }
456
457 if (m_parser_is_strict && extra_params_found)
458 {
459 return false;
460 }
461 }
462 */
463 return true;
464}
465
466
468{
469 std::string doc;
470 doc = doc + std::string("\n=============================================\n");
471 doc = doc + std::string("This is the help for device: FakeMotionControl\n");
472 doc = doc + std::string("\n");
473 doc = doc + std::string("This is the list of the parameters accepted by the device:\n");
474 doc = doc + std::string("'GENERAL::Joints': Number of degrees of freedom\n");
475 doc = doc + std::string("'GENERAL::AxisMap': a list of reordered indices for the axes\n");
476 doc = doc + std::string("'GENERAL::AxisName': a list of strings representing the axes names\n");
477 doc = doc + std::string("'GENERAL::AxisType': a list of strings representing the axes type (revolute/prismatic)\n");
478 doc = doc + std::string("'GENERAL::ampsToSensor': a list of scales for the ampsToSensor conversion factors\n");
479 doc = doc + std::string("'GENERAL::fullscalePWM': a list of scales for the fullscalePWM conversion factors\n");
480 doc = doc + std::string("'GENERAL::Encoder': a list of scales for the encoders\n");
481 doc = doc + std::string("'LIMITS::Max': max encoder position\n");
482 doc = doc + std::string("'LIMITS::Min': min encoder position\n");
483 doc = doc + std::string("\n");
484 doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n");
485 doc = doc + " yarpdev --device fakeMotionControl --GENERAL::Joints 1 --GENERAL::AxisMap <optional_value> --GENERAL::AxisName <optional_value> --GENERAL::AxisType <optional_value> --GENERAL::ampsToSensor <optional_value> --GENERAL::fullscalePWM <optional_value> --GENERAL::Encoder <optional_value> --LIMITS::Max <optional_value> --LIMITS::Min <optional_value>\n";
486 doc = doc + std::string("Using only mandatory params:\n");
487 doc = doc + " yarpdev --device fakeMotionControl\n";
488 doc = doc + std::string("=============================================\n\n"); return doc;
489}
#define yError(...)
Definition Log.h:361
std::vector< std::string > getListOfParams() const override
Return a list of all params used by the device.
bool getParamValue(const std::string &paramName, std::string &paramValue) const override
Return the value (represented as a string) of the requested parameter.
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
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:65
size_type size() const
Gets the number of elements in the bottle.
Definition Bottle.cpp:257
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition Bottle.cpp:252
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Definition Bottle.cpp:283
std::string toString() const override
Gives a human-readable textual representation of the bottle.
Definition Bottle.cpp:217
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
Definition Bottle.cpp:293
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 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:228
virtual std::int64_t asInt64() const
Get 64-bit integer value.
Definition Value.cpp:216
virtual Bottle * asList() const
Get list value.
Definition Value.cpp:252
virtual std::string asString() const
Get string value.
Definition Value.cpp:246
#define yCInfo(component,...)
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)