YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
BoschIMU_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 12:31:36 2025
12
13
15#include <yarp/os/LogStream.h>
16#include <yarp/os/Value.h>
17
18namespace {
19 YARP_LOG_COMPONENT(BoschIMUParamsCOMPONENT, "yarp.device.BoschIMU")
20}
21
22
26
27
28std::vector<std::string> BoschIMU_ParamsParser::getListOfParams() const
29{
30 std::vector<std::string> params;
31 params.push_back("comport");
32 params.push_back("baudrate");
33 params.push_back("i2c");
34 params.push_back("period");
35 params.push_back("sensor_name");
36 params.push_back("frame_name");
37 params.push_back("channels");
38 return params;
39}
40
41
42bool BoschIMU_ParamsParser::getParamValue(const std::string& paramName, std::string& paramValue) const
43{
44 if (paramName =="comport")
45 {
46 paramValue = m_comport;
47 return true;
48 }
49 if (paramName =="baudrate")
50 {
51 paramValue = std::to_string(m_baudrate);
52 return true;
53 }
54 if (paramName =="i2c")
55 {
56 paramValue = m_i2c;
57 return true;
58 }
59 if (paramName =="period")
60 {
61 paramValue = std::to_string(m_period);
62 return true;
63 }
64 if (paramName =="sensor_name")
65 {
66 paramValue = m_sensor_name;
67 return true;
68 }
69 if (paramName =="frame_name")
70 {
71 paramValue = m_frame_name;
72 return true;
73 }
74 if (paramName =="channels")
75 {
76 paramValue = std::to_string(m_channels);
77 return true;
78 }
79
80 yError() <<"parameter '" << paramName << "' was not found";
81 return false;
82
83}
84
85
87{
88 //This is a sub-optimal solution.
89 //Ideally getConfiguration() should return all parameters but it is currently
90 //returning only user provided parameters (excluding default values)
91 //This behaviour will be fixed in the near future.
92 std::string s_cfg = m_provided_configuration;
93 return s_cfg;
94}
95
97{
98 //Check for --help option
99 if (config.check("help"))
100 {
101 yCInfo(BoschIMUParamsCOMPONENT) << getDocumentationOfDeviceParams();
102 }
103
106 //Parser of parameter comport
107 {
108 if (config.check("comport"))
109 {
110 m_comport = config.find("comport").asString();
111 yCInfo(BoschIMUParamsCOMPONENT) << "Parameter 'comport' using value:" << m_comport;
112 }
113 else
114 {
115 yCInfo(BoschIMUParamsCOMPONENT) << "Parameter 'comport' using DEFAULT value:" << m_comport;
116 }
117 prop_check.unput("comport");
118 }
119
120 //Parser of parameter baudrate
121 {
122 if (config.check("baudrate"))
123 {
124 m_baudrate = config.find("baudrate").asInt64();
125 yCInfo(BoschIMUParamsCOMPONENT) << "Parameter 'baudrate' using value:" << m_baudrate;
126 }
127 else
128 {
129 yCInfo(BoschIMUParamsCOMPONENT) << "Parameter 'baudrate' using DEFAULT value:" << m_baudrate;
130 }
131 prop_check.unput("baudrate");
132 }
133
134 //Parser of parameter i2c
135 {
136 if (config.check("i2c"))
137 {
138 m_i2c = config.find("i2c").asString();
139 yCInfo(BoschIMUParamsCOMPONENT) << "Parameter 'i2c' using value:" << m_i2c;
140 }
141 else
142 {
143 yCInfo(BoschIMUParamsCOMPONENT) << "Parameter 'i2c' using DEFAULT value:" << m_i2c;
144 }
145 prop_check.unput("i2c");
146 }
147
148 //Parser of parameter period
149 {
150 if (config.check("period"))
151 {
152 m_period = config.find("period").asInt64();
153 yCInfo(BoschIMUParamsCOMPONENT) << "Parameter 'period' using value:" << m_period;
154 }
155 else
156 {
157 yCInfo(BoschIMUParamsCOMPONENT) << "Parameter 'period' using DEFAULT value:" << m_period;
158 }
159 prop_check.unput("period");
160 }
161
162 //Parser of parameter sensor_name
163 {
164 if (config.check("sensor_name"))
165 {
166 m_sensor_name = config.find("sensor_name").asString();
167 yCInfo(BoschIMUParamsCOMPONENT) << "Parameter 'sensor_name' using value:" << m_sensor_name;
168 }
169 else
170 {
171 yCInfo(BoschIMUParamsCOMPONENT) << "Parameter 'sensor_name' using DEFAULT value:" << m_sensor_name;
172 }
173 prop_check.unput("sensor_name");
174 }
175
176 //Parser of parameter frame_name
177 {
178 if (config.check("frame_name"))
179 {
180 m_frame_name = config.find("frame_name").asString();
181 yCInfo(BoschIMUParamsCOMPONENT) << "Parameter 'frame_name' using value:" << m_frame_name;
182 }
183 else
184 {
185 yCInfo(BoschIMUParamsCOMPONENT) << "Parameter 'frame_name' using DEFAULT value:" << m_frame_name;
186 }
187 prop_check.unput("frame_name");
188 }
189
190 //Parser of parameter channels
191 {
192 if (config.check("channels"))
193 {
194 m_channels = config.find("channels").asInt64();
195 yCInfo(BoschIMUParamsCOMPONENT) << "Parameter 'channels' using value:" << m_channels;
196 }
197 else
198 {
199 yCInfo(BoschIMUParamsCOMPONENT) << "Parameter 'channels' using DEFAULT value:" << m_channels;
200 }
201 prop_check.unput("channels");
202 }
203
204 /*
205 //This code check if the user set some parameter which are not check by the parser
206 //If the parser is set in strict mode, this will generate an error
207 if (prop_check.size() > 0)
208 {
209 bool extra_params_found = false;
210 for (auto it=prop_check.begin(); it!=prop_check.end(); it++)
211 {
212 if (m_parser_is_strict)
213 {
214 yCError(BoschIMUParamsCOMPONENT) << "User asking for parameter: "<<it->name <<" which is unknown to this parser!";
215 extra_params_found = true;
216 }
217 else
218 {
219 yCWarning(BoschIMUParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!";
220 }
221 }
222
223 if (m_parser_is_strict && extra_params_found)
224 {
225 return false;
226 }
227 }
228 */
229 return true;
230}
231
232
234{
235 std::string doc;
236 doc = doc + std::string("\n=============================================\n");
237 doc = doc + std::string("This is the help for device: BoschIMU\n");
238 doc = doc + std::string("\n");
239 doc = doc + std::string("This is the list of the parameters accepted by the device:\n");
240 doc = doc + std::string("'comport': full name of device file\n");
241 doc = doc + std::string("'baudrate': baudrate setting of COM port\n");
242 doc = doc + std::string("'i2c': full name of device file\n");
243 doc = doc + std::string("'period': period of the thread\n");
244 doc = doc + std::string("'sensor_name': full name of the device\n");
245 doc = doc + std::string("'frame_name': full name of the sensor frame in which the measurements are expressed\n");
246 doc = doc + std::string("'channels': number of channels in the output port. Default 12. If 16, also includes quaternion data\n");
247 doc = doc + std::string("\n");
248 doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n");
249 doc = doc + " yarpdev --device imuBosch_BNO055 --comport <optional_value> --baudrate 115200 --i2c <optional_value> --period 10 --sensor_name sensor_imu_bosch_bno055 --frame_name sensor_imu_bosch_bno055 --channels 12\n";
250 doc = doc + std::string("Using only mandatory params:\n");
251 doc = doc + " yarpdev --device imuBosch_BNO055\n";
252 doc = doc + std::string("=============================================\n\n"); return doc;
253}
#define yError(...)
Definition Log.h:361
std::string getDocumentationOfDeviceParams() const override
Get the documentation of the DeviceDriver's parameters.
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
std::string getConfiguration() const override
Return the configuration of the device.
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.
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.
#define yCInfo(component,...)
#define YARP_LOG_COMPONENT(name,...)