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;
218  eOmc_adv_actuator_descriptor_t advdescr;
220 
221 
222 
223 typedef struct
224 {
225  eOmc_encoder_descriptor_t desc;
226  int32_t resolution;
227  double tolerance;
229 
230 
231 typedef struct
232 {
233 
235  eObrd_ethtype_t ethboardtype;
236  std::vector<servCanBoard_t> canboards;
237 
238  eObrd_canlocation_t maislocation;
239  std::vector<eObrd_canlocation_t> psclocations;
240  std::vector<eObrd_canlocation_t> poslocations;
241 
242  eOmc_mc4shifts_t mc4shifts;
243  std::vector<eOmc_mc4broadcast_t> mc4broadcasts;
244  std::vector<eObrd_canlocation_t> mc4joints;
245 
246  //servMC_controller_t controller;
247 
248  std::vector<servMC_actuator_t> actuators;
249  std::vector<servMC_encoder_t> encoder1s;
250  std::vector<servMC_encoder_t> encoder2s;
251 
252  //std::vector<int> joint2set;
253  //int numofjointsets;
254  //std::vector<eOmc_jointset_configuration_t> jointset_cfgs;
256 
257 
258 typedef struct
259 {
260  uint16_t tbd1;
261  std::vector<int> tbd2;
263 
264 
265 
266 typedef struct
267 {
268  eOmn_serv_type_t type;
269  eOmn_serv_diagn_cfg_t diagconfig;
273 
274 #endif
275 
276 // todo: add definition of static const array of strings containing the names of boards, sensors, etc.
277 
278 
279 // -- class ServiceParser
280 
282 {
283 public:
284 
285  ServiceParser();
287 
288 public:
289 
290  bool parseService(yarp::os::Searchable &config, servConfigMais_t& maisconfig);
291  bool parseService(yarp::os::Searchable &config, servConfigStrain_t &strainconfig);
292  bool parseService(yarp::os::Searchable &config, servConfigFTsensor_t &ftconfig);
293  bool parseService(yarp::os::Searchable &config, servConfigImu_t &imuconfig);
294  bool parseService(yarp::os::Searchable &config, servConfigSkin_t &skinconfig);
295  bool parseService(yarp::os::Searchable &config, servConfigPSC_t &pscconfig);
296  bool parseService(yarp::os::Searchable &config, servConfigPOS_t &pscconfig);
297 #if defined(SERVICE_PARSER_USE_MC)
298  bool parseService(yarp::os::Searchable &config, servConfigMC_t &mcconfig);
299  bool parseService2(yarp::os::Searchable &config, servConfigMC_t &mcconfig); // the fixed one.
300  //bool convert(std::string const &fromstring, eOmc_ctrlboard_t &controllerboard, bool &formaterror);
301  //bool convert(Bottle &bottle, std::vector<double> &matrix, bool &formaterror, int targetsize);
302  bool convert(std::string const &fromstring, eOmc_actuator_t &toactuatortype, bool &formaterror);
303  bool convert(std::string const &fromstring, eOmc_position_t &toposition, bool &formaterror);
304  bool convert(std::string const &fromstring, eOmc_encoder_t &toencodertype, bool &formaterror);
305 
306  bool parse_connector(const std::string &fromstring, eObrd_connector_t &toconnector, bool &formaterror);
307  bool parse_mais(std::string const &fromstring, eObrd_portmais_t &pmais, bool &formaterror);
308 
309  bool parse_port_conn(std::string const &fromstring, eObrd_type_t const board, uint8_t &toport, bool &formaterror);
310  bool parse_port_mais(std::string const &fromstring, uint8_t &toport, bool &formaterror);
311 
312  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);
313  bool parse_encoder_port(std::string const &fromstring, eObrd_ethtype_t const ethboard, eOmc_encoder_t type, uint8_t &toport, bool &formaterror);
314 
315  bool parse_psc(std::string const &fromstring, eObrd_portpsc_t &ppsc, bool &formaterror);
316  bool parse_port_psc(std::string const &fromstring, uint8_t &toport, bool &formaterror);
317 
318  bool parse_POS_port(std::string const &fromstring, eObrd_portpos_t &ppos, bool &formaterror);
319  bool parse_port_pos(std::string const &fromstring, uint8_t &toport, bool &formaterror);
320 
321  bool parse_POS_connector(std::string const &fromstring, const eObrd_type_t brd, eObrd_connector_t &conn, bool &formaterror);
322  bool parse_POS_CALIB_rotation(std::string const &fromstring, eoas_pos_ROT_t &rot, bool &formaterror);
323  bool parse_POS_CALIB_type(std::string const &fromstring, eoas_pos_TYPE_t &type, bool &formaterror);
324 
325 #endif
326 
327  bool convert(std::string const &fromstring, eOmn_serv_type_t &toservicetype, bool &formaterror);
328  bool convert(std::string const &fromstring, eOmn_serv_diagn_mode_t &todiagnmode, bool &formaterror);
329  bool convert(std::string const &fromstring, eObrd_type_t& tobrdtype, bool& formaterror);
330  bool convert(std::string const &fromstring, eObrd_cantype_t &tobrdcantype, bool &formaterror);
331  bool convert(std::string const &fromstring, eObrd_ethtype_t& tobrdethtype, bool& formaterror);
332  bool convert(std::string const &fromstring, bool &tobool, bool &formaterror);
333  bool convert(const int number, uint8_t &tou8, bool &formaterror);
334  bool convert(const int number, uint16_t &tou16, bool &formaterror);
335  bool convert(std::string const &fromstring, eOas_sensor_t &tosensortype, bool &formaterror);
336  bool convert(std::string const &fromstring, std::string &str, bool &formaterror);
337  bool convert(std::string const &fromstring, const uint8_t strsize, char *str, bool &formaterror);
338  bool convert(std::string const &fromstring, eObrd_location_t &location, bool &formaterror);
339  bool convert(std::string const &fromstring, eOlocation_t &location, bool &formaterror);
340 
341 
342  bool convert(eObrd_location_t const &loc, char *str, int len);
343  bool convert(eOlocation_t const &loc, char *str, int len);
344  bool convert(eObrd_canlocation_t const &canloc, char *str, int len);
345 
346  bool convert(eObrd_protocolversion_t const &prot, char *str, int len);
347  bool convert(eObrd_firmwareversion_t const &firm, char *str, int len);
348 
349  bool convert(std::string const &fromstring, eOmc_pidoutputtype_t& pidoutputtype, bool& formaterror);
350  bool convert(std::string const &fromstring, eOmc_jsetconstraint_t &jsetconstraint, bool& formaterror);
353  bool parse_debugEmbBoardsNotConnected(yarp::os::Searchable &config, bool &embBoardsConnected);
354  public:
355 
358 
360  eOmn_serv_config_data_sk_skin_t tmp;
361 
362 #if defined(SERVICE_PARSER_USE_MC)
364 #endif
365 
366 private:
367 
368  bool check_analog(yarp::os::Searchable &config, eOmn_serv_type_t type);
369 
370  bool check_skin(yarp::os::Searchable &config);
371 
372  bool check_motion(yarp::os::Searchable &config);
373 
374  int getnumofjointsets(void);
375 
376  bool copyjomocouplingInfo(eOmc_4jomo_coupling_t *jc_dest);
377 
378 
379  // suggestion: split check_motion() in sub-methods which parse the groups ...
380 };
381 
382 #endif
383 
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_adv_actuator_descriptor_t advdescr
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