TactileSensor.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package
19  * @author
20  * @date
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #pragma once
25 
26 #include "AbstractInterface.h"
27 
28 #define extract_short(array, index) \
29  ((unsigned short)array[index] | ((unsigned short)array[index + 1] << 8))
30 #define TAC_CHECK_RES(res, expected, resp) \
31  { \
32  if (res < expected) \
33  { \
34  dbgPrint("Response length is too short, should be = %d (is %d)\n", expected, res); \
35  if (res > 0) \
36  free(resp); \
37  return -1; \
38  } \
39  status_t status = cmd_get_response_status(resp); \
40  if (status != E_SUCCESS) \
41  { \
42  dbgPrint("Command not successful: %s\n", status_to_str(status)); \
43  free(resp); \
44  return -1; \
45  } \
46  }
47 
48 typedef struct
49 {
50  int res_x; // Horizontal matrix resolution. For non-rectangular matrices, this is the horizontal resolution of the surrounding rectangle measured in sensor cells.
51  int res_y; // Vertical matrix resolution. For non-rectangular matrices, this is the vertical resolution of the surrounding rectangle measured in sensor cells.
52  int cell_width; // Width of one sensor cell in 1/100 millimeters.
53  int cell_height; // Height of one sensor cell in 1/100 millimeters.
54  int fullscale; // Full scale value of the output signal.
56 
57 typedef struct
58 {
59  unsigned char type; // System Type: 0 - unknown, 4 - WTS Tactile Sensor Module
60  unsigned char hw_rev; // Hardware Revision
61  unsigned short
62  fw_version; // Firmware Version: D15...12: major version, D11...8: minor version 1, D7..4 minor version 2, D3..0: 0 for release version, 1..15 for release candidate versions
63  unsigned short sn; // Serial Number of the device
65 
66 struct FrameData
67 {
68 public:
69  FrameData(std::shared_ptr<std::vector<short>> data, int count) : data(data), count(count)
70  {
71  }
72 
73  std::shared_ptr<std::vector<short>> data;
74  int count;
75 };
76 
78 {
79 public:
80  PeriodicFrameData(std::shared_ptr<std::vector<short>> data, int count, unsigned int timestamp) :
82  {
83  }
84 
85  std::shared_ptr<std::vector<short>> data;
86  int count;
87  unsigned int timestamp;
88 };
89 
91 {
92 public:
93  TactileSensor(std::shared_ptr<AbstractInterface> interface);
94  virtual ~TactileSensor();
95 
97  static void printMatrixInfo(tac_matrix_info_t* mi);
99  static void printMatrix(short* matrix, int width, int height);
100 
101  void startPeriodicFrameAcquisition(unsigned short delay_ms);
102  void stopPeriodicFrameAcquisition(void);
104  void tareSensorMatrix(unsigned char operation);
105  void
106  setAquisitionWindow(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2);
107  int setAdvanvedAcquisitionMask(char* mask);
108  int getAcquisitionMask(char** mask, int* mask_len);
109  void setThreshold(short threshold);
110  unsigned short getThreshold();
111  void setFrontEndGain(unsigned char gain);
112  unsigned char getFrontEndGain();
113  std::string getSensorType();
114  float readDeviceTemperature();
117  void setDeviceTag(std::string tag);
118  std::string getDeviceTag();
119  bool tryGetDeviceTag(std::string& tag);
120  int loop(char* data, int data_len);
121 
122  std::string getInterfaceInfo();
123 
124 private:
125  std::shared_ptr<AbstractInterface> interface;
126  FrameData getFrameData(Response* response);
127  PeriodicFrameData getPeriodicFrameData(Response* response);
128 
129 private:
130  friend std::ostream& operator<<(std::ostream&, const TactileSensor&);
131 };
132 
133 std::ostream& operator<<(std::ostream& strm, const TactileSensor& a);
TactileSensor::setDeviceTag
void setDeviceTag(std::string tag)
Definition: TactileSensor.cpp:346
PeriodicFrameData::PeriodicFrameData
PeriodicFrameData(std::shared_ptr< std::vector< short >> data, int count, unsigned int timestamp)
Definition: TactileSensor.h:80
TactileSensor::printSystemInformation
static void printSystemInformation(tac_system_information_t si)
Definition: TactileSensor.cpp:333
FrameData
Definition: TactileSensor.h:66
FrameData::data
std::shared_ptr< std::vector< short > > data
Definition: TactileSensor.h:73
PeriodicFrameData::count
int count
Definition: TactileSensor.h:86
TactileSensor::getAcquisitionMask
int getAcquisitionMask(char **mask, int *mask_len)
Definition: TactileSensor.cpp:242
TactileSensor::readSingleFrame
FrameData readSingleFrame()
Definition: TactileSensor.cpp:93
TactileSensor::startPeriodicFrameAcquisition
void startPeriodicFrameAcquisition(unsigned short delay_ms)
Definition: TactileSensor.cpp:169
tac_matrix_info_t::fullscale
int fullscale
Definition: TactileSensor.h:54
TactileSensor::setAquisitionWindow
void setAquisitionWindow(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2)
Definition: TactileSensor.cpp:220
PeriodicFrameData::data
std::shared_ptr< std::vector< short > > data
Definition: TactileSensor.h:85
tac_system_information_t
Definition: TactileSensor.h:57
TactileSensor::setFrontEndGain
void setFrontEndGain(unsigned char gain)
Definition: TactileSensor.cpp:268
TactileSensor::operator<<
friend std::ostream & operator<<(std::ostream &, const TactileSensor &)
Definition: TactileSensor.cpp:393
TactileSensor::stopPeriodicFrameAcquisition
void stopPeriodicFrameAcquisition(void)
Definition: TactileSensor.cpp:179
TactileSensor::printMatrix
static void printMatrix(short *matrix, int width, int height)
Definition: TactileSensor.cpp:75
TactileSensor
Definition: TactileSensor.h:90
tac_matrix_info_t::res_x
int res_x
Definition: TactileSensor.h:50
armarx::ctrlutil::a
double a(double t, double a0, double j)
Definition: CtrlUtil.h:45
AbstractInterface.h
tac_system_information_t::fw_version
unsigned short fw_version
Definition: TactileSensor.h:62
FrameData::count
int count
Definition: TactileSensor.h:74
tac_matrix_info_t::cell_width
int cell_width
Definition: TactileSensor.h:52
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
PeriodicFrameData::timestamp
unsigned int timestamp
Definition: TactileSensor.h:87
TactileSensor::getSystemInformation
tac_system_information_t getSystemInformation()
Definition: TactileSensor.cpp:319
TactileSensor::tareSensorMatrix
void tareSensorMatrix(unsigned char operation)
Definition: TactileSensor.cpp:209
FrameData::FrameData
FrameData(std::shared_ptr< std::vector< short >> data, int count)
Definition: TactileSensor.h:69
TactileSensor::getThreshold
unsigned short getThreshold()
Definition: TactileSensor.cpp:259
TactileSensor::getFrontEndGain
unsigned char getFrontEndGain()
Definition: TactileSensor.cpp:283
TactileSensor::setThreshold
void setThreshold(short threshold)
Definition: TactileSensor.cpp:248
TactileSensor::tryGetDeviceTag
bool tryGetDeviceTag(std::string &tag)
Definition: TactileSensor.cpp:365
TactileSensor::printMatrixInfo
static void printMatrixInfo(tac_matrix_info_t *mi)
Definition: TactileSensor.cpp:64
TactileSensor::~TactileSensor
virtual ~TactileSensor()
Definition: TactileSensor.cpp:39
tac_matrix_info_t::cell_height
int cell_height
Definition: TactileSensor.h:53
TactileSensor::readDeviceTemperature
float readDeviceTemperature()
Definition: TactileSensor.cpp:310
TactileSensor::getMatrixInformation
tac_matrix_info_t getMatrixInformation()
Definition: TactileSensor.cpp:45
tac_system_information_t::type
unsigned char type
Definition: TactileSensor.h:59
Response
Definition: Response.h:36
TactileSensor::receicePeriodicFrame
PeriodicFrameData receicePeriodicFrame()
Definition: TactileSensor.cpp:102
TactileSensor::setAdvanvedAcquisitionMask
int setAdvanvedAcquisitionMask(char *mask)
Definition: TactileSensor.cpp:236
tac_matrix_info_t::res_y
int res_y
Definition: TactileSensor.h:51
TactileSensor::loop
int loop(char *data, int data_len)
Definition: TactileSensor.cpp:381
TactileSensor::getSensorType
std::string getSensorType()
Definition: TactileSensor.cpp:297
tac_system_information_t::sn
unsigned short sn
Definition: TactileSensor.h:63
tac_system_information_t::hw_rev
unsigned char hw_rev
Definition: TactileSensor.h:60
PeriodicFrameData
Definition: TactileSensor.h:77
TactileSensor::getDeviceTag
std::string getDeviceTag()
Definition: TactileSensor.cpp:355
tac_matrix_info_t
Definition: TactileSensor.h:48
TactileSensor::TactileSensor
TactileSensor(std::shared_ptr< AbstractInterface > interface)
Definition: TactileSensor.cpp:34
TactileSensor::getInterfaceInfo
std::string getInterfaceInfo()
Definition: TactileSensor.cpp:387
operator<<
std::ostream & operator<<(std::ostream &strm, const TactileSensor &a)
Definition: TactileSensor.cpp:393