iCub-main
embObjStrain.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 #ifndef __embObjStrain_h__
5 #define __embObjStrain_h__
6 
7 #include <yarp/dev/DeviceDriver.h>
8 #include <yarp/dev/IAnalogSensor.h>
9 #include <yarp/os/PeriodicThread.h>
10 #include <string>
11 #include <list>
12 #include <mutex>
13 
14 #include <iCub/FactoryInterface.h>
15 #include <iCub/LoggerInterfaces.h>
16 
17 #include "IethResource.h"
18 #include <ethManager.h>
19 #include <abstractEthResource.h>
20 
21 
22 #include <yarp/os/LogStream.h>
23 
24 #include "serviceParser.h"
25 
26 
27 namespace yarp {
28  namespace dev {
29  class embObjStrain;
30  }
31 }
32 
33 
34 #define EMBOBJSTRAIN_USESERVICEPARSER
35 
36 // -- class embObjStrain
37 
52 class yarp::dev::embObjStrain: public yarp::dev::IAnalogSensor,
53  public yarp::dev::DeviceDriver,
54  public eth::IethResource
55 {
56 
57 public:
58 
59  enum { strain_Channels = 6, strain_FormatData = 16 };
60 
61 public:
62 
63  embObjStrain();
64  ~embObjStrain();
65 
66  // An open function yarp factory compatible
67  bool open(yarp::os::Searchable &config);
68  bool close();
69 
70  // IAnalogSensor interface
71  virtual int read(yarp::sig::Vector &out);
72  virtual int getState(int ch);
73  virtual int getChannels();
74  virtual int calibrateChannel(int ch, double v);
75  virtual int calibrateSensor();
76  virtual int calibrateSensor(const yarp::sig::Vector& value);
77  virtual int calibrateChannel(int ch);
78 
79  // IethResource interface
80  virtual bool initialised();
81  virtual eth::iethresType_t type();
82  virtual bool update(eOprotID32_t id32, double timestamp, void* rxdata);
83 
84 private:
85 
86  string boardIPstring;
87  string boardName;
88  eOipv4addr_t ipv4addr;
89 
90  eth::TheEthManager* ethManager;
92  ServiceParser* parser;
93 
94  bool opened;
95  bool verbosewhenok;
96 
97  unsigned int counterSat;
98  unsigned int counterError;
99  unsigned int counterTimeout;
100 
102  // parameters
103  servConfigStrain_t serviceConfig;
104 
105 
106  std::mutex mtx;
107 
108  vector<double> analogdata;
109  vector<double> offset;
110  vector<double> scaleFactor;
111 
112  bool scaleFactorIsFilled;
113 
114  short status;
115  double timeStamp;
116 
117 private:
118 
119  // for all
120  bool fromConfig(yarp::os::Searchable &config);
121  bool initRegulars();
122  void cleanup(void);
123  void printServiceConfig(void);
124 
125  // for strain
126  bool fillScaleFactor();
127  bool sendConfig2Strain(void);
128 
129  // for ??
130  void resetCounters();
131  void getCounters(unsigned int &saturations, unsigned int &errors, unsigned int &timeouts);
132 };
133 
134 
135 #endif
136 
Interface for a factory device; a device that can create objects.
embObjStrain : driver for communication with IIT's STRAIN board over EMS boards.
Definition: embObjStrain.h:55
virtual int read(yarp::sig::Vector &out)
Read a vector from the sensor.
virtual eth::iethresType_t type()
virtual bool update(eOprotID32_t id32, double timestamp, void *rxdata)
virtual int calibrateChannel(int ch, double v)
virtual int getState(int ch)
virtual bool initialised()
virtual int calibrateSensor()
bool open(yarp::os::Searchable &config)
static int v
Definition: iCub_Sim.cpp:42
iethresType_t
Definition: IethResource.h:61
Copyright (C) 2008 RobotCub Consortium.
out
Definition: sine.m:8