iCub-main
CanBusFtSensor.h
Go to the documentation of this file.
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 // Copyright: (C) 2013 iCub Facility
4 // Authors: Marco Randazzo <marco.randazzo@iit.it> Valentina Vasco <valentina.vasco@iit.it>
5 // CopyPolicy: Released under the terms of the GNU GPL v2.0.
6 
7 #ifndef __CANBUSFTSENSOR_H__
8 #define __CANBUSFTSENSOR_H__
9 
10 #include <mutex>
11 #include <yarp/os/PeriodicThread.h>
12 #include <yarp/dev/IAnalogSensor.h>
13 #include <yarp/dev/PolyDriver.h>
14 #include <yarp/dev/CanBusInterface.h>
15 #include <yarp/dev/MultipleAnalogSensorsInterfaces.h>
16 #include <yarp/sig/Vector.h>
17 
18 using namespace yarp::os;
19 using namespace yarp::dev;
20 
45 class CanBusFtSensor : public PeriodicThread,
46  public yarp::dev::IAnalogSensor,
47  public DeviceDriver,
48  public yarp::dev::ISixAxisForceTorqueSensors
49 {
50  enum AnalogDataFormat
51  {
52  ANALOG_FORMAT_ERR = 0,
53  ANALOG_FORMAT_8_BIT = 8,
54  ANALOG_FORMAT_16_BIT = 16,
55  };
56 
57  enum SensorStatus
58  {
59  ANALOG_IDLE=0,
60  ANALOG_OK=1,
61  ANALOG_NOT_RESPONDING=-1,
62  ANALOG_SATURATION=-2,
63  ANALOG_ERROR=-3,
64  };
65 
66 protected:
67  PolyDriver driver;
68  ICanBus *pCanBus;
69  ICanBufferFactory *pCanBufferFactory;
70  CanBuffer inBuffer;
71  CanBuffer outBuffer;
73 
74  mutable std::mutex mtx;
75 
76  unsigned int channelsNum;
77  unsigned short boardId;
78  short status;
79  double timeStamp;
80  AnalogDataFormat dataFormat;
81  yarp::sig::Vector data;
82  yarp::sig::Vector scaleFactor;
83  unsigned short useCalibration;
84  bool diagnostic;
85  std::string sensorName;
86  std::string frameName;
87 
88 public:
89  CanBusFtSensor(int period=20) : PeriodicThread((double)period/1000.0)
90  {}
91 
92 
94  {
95  }
96 
97  virtual bool open(yarp::os::Searchable& config);
98  virtual bool close();
99 
100 
101  //IAnalogSensor interface
102  virtual int read(yarp::sig::Vector &out);
103  virtual int getState(int ch);
104  virtual int getChannels();
105  int calibrateSensor();
106  virtual int calibrateChannel(int ch, double v);
107 
108  virtual int calibrateSensor(const yarp::sig::Vector& v);
109  virtual int calibrateChannel(int ch);
110 
111  virtual bool threadInit();
112  virtual void threadRelease();
113  virtual void run();
114 
115  // ISixAxisForceTorqueSensors
116  virtual size_t getNrOfSixAxisForceTorqueSensors() const override;
117  virtual yarp::dev::MAS_status getSixAxisForceTorqueSensorStatus(size_t sens_index) const override;
118  virtual bool getSixAxisForceTorqueSensorName(size_t sens_index, std::string &name) const override;
119  virtual bool getSixAxisForceTorqueSensorFrameName(size_t sens_index, std::string &frameName) const override;
120  virtual bool getSixAxisForceTorqueSensorMeasure(size_t sens_index, yarp::sig::Vector& out, double& timestamp) const override;
121 
122  //internal methods
123  private:
124  bool decode8 (const unsigned char *msg, int msg_id, double *data);
125  bool decode16(const unsigned char *msg, int msg_id, double *data);
126  bool sensor_start (yarp::os::Searchable& config);
127  bool sensor_stop ();
128  bool readFullScaleAnalog(int ch);
129 };
130 
131 
132 #endif
@ data
canbusftsensor : driver for CAN communication with IIT's analog sensor boards, including the MAIS and...
std::string frameName
ICanBus * pCanBus
unsigned short boardId
CanBuffer outBuffer
yarp::sig::Vector data
unsigned short useCalibration
PolyDriver driver
ICanBufferFactory * pCanBufferFactory
std::mutex mtx
AnalogDataFormat dataFormat
std::string sensorName
unsigned int channelsNum
CanBusFtSensor(int period=20)
yarp::sig::Vector scaleFactor
CanBuffer inBuffer
static int v
Definition: iCub_Sim.cpp:42
bool read(yarp::os::Searchable &cfgtotal, pc104Data &pc104data)
Definition: ethParser.cpp:92
out
Definition: sine.m:8