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  double accFactor;
55  double gyrFactor;
56  double magFactor;
57  double eulFactor;
59 
60 typedef struct
61 {
62  eOmn_serv_parameter_t ethservice;
64  std::vector<eOas_inertial3_descriptor_t> inertials; //TODO to remove because information is already stored!
65  std::vector<std::string> id;
66  std::vector<std::string> sensorName;
69 
70 
71 typedef struct
72 {
73  eOmn_serv_parameter_t ethservice;
75  std::vector<std::string> idList;
77 
78 
79 typedef struct
80 {
81  eOmn_serv_parameter_t ethservice;
83  std::vector<std::string> idList;
85 
86 
87 #if defined(SERVICE_PARSER_USE_MC)
88 typedef struct
89 {
90  eOmn_serv_parameter_t ethservice;
91  uint32_t id; // only for test: this param contains num of board
93 #endif
94 
96 {
97  eObrd_cantype_t type;
98  eObrd_protocolversion_t protocol;
99  eObrd_firmwareversion_t firmware;
101  void clear() { type = eobrd_cantype_none; protocol.major = 0; protocol.minor = 0; firmware.major = 0; firmware.minor = 0; firmware.build = 0; }
102 };
103 
105 {
106  eObrd_type_t type;
107  eObrd_protocolversion_t protocol;
108  eObrd_firmwareversion_t firmware;
109  servBoard_t() { type = eobrd_none; protocol.major = 0; protocol.minor = 0; firmware.major = 0; firmware.minor = 0; firmware.build = 0; }
110 };
111 
113 {
116  void clear() { canboard.clear(); canboard.type = eobrd_cantype_mtb; }
117 };
118 
119 
121 {
122  eoas_pos_TYPE_t type {eoas_pos_TYPE_none};
123  eoas_pos_ROT_t rotation {eoas_pos_ROT_zero};
124  float offset {0.0};
125  bool invertdirection {false};
126  void clear()
127  {
128  type = eoas_pos_TYPE_none; rotation = eoas_pos_ROT_zero; offset = 0.0; invertdirection = false;
129  }
130 };
131 
133 {
134  eObrd_portpos_t port {eobrd_portpos_none};
135  eObrd_connector_t connector {eobrd_conn_none};
137  void clear()
138  {
139  port = eobrd_portpos_none; connector = eobrd_conn_none; calibration.clear();
140  }
141 };
142 
144 {
145  std::string id {""};
146  eOas_sensor_t type {eoas_none};
147  eObrd_location_t location {{eobrd_place_none, 0}};
148  eObrd_type_t boardtype {eobrd_none};
149  std::string frameName {""};
150  std::string sensorName {""};
152  void clear()
153  {
154  id.clear(); type = eoas_none; location.any.place = eobrd_place_none;
155  boardtype = eobrd_none; frameName.clear(); sensorName.clear(); pos.clear();
156  }
157 };
158 
159 
160 typedef struct
161 {
162  std::vector<servCanBoard_t> canboards;
163  std::vector<servAnalogSensor_t> sensors;
165 
166 
167 typedef struct
168 {
169  uint16_t acquisitionrate;
170  std::vector<servAnalogSensor_t> enabledsensors;
172 
173 
174 typedef struct
175 {
176  eOmn_serv_type_t type;
180 
181 
182 typedef struct
183 {
186 
187 
188 
189 typedef struct
190 {
193 
194 
195 typedef struct
196 {
197  eOmn_serv_type_t type;
199  //servSKsettings_t settings;
201 
202 
203 #if defined(SERVICE_PARSER_USE_MC)
204 
205 // typedef struct
206 // {
207 // std::vector<double> matrixJ2M;
208 // std::vector<double> matrixM2J;
209 // std::vector<double> matrixE2J;
210 // } servMC_controller_t;
211 
212 
213 
214 typedef struct
215 {
216  eOmc_actuator_t type;
217  eOmc_actuator_descriptor_t desc;
219 
220 
221 
222 typedef struct
223 {
224  eOmc_encoder_descriptor_t desc;
225  int32_t resolution;
226  double tolerance;
228 
229 
230 typedef struct
231 {
232 
234  eObrd_ethtype_t ethboardtype;
235  std::vector<servCanBoard_t> canboards;
236 
237  eObrd_canlocation_t maislocation;
238  std::vector<eObrd_canlocation_t> psclocations;
239  std::vector<eObrd_canlocation_t> poslocations;
240 
241  eOmc_mc4shifts_t mc4shifts;
242  std::vector<eOmc_mc4broadcast_t> mc4broadcasts;
243  std::vector<eObrd_canlocation_t> mc4joints;
244 
245  //servMC_controller_t controller;
246 
247  std::vector<servMC_actuator_t> actuators;
248  std::vector<servMC_encoder_t> encoder1s;
249  std::vector<servMC_encoder_t> encoder2s;
250 
251  //std::vector<int> joint2set;
252  //int numofjointsets;
253  //std::vector<eOmc_jointset_configuration_t> jointset_cfgs;
255 
256 
257 typedef struct
258 {
259  uint16_t tbd1;
260  std::vector<int> tbd2;
262 
263 
264 
265 typedef struct
266 {
267  eOmn_serv_type_t type;
268  eOmn_serv_diagn_cfg_t diagconfig;
272 
273 #endif
274 
275 // todo: add definition of static const array of strings containing the names of boards, sensors, etc.
276 
277 
278 // -- class ServiceParser
279 
281 {
282 public:
283 
284  ServiceParser();
286 
287 public:
288 
289  bool parseService(yarp::os::Searchable &config, servConfigMais_t& maisconfig);
290  bool parseService(yarp::os::Searchable &config, servConfigStrain_t &strainconfig);
291  bool parseService(yarp::os::Searchable &config, servConfigFTsensor_t &ftconfig);
292  bool parseService(yarp::os::Searchable &config, servConfigImu_t &imuconfig);
293  bool parseService(yarp::os::Searchable &config, servConfigSkin_t &skinconfig);
294  bool parseService(yarp::os::Searchable &config, servConfigPSC_t &pscconfig);
295  bool parseService(yarp::os::Searchable &config, servConfigPOS_t &pscconfig);
296 #if defined(SERVICE_PARSER_USE_MC)
297  bool parseService(yarp::os::Searchable &config, servConfigMC_t &mcconfig);
298  bool parseService2(yarp::os::Searchable &config, servConfigMC_t &mcconfig); // the fixed one.
299  //bool convert(std::string const &fromstring, eOmc_ctrlboard_t &controllerboard, bool &formaterror);
300  //bool convert(Bottle &bottle, std::vector<double> &matrix, bool &formaterror, int targetsize);
301  bool convert(std::string const &fromstring, eOmc_actuator_t &toactuatortype, bool &formaterror);
302  bool convert(std::string const &fromstring, eOmc_position_t &toposition, bool &formaterror);
303  bool convert(std::string const &fromstring, eOmc_encoder_t &toencodertype, bool &formaterror);
304 
305  bool parse_connector(const std::string &fromstring, eObrd_connector_t &toconnector, bool &formaterror);
306  bool parse_mais(std::string const &fromstring, eObrd_portmais_t &pmais, bool &formaterror);
307 
308  bool parse_port_conn(std::string const &fromstring, eObrd_type_t const board, uint8_t &toport, bool &formaterror);
309  bool parse_port_mais(std::string const &fromstring, uint8_t &toport, bool &formaterror);
310 
311  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);
312  bool parse_encoder_port(std::string const &fromstring, eObrd_ethtype_t const ethboard, eOmc_encoder_t type, uint8_t &toport, bool &formaterror);
313 
314  bool parse_psc(std::string const &fromstring, eObrd_portpsc_t &ppsc, bool &formaterror);
315  bool parse_port_psc(std::string const &fromstring, uint8_t &toport, bool &formaterror);
316 
317  bool parse_POS_port(std::string const &fromstring, eObrd_portpos_t &ppos, bool &formaterror);
318  bool parse_port_pos(std::string const &fromstring, uint8_t &toport, bool &formaterror);
319 
320  bool parse_POS_connector(std::string const &fromstring, const eObrd_type_t brd, eObrd_connector_t &conn, bool &formaterror);
321  bool parse_POS_CALIB_rotation(std::string const &fromstring, eoas_pos_ROT_t &rot, bool &formaterror);
322  bool parse_POS_CALIB_type(std::string const &fromstring, eoas_pos_TYPE_t &type, bool &formaterror);
323 
324 #endif
325 
326  bool convert(std::string const &fromstring, eOmn_serv_type_t &toservicetype, bool &formaterror);
327  bool convert(std::string const &fromstring, eOmn_serv_diagn_mode_t &todiagnmode, bool &formaterror);
328  bool convert(std::string const &fromstring, eObrd_type_t& tobrdtype, bool& formaterror);
329  bool convert(std::string const &fromstring, eObrd_cantype_t &tobrdcantype, bool &formaterror);
330  bool convert(std::string const &fromstring, eObrd_ethtype_t& tobrdethtype, bool& formaterror);
331  bool convert(std::string const &fromstring, bool &tobool, bool &formaterror);
332  bool convert(const int number, uint8_t &tou8, bool &formaterror);
333  bool convert(const int number, uint16_t &tou16, bool &formaterror);
334  bool convert(std::string const &fromstring, eOas_sensor_t &tosensortype, bool &formaterror);
335  bool convert(std::string const &fromstring, std::string &str, bool &formaterror);
336  bool convert(std::string const &fromstring, const uint8_t strsize, char *str, bool &formaterror);
337  bool convert(std::string const &fromstring, eObrd_location_t &location, bool &formaterror);
338 
339 
340  bool convert(eObrd_location_t const &loc, char *str, int len);
341  bool convert(eObrd_canlocation_t const &canloc, char *str, int len);
342 
343  bool convert(eObrd_protocolversion_t const &prot, char *str, int len);
344  bool convert(eObrd_firmwareversion_t const &firm, char *str, int len);
345 
346  bool convert(std::string const &fromstring, eOmc_pidoutputtype_t& pidoutputtype, bool& formaterror);
347  bool convert(std::string const &fromstring, eOmc_jsetconstraint_t &jsetconstraint, bool& formaterror);
350  bool parse_debugEmbBoardsNotConnected(yarp::os::Searchable &config, bool &embBoardsConnected);
351  public:
352 
355 
357  eOmn_serv_config_data_sk_skin_t tmp;
358 
359 #if defined(SERVICE_PARSER_USE_MC)
361 #endif
362 
363 private:
364 
365  bool check_analog(yarp::os::Searchable &config, eOmn_serv_type_t type);
366 
367  bool check_skin(yarp::os::Searchable &config);
368 
369  bool check_motion(yarp::os::Searchable &config);
370 
371  int getnumofjointsets(void);
372 
373  bool copyjomocouplingInfo(eOmc_4jomo_coupling_t *jc_dest);
374 
375 
376  // suggestion: split check_motion() in sub-methods which parse the groups ...
377 };
378 
379 #endif
380 
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)
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
Definition: serviceParser.h:97
eObrd_protocolversion_t protocol
Definition: serviceParser.h:98
eObrd_firmwareversion_t firmware
Definition: serviceParser.h:99
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:62
std::vector< eOas_inertial3_descriptor_t > inertials
Definition: serviceParser.h:64
imuConvFactors_t convFactors
Definition: serviceParser.h:67
std::vector< std::string > id
Definition: serviceParser.h:65
std::vector< std::string > sensorName
Definition: serviceParser.h:66
eOmn_serv_parameter_t ethservice
Definition: serviceParser.h:90
eOmn_serv_parameter_t ethservice
Definition: serviceParser.h:26
std::string nameOfMais
Definition: serviceParser.h:28
std::vector< std::string > idList
Definition: serviceParser.h:83
eOmn_serv_parameter_t ethservice
Definition: serviceParser.h:81
std::vector< std::string > idList
Definition: serviceParser.h:75
eOmn_serv_parameter_t ethservice
Definition: serviceParser.h:73
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