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.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:31 2025
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 return false;
54 }
55 if (paramName =="GENERAL::AxisName")
56 {
57 return false;
58 }
59 if (paramName =="GENERAL::AxisType")
60 {
61 return false;
62 }
63 if (paramName =="GENERAL::ampsToSensor")
64 {
65 return false;
66 }
67 if (paramName =="GENERAL::fullscalePWM")
68 {
69 return false;
70 }
71 if (paramName =="GENERAL::Encoder")
72 {
73 return false;
74 }
75 if (paramName =="LIMITS::Max")
76 {
77 return false;
78 }
79 if (paramName =="LIMITS::Min")
80 {
81 return false;
82 }
83
84 yError() <<"parameter '" << paramName << "' was not found";
85 return false;
86
87}
88
89
91{
92 //This is a sub-optimal solution.
93 //Ideally getConfiguration() should return all parameters but it is currently
94 //returning only user provided parameters (excluding default values)
95 //This behaviour will be fixed in the near future.
96 std::string s_cfg = m_provided_configuration;
97 return s_cfg;
98}
99
101{
102 //Check for --help option
103 if (config.check("help"))
104 {
105 yCInfo(FakeMotionControlParamsCOMPONENT) << getDocumentationOfDeviceParams();
106 }
107
110 //Parser of parameter GENERAL::Joints
111 {
112 yarp::os::Bottle sectionp;
113 sectionp = config.findGroup("GENERAL");
114 if (sectionp.check("Joints"))
115 {
116 m_GENERAL_Joints = sectionp.find("Joints").asInt64();
117 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'GENERAL::Joints' using value:" << m_GENERAL_Joints;
118 }
119 else
120 {
121 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'GENERAL::Joints' using DEFAULT value:" << m_GENERAL_Joints;
122 }
123 prop_check.unput("GENERAL::Joints");
124 }
125
126 //Parser of parameter GENERAL::AxisMap
127 {
128 yarp::os::Bottle sectionp;
129 sectionp = config.findGroup("GENERAL");
130 if (sectionp.check("AxisMap"))
131 {
132 {
133 m_GENERAL_AxisMap.clear();
134 yarp::os::Bottle* tempBot = sectionp.find("AxisMap").asList();
135 if (tempBot)
136 {
137 std::string tempBots = tempBot->toString();
138 for (size_t i=0; i<tempBot->size(); i++)
139 {
140 m_GENERAL_AxisMap.push_back(tempBot->get(i).asInt64());
141 }
142 }
143 else
144 {
145 yCError(FakeMotionControlParamsCOMPONENT) <<"parameter 'GENERAL_AxisMap' is not a properly formatted bottle";
146 }
147 }
148 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'GENERAL::AxisMap' using value:" << m_GENERAL_AxisMap;
149 }
150 else
151 {
152 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'GENERAL::AxisMap' using DEFAULT value:" << m_GENERAL_AxisMap;
153 }
154 prop_check.unput("GENERAL::AxisMap");
155 }
156
157 //Parser of parameter GENERAL::AxisName
158 {
159 yarp::os::Bottle sectionp;
160 sectionp = config.findGroup("GENERAL");
161 if (sectionp.check("AxisName"))
162 {
163 {
164 m_GENERAL_AxisName.clear();
165 yarp::os::Bottle* tempBot = sectionp.find("AxisName").asList();
166 if (tempBot)
167 {
168 std::string tempBots = tempBot->toString();
169 for (size_t i=0; i<tempBot->size(); i++)
170 {
171 m_GENERAL_AxisName.push_back(tempBot->get(i).asString());
172 }
173 }
174 else
175 {
176 yCError(FakeMotionControlParamsCOMPONENT) <<"parameter 'GENERAL_AxisName' is not a properly formatted bottle";
177 }
178 }
179 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'GENERAL::AxisName' using value:" << m_GENERAL_AxisName;
180 }
181 else
182 {
183 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'GENERAL::AxisName' using DEFAULT value:" << m_GENERAL_AxisName;
184 }
185 prop_check.unput("GENERAL::AxisName");
186 }
187
188 //Parser of parameter GENERAL::AxisType
189 {
190 yarp::os::Bottle sectionp;
191 sectionp = config.findGroup("GENERAL");
192 if (sectionp.check("AxisType"))
193 {
194 {
195 m_GENERAL_AxisType.clear();
196 yarp::os::Bottle* tempBot = sectionp.find("AxisType").asList();
197 if (tempBot)
198 {
199 std::string tempBots = tempBot->toString();
200 for (size_t i=0; i<tempBot->size(); i++)
201 {
202 m_GENERAL_AxisType.push_back(tempBot->get(i).asString());
203 }
204 }
205 else
206 {
207 yCError(FakeMotionControlParamsCOMPONENT) <<"parameter 'GENERAL_AxisType' is not a properly formatted bottle";
208 }
209 }
210 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'GENERAL::AxisType' using value:" << m_GENERAL_AxisType;
211 }
212 else
213 {
214 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'GENERAL::AxisType' using DEFAULT value:" << m_GENERAL_AxisType;
215 }
216 prop_check.unput("GENERAL::AxisType");
217 }
218
219 //Parser of parameter GENERAL::ampsToSensor
220 {
221 yarp::os::Bottle sectionp;
222 sectionp = config.findGroup("GENERAL");
223 if (sectionp.check("ampsToSensor"))
224 {
225 {
227 yarp::os::Bottle* tempBot = sectionp.find("ampsToSensor").asList();
228 if (tempBot)
229 {
230 std::string tempBots = tempBot->toString();
231 for (size_t i=0; i<tempBot->size(); i++)
232 {
233 m_GENERAL_ampsToSensor.push_back(tempBot->get(i).asFloat64());
234 }
235 }
236 else
237 {
238 yCError(FakeMotionControlParamsCOMPONENT) <<"parameter 'GENERAL_ampsToSensor' is not a properly formatted bottle";
239 }
240 }
241 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'GENERAL::ampsToSensor' using value:" << m_GENERAL_ampsToSensor;
242 }
243 else
244 {
245 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'GENERAL::ampsToSensor' using DEFAULT value:" << m_GENERAL_ampsToSensor;
246 }
247 prop_check.unput("GENERAL::ampsToSensor");
248 }
249
250 //Parser of parameter GENERAL::fullscalePWM
251 {
252 yarp::os::Bottle sectionp;
253 sectionp = config.findGroup("GENERAL");
254 if (sectionp.check("fullscalePWM"))
255 {
256 {
258 yarp::os::Bottle* tempBot = sectionp.find("fullscalePWM").asList();
259 if (tempBot)
260 {
261 std::string tempBots = tempBot->toString();
262 for (size_t i=0; i<tempBot->size(); i++)
263 {
264 m_GENERAL_fullscalePWM.push_back(tempBot->get(i).asFloat64());
265 }
266 }
267 else
268 {
269 yCError(FakeMotionControlParamsCOMPONENT) <<"parameter 'GENERAL_fullscalePWM' is not a properly formatted bottle";
270 }
271 }
272 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'GENERAL::fullscalePWM' using value:" << m_GENERAL_fullscalePWM;
273 }
274 else
275 {
276 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'GENERAL::fullscalePWM' using DEFAULT value:" << m_GENERAL_fullscalePWM;
277 }
278 prop_check.unput("GENERAL::fullscalePWM");
279 }
280
281 //Parser of parameter GENERAL::Encoder
282 {
283 yarp::os::Bottle sectionp;
284 sectionp = config.findGroup("GENERAL");
285 if (sectionp.check("Encoder"))
286 {
287 {
288 m_GENERAL_Encoder.clear();
289 yarp::os::Bottle* tempBot = sectionp.find("Encoder").asList();
290 if (tempBot)
291 {
292 std::string tempBots = tempBot->toString();
293 for (size_t i=0; i<tempBot->size(); i++)
294 {
295 m_GENERAL_Encoder.push_back(tempBot->get(i).asInt64());
296 }
297 }
298 else
299 {
300 yCError(FakeMotionControlParamsCOMPONENT) <<"parameter 'GENERAL_Encoder' is not a properly formatted bottle";
301 }
302 }
303 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'GENERAL::Encoder' using value:" << m_GENERAL_Encoder;
304 }
305 else
306 {
307 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'GENERAL::Encoder' using DEFAULT value:" << m_GENERAL_Encoder;
308 }
309 prop_check.unput("GENERAL::Encoder");
310 }
311
312 //Parser of parameter LIMITS::Max
313 {
314 yarp::os::Bottle sectionp;
315 sectionp = config.findGroup("LIMITS");
316 if (sectionp.check("Max"))
317 {
318 {
319 m_LIMITS_Max.clear();
320 yarp::os::Bottle* tempBot = sectionp.find("Max").asList();
321 if (tempBot)
322 {
323 std::string tempBots = tempBot->toString();
324 for (size_t i=0; i<tempBot->size(); i++)
325 {
326 m_LIMITS_Max.push_back(tempBot->get(i).asFloat64());
327 }
328 }
329 else
330 {
331 yCError(FakeMotionControlParamsCOMPONENT) <<"parameter 'LIMITS_Max' is not a properly formatted bottle";
332 }
333 }
334 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'LIMITS::Max' using value:" << m_LIMITS_Max;
335 }
336 else
337 {
338 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'LIMITS::Max' using DEFAULT value:" << m_LIMITS_Max;
339 }
340 prop_check.unput("LIMITS::Max");
341 }
342
343 //Parser of parameter LIMITS::Min
344 {
345 yarp::os::Bottle sectionp;
346 sectionp = config.findGroup("LIMITS");
347 if (sectionp.check("Min"))
348 {
349 {
350 m_LIMITS_Min.clear();
351 yarp::os::Bottle* tempBot = sectionp.find("Min").asList();
352 if (tempBot)
353 {
354 std::string tempBots = tempBot->toString();
355 for (size_t i=0; i<tempBot->size(); i++)
356 {
357 m_LIMITS_Min.push_back(tempBot->get(i).asFloat64());
358 }
359 }
360 else
361 {
362 yCError(FakeMotionControlParamsCOMPONENT) <<"parameter 'LIMITS_Min' is not a properly formatted bottle";
363 }
364 }
365 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'LIMITS::Min' using value:" << m_LIMITS_Min;
366 }
367 else
368 {
369 yCInfo(FakeMotionControlParamsCOMPONENT) << "Parameter 'LIMITS::Min' using DEFAULT value:" << m_LIMITS_Min;
370 }
371 prop_check.unput("LIMITS::Min");
372 }
373
374 /*
375 //This code check if the user set some parameter which are not check by the parser
376 //If the parser is set in strict mode, this will generate an error
377 if (prop_check.size() > 0)
378 {
379 bool extra_params_found = false;
380 for (auto it=prop_check.begin(); it!=prop_check.end(); it++)
381 {
382 if (m_parser_is_strict)
383 {
384 yCError(FakeMotionControlParamsCOMPONENT) << "User asking for parameter: "<<it->name <<" which is unknown to this parser!";
385 extra_params_found = true;
386 }
387 else
388 {
389 yCWarning(FakeMotionControlParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!";
390 }
391 }
392
393 if (m_parser_is_strict && extra_params_found)
394 {
395 return false;
396 }
397 }
398 */
399 return true;
400}
401
402
404{
405 std::string doc;
406 doc = doc + std::string("\n=============================================\n");
407 doc = doc + std::string("This is the help for device: FakeMotionControl\n");
408 doc = doc + std::string("\n");
409 doc = doc + std::string("This is the list of the parameters accepted by the device:\n");
410 doc = doc + std::string("'GENERAL::Joints': Number of degrees of freedom\n");
411 doc = doc + std::string("'GENERAL::AxisMap': a list of reordered indices for the axes\n");
412 doc = doc + std::string("'GENERAL::AxisName': a list of strings representing the axes names\n");
413 doc = doc + std::string("'GENERAL::AxisType': a list of strings representing the axes type (revolute/prismatic)\n");
414 doc = doc + std::string("'GENERAL::ampsToSensor': a list of scales for the ampsToSensor conversion factors\n");
415 doc = doc + std::string("'GENERAL::fullscalePWM': a list of scales for the fullscalePWM conversion factors\n");
416 doc = doc + std::string("'GENERAL::Encoder': a list of scales for the encoders\n");
417 doc = doc + std::string("'LIMITS::Max': max encoder position\n");
418 doc = doc + std::string("'LIMITS::Min': min encoder position\n");
419 doc = doc + std::string("\n");
420 doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n");
421 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";
422 doc = doc + std::string("Using only mandatory params:\n");
423 doc = doc + " yarpdev --device fakeMotionControl\n";
424 doc = doc + std::string("=============================================\n\n"); return doc;
425}
#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:64
size_type size() const
Gets the number of elements in the bottle.
Definition Bottle.cpp:251
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition Bottle.cpp:246
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Definition Bottle.cpp:277
std::string toString() const override
Gives a human-readable textual representation of the bottle.
Definition Bottle.cpp:211
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 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::int64_t asInt64() const
Get 64-bit integer value.
Definition Value.cpp:210
virtual Bottle * asList() const
Get list value.
Definition Value.cpp:240
virtual std::string asString() const
Get string value.
Definition Value.cpp:234
#define yCInfo(component,...)
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)