iCub-main
embObjSkin.h
Go to the documentation of this file.
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 
4 /* Copyright (C) 2012 iCub Facility, Istituto Italiano di Tecnologia
5  * Author: Alberto Cardellino
6  * email: alberto.cardellino@iit.it
7  * Permission is granted to copy, distribute, and/or modify this program
8  * under the terms of the GNU General Public License, version 2 or any
9  * later version published by the Free Software Foundation.
10  *
11  * A copy of the license can be found at
12  * http://www.robotcub.org/icub/license/gpl.txt
13  *
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
17  * Public License for more details
18  */
19 
20 
21 #ifndef __EMBOBJSKIN_H__
22 #define __EMBOBJSKIN_H__
23 
24 #include <string>
25 #include <mutex>
26 
27 #include <yarp/os/PeriodicThread.h>
28 #include <yarp/dev/ControlBoardInterfaces.h>
29 #include <yarp/dev/IAnalogSensor.h>
30 #include <yarp/dev/PolyDriver.h>
31 
32 
33 #include "IethResource.h"
34 #include <ethManager.h>
35 #include <abstractEthResource.h>
36 
37 
38 #include "SkinConfigReader.h"
39 #include <SkinDiagnostics.h>
40 #include "serviceParser.h"
41 
42 using namespace yarp::os;
43 using namespace yarp::dev;
44 using namespace yarp::os::impl;
45 using namespace yarp::sig;
46 
47 
48 
50 {
51 public:
52  int idPatch;
53  eOcanport_t canport; // so far a patch contains addresses of a unique canport
54  eOprotIndex_t indexNv;
55  std::vector <int> cardAddrList;
56  int checkCardAddrIsInList(int cardAddr);
57 };
58 
60 {
61  public:
63  std::vector<SkinPatchInfo> patchInfoList;
64  uint8_t numOfPatches;
65 };
66 
67 
68 // -- class EmbObjSkin
69 
70 class EmbObjSkin : public yarp::dev::IAnalogSensor,
71  public DeviceDriver,
72  public eth::IethResource
73 {
74 
75 public:
76 
77  enum { EMBSK_SIZE_INFO = 128 };
79 
80  bool opened;
81 
82 protected:
83 
84  string boardIPstring;
85  string boardName;
86  eOipv4addr_t ipv4addr;
87 
90 
91  std::mutex mtx;
92  //int totalCardsNum;
93  //std::vector<SkinPatchInfo> patchInfoList;
94  size_t sensorsNum;
95  Vector skindata;
96  //uint8_t numOfPatches; //currently one patch is made up by all skin boards connected to one can port of ems.
99  bool _newCfg;
102 
103  bool init();
104  bool fromConfig(yarp::os::Searchable& config);
105  bool initWithSpecialConfig(yarp::os::Searchable& config);
106  bool start();
107  bool configPeriodicMessage(void);
108  eOprotIndex_t convertIdPatch2IndexNv(int idPatch)
109  {
110  /*in xml file idPatch are number of ems canPort identified with numer 1 or 2 on electronic schematics.
111  * in ethernet protocol the patch number is the index part of network variable identifier, that starts from 0 */
112  if(_skCfg.numOfPatches == 1)
113  return(0);
114  else
115  return(idPatch-1);
116  }
117 
118 private:
119 
120  ServiceParser *parser;
121  eOmn_serv_parameter_t ethservice;
122 
123  bool verbosewhenok;
124 
125  /****************** diagnostic********************************/
126  bool _isDiagnosticPresent; // is the diagnostic available from the firmware
127  /*************************************************************/
128 
130  std::vector<iCub::skin::diagnostics::DetectedError> errors;
131 
132 public:
133 
134  EmbObjSkin();
135  ~EmbObjSkin();
136 
137  virtual bool open(yarp::os::Searchable& config);
138 
139  virtual bool close();
140  void cleanup(void);
141 
142  virtual int read(yarp::sig::Vector &out);
143  virtual int getState(int ch);
144  virtual int getChannels();
145  virtual int calibrateSensor();
146  virtual int calibrateChannel(int ch, double v);
147 
148  virtual int calibrateSensor(const yarp::sig::Vector& v);
149  virtual int calibrateChannel(int ch);
150 
151  virtual bool initialised();
152  virtual eth::iethresType_t type();
153  virtual bool update(eOprotID32_t id32, double timestamp, void *rxdata);
154 
155 };
156 
157 #endif
158 
#define SPECIAL_TRIANGLE_CFG_MAX_NUM
Definition: CanBusSkin.cpp:21
eth::AbstractEthResource * res
Definition: embObjSkin.h:89
SkinConfigReader _cfgReader
Definition: embObjSkin.h:100
SkinConfig _skCfg
Definition: embObjSkin.h:101
Vector skindata
Definition: embObjSkin.h:95
string boardName
Definition: embObjSkin.h:85
SkinBoardCfgParam _brdCfg
Definition: embObjSkin.h:97
bool _newCfg
Definition: embObjSkin.h:99
string boardIPstring
Definition: embObjSkin.h:84
eOprotIndex_t convertIdPatch2IndexNv(int idPatch)
Definition: embObjSkin.h:108
SkinTriangleCfgParam _triangCfg
Definition: embObjSkin.h:98
bool opened
Definition: embObjSkin.h:80
size_t sensorsNum
Definition: embObjSkin.h:94
eOipv4addr_t ipv4addr
Definition: embObjSkin.h:86
std::mutex mtx
Definition: embObjSkin.h:91
eth::TheEthManager * ethManager
Definition: embObjSkin.h:88
uint8_t numOfPatches
Definition: embObjSkin.h:64
int totalCardsNum
Definition: embObjSkin.h:62
std::vector< SkinPatchInfo > patchInfoList
Definition: embObjSkin.h:63
std::vector< int > cardAddrList
Definition: embObjSkin.h:55
eOprotIndex_t indexNv
Definition: embObjSkin.h:54
eOcanport_t canport
Definition: embObjSkin.h:53
bool read(yarp::os::Searchable &cfgtotal, pc104Data &pc104data)
Definition: ethParser.cpp:92
iethresType_t
Definition: IethResource.h:62
out
Definition: sine.m:8