iCub-main
embObjAnalogSensor.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 __analogSensorEth_h__
4 #define __analogSensorEth_h__
5 
6 #include <yarp/dev/DeviceDriver.h>
7 #include <yarp/dev/IAnalogSensor.h>
8 #include <yarp/os/PeriodicThread.h>
9 #include <string>
10 #include <list>
11 #include <mutex>
12 
13 #include <iCub/FactoryInterface.h>
14 #include <iCub/LoggerInterfaces.h>
15 
16 #include "IethResource.h"
17 #include <ethManager.h>
18 #include <abstractEthResource.h>
19 
20 
21 #include <yarp/os/LogStream.h>
22 
23 
24 namespace yarp{
25  namespace dev{
26  class embObjAnalogSensor;
27  }
28 }
29 
30 
32 {
33 private:
34  double *_data;
35  int _size;
36  int _bufferSize;
37 public:
38  AnalogData(int ch, int buffsize): _data(0), _size(ch), _bufferSize(buffsize)
39  {
40  _data=new double[_bufferSize];
41  for(int k=0;k<_bufferSize;k++)
42  _data[k]=0;
43  }
45  {
46  delete [] _data;
47  }
48 
49  inline double &operator[](int i)
50  { return _data[i]; }
51 
52  inline int size()
53  { return _size; }
54 
55  inline double *getBuffer()
56  {return _data;}
57 };
58 
59 
60 
61 typedef int AnalogDataFormat;
65 class yarp::dev::embObjAnalogSensor: public yarp::dev::IAnalogSensor,
66  public yarp::dev::DeviceDriver,
67  public eth::IethResource
68 {
69 
70 public:
71 
73 
74 
76  {
81  };
82 
83 public:
84 
87 
88  // An open function yarp factory compatible
89  bool open(yarp::os::Searchable &config);
90  bool close();
91 
92  // IAnalogSensor interface
93  virtual int read(yarp::sig::Vector &out);
94  virtual int getState(int ch);
95  virtual int getChannels();
96  virtual int calibrateChannel(int ch, double v);
97  virtual int calibrateSensor();
98  virtual int calibrateSensor(const yarp::sig::Vector& value);
99  virtual int calibrateChannel(int ch);
100 
101  // IethResource interface
102  virtual bool initialised();
103  virtual eth::iethresType_t type();
104  virtual bool update(eOprotID32_t id32, double timestamp, void* rxdata);
105 
106 private:
107 
108  string boardIPstring;
109  string boardName;
110  eOipv4addr_t ipv4addr;
111 
113  eth::TheEthManager *ethManager;
115 
116  bool opened;
117  bool verbosewhenok;
118 
119  unsigned int counterSat;
120  unsigned int counterError;
121  unsigned int counterTimeout;
122 
124  // parameters
125  int _period;
126  int _channels;
127  int _numofsensors;
128  short _useCalibration;
129  AnalogSensorType _as_type;
130 
131 // uint8_t _fromInertialPos2DataIndexAccelerometers[eoas_inertial1_pos_max_numberof];
132 // uint8_t _fromInertialPos2DataIndexGyroscopes[eoas_inertial1_pos_max_numberof];
133 
134  AnalogData *analogdata;
135  short status;
136 
137  double timeStamp;
138  double* scaleFactor;
139  std::mutex mtx;
140 
141 private:
142 
143  // for all
144  bool extractGroup(Bottle &input, Bottle &out, const std::string &key1, const std::string &txt, int size);
145  bool fromConfig(yarp::os::Searchable &config);
146  bool init();
147  void cleanup(void);
148 
149 
150  // for strain
151  bool fillDatOfStrain(void *as_array_raw);
152  bool sendConfig2Strain(void);
153  bool getFullscaleValues();
154 
155 
156  // for mais
157  bool fillDatOfMais(void *as_array_raw);
158  bool sendConfig2Mais(void);
159 
160 
161  // for inertials
162  bool fillDatOfInertial(void *inertialdata);
163  bool configServiceInertials(Searchable& globalConfig);
164  bool sendConfig2SkinInertial(yarp::os::Searchable &config);
165  //eOas_inertial1_position_t getLocationOfInertialSensor(std::string &strpos);
166 
167 
168  // for ??
169  void resetCounters();
170  void getCounters(unsigned int &saturations, unsigned int &errors, unsigned int &timeouts);
171 };
172 
173 
174 #endif
175 
Interface for a factory device; a device that can create objects.
double * getBuffer()
double & operator[](int i)
AnalogData(int ch, int buffsize)
class yarp::dev::embObjAnalogSensor
virtual bool update(eOprotID32_t id32, double timestamp, void *rxdata)
bool open(yarp::os::Searchable &config)
virtual int calibrateChannel(int ch, double v)
virtual eth::iethresType_t type()
virtual int read(yarp::sig::Vector &out)
Read a vector from the sensor.
int AnalogDataFormat
static int v
Definition: iCub_Sim.cpp:42
iethresType_t
Definition: IethResource.h:61
Copyright (C) 2008 RobotCub Consortium.
out
Definition: sine.m:8