iCub-main
serviceParser.h
Go to the documentation of this file.
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 #ifndef __serviceParser_h__
4 #define __serviceParser_h__
5 
6 #include <stdio.h>
7 #include <iostream>
8 #include <vector>
9 #include <list>
10 #include <string>
11 
12 #include <yarp/os/Searchable.h>
13 
14 #include "EoBoards.h"
15 #include "EoManagement.h"
16 #include "EoAnalogSensors.h"
17 #include "EoMotionControl.h"
18 
19 
20 
21 
22 #define SERVICE_PARSER_USE_MC
23 
24 typedef struct
25 {
26  eOmn_serv_parameter_t ethservice;
28  std::string nameOfMais;
30 
31 
32 typedef struct
33 {
34  eOmn_serv_parameter_t ethservice;
37  std::string nameOfStrain;
38  eObrd_cantype_t boardType;
40 
41 typedef struct
42 {
43  eOmn_serv_parameter_t ethservice;
46  std::string nameOfStrain;
47  eObrd_cantype_t boardType;
49  std::string frameName;
51 
52 typedef struct
53 {
54  eOmn_serv_parameter_t ethservice;
56  std::vector<eOas_inertial_descriptor_t> inertials;
57  std::vector<std::string> id;
59 
60 typedef struct
61 {
62  double accFactor;
63  double gyrFactor;
64  double magFactor;
65  double eulFactor;
67 
68 typedef struct
69 {
70  eOmn_serv_parameter_t ethservice;
72  std::vector<eOas_inertial3_descriptor_t> inertials; //TODO to remove because information is already stored!
73  std::vector<std::string> id;
74  std::vector<std::string> sensorName;
77 
78 
79 typedef struct
80 {
81  eOmn_serv_parameter_t ethservice;
83  std::vector<std::string> idList;
85 
86 
87 typedef struct
88 {
89  eOmn_serv_parameter_t ethservice;
91  std::vector<std::string> idList;
93 
94 
95 #if defined(SERVICE_PARSER_USE_MC)
96 typedef struct
97 {
98  eOmn_serv_parameter_t ethservice;
99  uint32_t id; // only for test: this param contains num of board
101 #endif
102 
104 {
105  eObrd_cantype_t type;
106  eObrd_protocolversion_t protocol;
107  eObrd_firmwareversion_t firmware;
109  void clear() { type = eobrd_cantype_none; protocol.major = 0; protocol.minor = 0; firmware.major = 0; firmware.minor = 0; firmware.build = 0; }
110 };
111 
113 {
114  eObrd_type_t type;
115  eObrd_protocolversion_t protocol;
116  eObrd_firmwareversion_t firmware;
117  servBoard_t() { type = eobrd_none; protocol.major = 0; protocol.minor = 0; firmware.major = 0; firmware.minor = 0; firmware.build = 0; }
118 };
119 
121 {
124  void clear() { canboard.clear(); canboard.type = eobrd_cantype_mtb; }
125 };
126 
127 
129 {
130  eoas_pos_TYPE_t type {eoas_pos_TYPE_none};
131  eoas_pos_ROT_t rotation {eoas_pos_ROT_zero};
132  float offset {0.0};
133  bool invertdirection {false};
134  void clear()
135  {
136  type = eoas_pos_TYPE_none; rotation = eoas_pos_ROT_zero; offset = 0.0; invertdirection = false;
137  }
138 };
139 
141 {
142  eObrd_portpos_t port {eobrd_portpos_none};
143  eObrd_connector_t connector {eobrd_conn_none};
145  void clear()
146  {
147  port = eobrd_portpos_none; connector = eobrd_conn_none; calibration.clear();
148  }
149 };
150 
152 {
153  std::string id {""};
154  eOas_sensor_t type {eoas_none};
155  eObrd_location_t location {{eobrd_place_none, 0}};
156  eObrd_type_t boardtype {eobrd_none};
157  std::string frameName {""};
158  std::string sensorName {""};
160  void clear()
161  {
162  id.clear(); type = eoas_none; location.any.place = eobrd_place_none;
163  boardtype = eobrd_none; frameName.clear(); sensorName.clear(); pos.clear();
164  }
165 };
166 
167 
168 typedef struct
169 {
170  std::vector<servCanBoard_t> canboards;
171  std::vector<servAnalogSensor_t> sensors;
173 
174 
175 typedef struct
176 {
177  uint16_t acquisitionrate;
178  std::vector<servAnalogSensor_t> enabledsensors;
180 
181 
182 typedef struct
183 {
184  eOmn_serv_type_t type;
188 
189 
190 typedef struct
191 {
194 
195 
196 
197 typedef struct
198 {
201 
202 
203 typedef struct
204 {
205  eOmn_serv_type_t type;
207  //servSKsettings_t settings;
209 
210 
211 #if defined(SERVICE_PARSER_USE_MC)
212 
213 // typedef struct
214 // {
215 // std::vector<double> matrixJ2M;
216 // std::vector<double> matrixM2J;
217 // std::vector<double> matrixE2J;
218 // } servMC_controller_t;
219 
220 
221 
222 typedef struct
223 {
224  eOmc_actuator_t type;
225  eOmc_actuator_descriptor_t desc;
227 
228 
229 
230 typedef struct
231 {
232  eOmc_encoder_descriptor_t desc;
233  int32_t resolution;
234  double tolerance;
236 
237 
238 typedef struct
239 {
240 
242  eObrd_ethtype_t ethboardtype;
243  std::vector<servCanBoard_t> canboards;
244 
245  eObrd_canlocation_t maislocation;
246  std::vector<eObrd_canlocation_t> psclocations;
247  std::vector<eObrd_canlocation_t> poslocations;
248 
249  eOmc_mc4shifts_t mc4shifts;
250  std::vector<eOmc_mc4broadcast_t> mc4broadcasts;
251  std::vector<eObrd_canlocation_t> mc4joints;
252 
253  //servMC_controller_t controller;
254 
255  std::vector<servMC_actuator_t> actuators;
256  std::vector<servMC_encoder_t> encoder1s;
257  std::vector<servMC_encoder_t> encoder2s;
258 
259  //std::vector<int> joint2set;
260  //int numofjointsets;
261  //std::vector<eOmc_jointset_configuration_t> jointset_cfgs;
263 
264 
265 typedef struct
266 {
267  uint16_t tbd1;
268  std::vector<int> tbd2;
270 
271 
272 
273 typedef struct
274 {
275  eOmn_serv_type_t type;
276  eOmn_serv_diagn_cfg_t diagconfig;
280 
281 #endif
282 
283 // todo: add definition of static const array of strings containing the names of boards, sensors, etc.
284 
285 
286 // -- class ServiceParser
287 
289 {
290 public:
291 
292  ServiceParser();
294 
295 public:
296 
297  bool parseService(yarp::os::Searchable &config, servConfigMais_t& maisconfig);
298  bool parseService(yarp::os::Searchable &config, servConfigStrain_t &strainconfig);
299  bool parseService(yarp::os::Searchable &config, servConfigFTsensor_t &ftconfig);
300  bool parseService(yarp::os::Searchable &config, servConfigInertials_t &inertialsconfig);
301  bool parseService(yarp::os::Searchable &config, servConfigImu_t &imuconfig);
302  bool parseService(yarp::os::Searchable &config, servConfigSkin_t &skinconfig);
303  bool parseService(yarp::os::Searchable &config, servConfigPSC_t &pscconfig);
304  bool parseService(yarp::os::Searchable &config, servConfigPOS_t &pscconfig);
305 #if defined(SERVICE_PARSER_USE_MC)
306  bool parseService(yarp::os::Searchable &config, servConfigMC_t &mcconfig);
307  bool parseService2(yarp::os::Searchable &config, servConfigMC_t &mcconfig); // the fixed one.
308  //bool convert(std::string const &fromstring, eOmc_ctrlboard_t &controllerboard, bool &formaterror);
309  //bool convert(Bottle &bottle, std::vector<double> &matrix, bool &formaterror, int targetsize);
310  bool convert(std::string const &fromstring, eOmc_actuator_t &toactuatortype, bool &formaterror);
311  bool convert(std::string const &fromstring, eOmc_position_t &toposition, bool &formaterror);
312  bool convert(std::string const &fromstring, eOmc_encoder_t &toencodertype, bool &formaterror);
313 
314  bool parse_connector(const std::string &fromstring, eObrd_connector_t &toconnector, bool &formaterror);
315  bool parse_mais(std::string const &fromstring, eObrd_portmais_t &pmais, bool &formaterror);
316 
317  bool parse_port_conn(std::string const &fromstring, eObrd_type_t const board, uint8_t &toport, bool &formaterror);
318  bool parse_port_mais(std::string const &fromstring, uint8_t &toport, bool &formaterror);
319 
320  bool parse_actuator_port(std::string const &fromstring, eObrd_ethtype_t const ethboard, eOmc_actuator_t const type, eOmc_actuator_descriptor_t &todes, bool &formaterror);
321  bool parse_encoder_port(std::string const &fromstring, eObrd_ethtype_t const ethboard, eOmc_encoder_t type, uint8_t &toport, bool &formaterror);
322 
323  bool parse_psc(std::string const &fromstring, eObrd_portpsc_t &ppsc, bool &formaterror);
324  bool parse_port_psc(std::string const &fromstring, uint8_t &toport, bool &formaterror);
325 
326  bool parse_POS_port(std::string const &fromstring, eObrd_portpos_t &ppos, bool &formaterror);
327  bool parse_port_pos(std::string const &fromstring, uint8_t &toport, bool &formaterror);
328 
329  bool parse_POS_connector(std::string const &fromstring, const eObrd_type_t brd, eObrd_connector_t &conn, bool &formaterror);
330  bool parse_POS_CALIB_rotation(std::string const &fromstring, eoas_pos_ROT_t &rot, bool &formaterror);
331  bool parse_POS_CALIB_type(std::string const &fromstring, eoas_pos_TYPE_t &type, bool &formaterror);
332 
333 #endif
334 
335  bool convert(std::string const &fromstring, eOmn_serv_type_t &toservicetype, bool &formaterror);
336  bool convert(std::string const &fromstring, eOmn_serv_diagn_mode_t &todiagnmode, bool &formaterror);
337  bool convert(std::string const &fromstring, eObrd_type_t& tobrdtype, bool& formaterror);
338  bool convert(std::string const &fromstring, eObrd_cantype_t &tobrdcantype, bool &formaterror);
339  bool convert(std::string const &fromstring, eObrd_ethtype_t& tobrdethtype, bool& formaterror);
340  bool convert(std::string const &fromstring, bool &tobool, bool &formaterror);
341  bool convert(const int number, uint8_t &tou8, bool &formaterror);
342  bool convert(const int number, uint16_t &tou16, bool &formaterror);
343  bool convert(std::string const &fromstring, eOas_sensor_t &tosensortype, bool &formaterror);
344  bool convert(std::string const &fromstring, std::string &str, bool &formaterror);
345  bool convert(std::string const &fromstring, const uint8_t strsize, char *str, bool &formaterror);
346  bool convert(std::string const &fromstring, eObrd_location_t &location, bool &formaterror);
347 
348 
349  bool convert(eObrd_location_t const &loc, char *str, int len);
350  bool convert(eObrd_canlocation_t const &canloc, char *str, int len);
351 
352  bool convert(eObrd_protocolversion_t const &prot, char *str, int len);
353  bool convert(eObrd_firmwareversion_t const &firm, char *str, int len);
354 
355  bool convert(std::string const &fromstring, eOmc_pidoutputtype_t& pidoutputtype, bool& formaterror);
356  bool convert(std::string const &fromstring, eOmc_jsetconstraint_t &jsetconstraint, bool& formaterror);
359  bool parse_debugEmbBoardsNotConnected(yarp::os::Searchable &config, bool &embBoardsConnected);
360  public:
361 
364 
366  eOmn_serv_config_data_sk_skin_t tmp;
367 
368 #if defined(SERVICE_PARSER_USE_MC)
370 #endif
371 
372 private:
373 
374  bool check_analog(yarp::os::Searchable &config, eOmn_serv_type_t type);
375 
376  bool check_skin(yarp::os::Searchable &config);
377 
378  bool check_motion(yarp::os::Searchable &config);
379 
380  int getnumofjointsets(void);
381 
382  bool copyjomocouplingInfo(eOmc_4jomo_coupling_t *jc_dest);
383 
384 
385  // suggestion: split check_motion() in sub-methods which parse the groups ...
386 };
387 
388 #endif
389 
bool parseService2(yarp::os::Searchable &config, servConfigMC_t &mcconfig)
bool parse_encoder_port(std::string const &fromstring, eObrd_ethtype_t const ethboard, eOmc_encoder_t type, uint8_t &toport, bool &formaterror)
bool parse_port_conn(std::string const &fromstring, eObrd_type_t const board, uint8_t &toport, bool &formaterror)
bool parseService(yarp::os::Searchable &config, servConfigInertials_t &inertialsconfig)
servASstrainSettings_t as_strain_settings
bool parseService(yarp::os::Searchable &config, servConfigFTsensor_t &ftconfig)
bool parse_actuator_port(std::string const &fromstring, eObrd_ethtype_t const ethboard, eOmc_actuator_t const type, eOmc_actuator_descriptor_t &todes, bool &formaterror)
bool parse_POS_CALIB_rotation(std::string const &fromstring, eoas_pos_ROT_t &rot, bool &formaterror)
bool convert(std::string const &fromstring, eOmc_actuator_t &toactuatortype, bool &formaterror)
bool convert(std::string const &fromstring, eOmc_encoder_t &toencodertype, bool &formaterror)
bool parseService(yarp::os::Searchable &config, servConfigPOS_t &pscconfig)
bool convert(std::string const &fromstring, eOmc_position_t &toposition, bool &formaterror)
bool parse_mais(std::string const &fromstring, eObrd_portmais_t &pmais, bool &formaterror)
servMCcollector_t mc_service
eOmn_serv_config_data_sk_skin_t tmp
servSKcollector_t sk_service
bool parse_port_psc(std::string const &fromstring, uint8_t &toport, bool &formaterror)
bool parse_POS_CALIB_type(std::string const &fromstring, eoas_pos_TYPE_t &type, bool &formaterror)
bool parseService(yarp::os::Searchable &config, servConfigMais_t &maisconfig)
bool parse_port_pos(std::string const &fromstring, uint8_t &toport, bool &formaterror)
bool parseService(yarp::os::Searchable &config, servConfigPSC_t &pscconfig)
bool parse_debugEmbBoardsNotConnected(yarp::os::Searchable &config, bool &embBoardsConnected)
bool parse_POS_connector(std::string const &fromstring, const eObrd_type_t brd, eObrd_connector_t &conn, bool &formaterror)
bool parse_POS_port(std::string const &fromstring, eObrd_portpos_t &ppos, bool &formaterror)
bool parseService(yarp::os::Searchable &config, servConfigSkin_t &skinconfig)
servMC_encoder_t * getEncoderAtMotor(int index)
bool parse_connector(const std::string &fromstring, eObrd_connector_t &toconnector, bool &formaterror)
bool parseService(yarp::os::Searchable &config, servConfigMC_t &mcconfig)
bool parseService(yarp::os::Searchable &config, servConfigImu_t &imuconfig)
servMC_encoder_t * getEncoderAtJoint(int index)
bool parse_psc(std::string const &fromstring, eObrd_portpsc_t &ppsc, bool &formaterror)
servAScollector_t as_service
bool parseService(yarp::os::Searchable &config, servConfigStrain_t &strainconfig)
bool parse_port_mais(std::string const &fromstring, uint8_t &toport, bool &formaterror)
uint8_t board
eOmn_serv_type_t type
servASsettings_t settings
servASproperties_t properties
std::vector< servAnalogSensor_t > sensors
std::vector< servCanBoard_t > canboards
std::vector< servAnalogSensor_t > enabledsensors
uint16_t acquisitionrate
servAnalogPOScalibration_t calibration
eObrd_connector_t connector
eObrd_portpos_t port
servAnalogPOSspecific_t pos
std::string frameName
eObrd_type_t boardtype
std::string sensorName
eObrd_location_t location
eOas_sensor_t type
eObrd_firmwareversion_t firmware
eObrd_type_t type
eObrd_protocolversion_t protocol
eObrd_cantype_t type
eObrd_protocolversion_t protocol
eObrd_firmwareversion_t firmware
eObrd_cantype_t boardType
Definition: serviceParser.h:47
std::string nameOfStrain
Definition: serviceParser.h:46
std::string frameName
Definition: serviceParser.h:49
eOmn_serv_parameter_t ethservice
Definition: serviceParser.h:43
eOmn_serv_parameter_t ethservice
Definition: serviceParser.h:70
std::vector< eOas_inertial3_descriptor_t > inertials
Definition: serviceParser.h:72
imuConvFactors_t convFactors
Definition: serviceParser.h:75
std::vector< std::string > id
Definition: serviceParser.h:73
std::vector< std::string > sensorName
Definition: serviceParser.h:74
eOmn_serv_parameter_t ethservice
Definition: serviceParser.h:54
std::vector< eOas_inertial_descriptor_t > inertials
Definition: serviceParser.h:56
std::vector< std::string > id
Definition: serviceParser.h:57
eOmn_serv_parameter_t ethservice
Definition: serviceParser.h:98
eOmn_serv_parameter_t ethservice
Definition: serviceParser.h:26
std::string nameOfMais
Definition: serviceParser.h:28
std::vector< std::string > idList
Definition: serviceParser.h:91
eOmn_serv_parameter_t ethservice
Definition: serviceParser.h:89
std::vector< std::string > idList
Definition: serviceParser.h:83
eOmn_serv_parameter_t ethservice
Definition: serviceParser.h:81
servCanBoard_t canboard
eOmn_serv_parameter_t ethservice
Definition: serviceParser.h:34
std::string nameOfStrain
Definition: serviceParser.h:37
eObrd_cantype_t boardType
Definition: serviceParser.h:38
eOmc_actuator_descriptor_t desc
eOmc_actuator_t type
eOmc_encoder_descriptor_t desc
servMCproperties_t properties
eOmn_serv_diagn_cfg_t diagconfig
servMCsettings_t settings
eOmn_serv_type_t type
std::vector< eOmc_mc4broadcast_t > mc4broadcasts
eOmc_mc4shifts_t mc4shifts
std::vector< eObrd_canlocation_t > poslocations
eObrd_canlocation_t maislocation
std::vector< servMC_actuator_t > actuators
std::vector< servMC_encoder_t > encoder2s
eObrd_ethtype_t ethboardtype
std::vector< eObrd_canlocation_t > mc4joints
std::vector< servMC_encoder_t > encoder1s
std::vector< eObrd_canlocation_t > psclocations
std::vector< servCanBoard_t > canboards
std::vector< int > tbd2
eOmn_serv_type_t type
servSKproperties_t properties
servCanBoard_t canboard