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 ) ( (unsigned short)array[index] | ( (unsigned short)array[index + 1] << 8 ) )
29 #define TAC_CHECK_RES( res, expected, resp ) { \
30  if ( res < expected ) { \
31  dbgPrint( "Response length is too short, should be = %d (is %d)\n", expected, res ); \
32  if ( res > 0 ) free( resp ); \
33  return -1; \
34  } \
35  status_t status = cmd_get_response_status( resp ); \
36  if ( status != E_SUCCESS ) \
37  { \
38  dbgPrint( "Command not successful: %s\n", status_to_str( status ) ); \
39  free( resp ); \
40  return -1; \
41  } \
42  }
43 
44 typedef struct
45 {
46  int res_x; // Horizontal matrix resolution. For non-rectangular matrices, this is the horizontal resolution of the surrounding rectangle measured in sensor cells.
47  int res_y; // Vertical matrix resolution. For non-rectangular matrices, this is the vertical resolution of the surrounding rectangle measured in sensor cells.
48  int cell_width; // Width of one sensor cell in 1/100 millimeters.
49  int cell_height; // Height of one sensor cell in 1/100 millimeters.
50  int fullscale; // Full scale value of the output signal.
52 
53 typedef struct
54 {
55  unsigned char type; // System Type: 0 - unknown, 4 - WTS Tactile Sensor Module
56  unsigned char hw_rev; // Hardware Revision
57  unsigned short 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
58  unsigned short sn; // Serial Number of the device
60 
61 struct FrameData
62 {
63 public:
64  FrameData(std::shared_ptr<std::vector<short> > data, int count)
65  : data(data), count(count)
66  {}
67  std::shared_ptr<std::vector<short> > data;
68  int count;
69 };
71 {
72 public:
73  PeriodicFrameData(std::shared_ptr<std::vector<short> > data, int count, unsigned int timestamp)
75  {}
76  std::shared_ptr<std::vector<short> > data;
77  int count;
78  unsigned int timestamp;
79 };
80 
82 {
83 public:
84  TactileSensor(std::shared_ptr<AbstractInterface> interface);
85  virtual ~TactileSensor();
86 
88  static void printMatrixInfo(tac_matrix_info_t* mi);
90  static void printMatrix(short* matrix, int width, int height);
91 
92  void startPeriodicFrameAcquisition(unsigned short delay_ms);
95  void tareSensorMatrix(unsigned char operation);
96  void setAquisitionWindow(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2);
97  int setAdvanvedAcquisitionMask(char* mask);
98  int getAcquisitionMask(char** mask, int* mask_len);
99  void setThreshold(short threshold);
100  unsigned short getThreshold();
101  void setFrontEndGain(unsigned char gain);
102  unsigned char getFrontEndGain();
103  std::string getSensorType();
104  float readDeviceTemperature();
107  void setDeviceTag(std::string tag);
108  std::string getDeviceTag();
109  bool tryGetDeviceTag(std::string& tag);
110  int loop(char* data, int data_len);
111 
112  std::string getInterfaceInfo();
113 
114 private:
115  std::shared_ptr<AbstractInterface> interface;
116  FrameData getFrameData(Response* response);
117  PeriodicFrameData getPeriodicFrameData(Response* response);
118 
119 private:
120  friend std::ostream& operator<<(std::ostream&, const TactileSensor&);
121 };
122 
123 std::ostream& operator<<(std::ostream& strm, const TactileSensor& a);
124 
TactileSensor::setDeviceTag
void setDeviceTag(std::string tag)
Definition: TactileSensor.cpp:290
TactileSensor::printSystemInformation
static void printSystemInformation(tac_system_information_t si)
Definition: TactileSensor.cpp:281
FrameData
Definition: TactileSensor.h:61
FrameData::data
std::shared_ptr< std::vector< short > > data
Definition: TactileSensor.h:67
PeriodicFrameData::count
int count
Definition: TactileSensor.h:77
TactileSensor::getAcquisitionMask
int getAcquisitionMask(char **mask, int *mask_len)
Definition: TactileSensor.cpp:206
TactileSensor::readSingleFrame
FrameData readSingleFrame()
Definition: TactileSensor.cpp:82
TactileSensor::startPeriodicFrameAcquisition
void startPeriodicFrameAcquisition(unsigned short delay_ms)
Definition: TactileSensor.cpp:151
tac_matrix_info_t::fullscale
int fullscale
Definition: TactileSensor.h:50
TactileSensor::setAquisitionWindow
void setAquisitionWindow(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2)
Definition: TactileSensor.cpp:191
PeriodicFrameData::data
std::shared_ptr< std::vector< short > > data
Definition: TactileSensor.h:76
tac_system_information_t
Definition: TactileSensor.h:53
TactileSensor::setFrontEndGain
void setFrontEndGain(unsigned char gain)
Definition: TactileSensor.cpp:226
TactileSensor::operator<<
friend std::ostream & operator<<(std::ostream &, const TactileSensor &)
Definition: TactileSensor.cpp:330
TactileSensor::stopPeriodicFrameAcquisition
void stopPeriodicFrameAcquisition(void)
Definition: TactileSensor.cpp:159
TactileSensor::printMatrix
static void printMatrix(short *matrix, int width, int height)
Definition: TactileSensor.cpp:65
TactileSensor
Definition: TactileSensor.h:81
tac_matrix_info_t::res_x
int res_x
Definition: TactileSensor.h:46
armarx::ctrlutil::a
double a(double t, double a0, double j)
Definition: CtrlUtil.h:45
AbstractInterface.h
FrameData::FrameData
FrameData(std::shared_ptr< std::vector< short > > data, int count)
Definition: TactileSensor.h:64
tac_system_information_t::fw_version
unsigned short fw_version
Definition: TactileSensor.h:57
FrameData::count
int count
Definition: TactileSensor.h:68
tac_matrix_info_t::cell_width
int cell_width
Definition: TactileSensor.h:48
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
PeriodicFrameData::timestamp
unsigned int timestamp
Definition: TactileSensor.h:78
TactileSensor::getSystemInformation
tac_system_information_t getSystemInformation()
Definition: TactileSensor.cpp:269
TactileSensor::tareSensorMatrix
void tareSensorMatrix(unsigned char operation)
Definition: TactileSensor.cpp:183
TactileSensor::getThreshold
unsigned short getThreshold()
Definition: TactileSensor.cpp:219
TactileSensor::getFrontEndGain
unsigned char getFrontEndGain()
Definition: TactileSensor.cpp:239
TactileSensor::setThreshold
void setThreshold(short threshold)
Definition: TactileSensor.cpp:210
TactileSensor::tryGetDeviceTag
bool tryGetDeviceTag(std::string &tag)
Definition: TactileSensor.cpp:306
TactileSensor::printMatrixInfo
static void printMatrixInfo(tac_matrix_info_t *mi)
Definition: TactileSensor.cpp:59
PeriodicFrameData::PeriodicFrameData
PeriodicFrameData(std::shared_ptr< std::vector< short > > data, int count, unsigned int timestamp)
Definition: TactileSensor.h:73
TactileSensor::~TactileSensor
virtual ~TactileSensor()
Definition: TactileSensor.cpp:36
tac_matrix_info_t::cell_height
int cell_height
Definition: TactileSensor.h:49
TactileSensor::readDeviceTemperature
float readDeviceTemperature()
Definition: TactileSensor.cpp:262
TactileSensor::getMatrixInformation
tac_matrix_info_t getMatrixInformation()
Definition: TactileSensor.cpp:41
tac_system_information_t::type
unsigned char type
Definition: TactileSensor.h:55
Response
Definition: Response.h:34
TactileSensor::receicePeriodicFrame
PeriodicFrameData receicePeriodicFrame()
Definition: TactileSensor.cpp:89
TactileSensor::setAdvanvedAcquisitionMask
int setAdvanvedAcquisitionMask(char *mask)
Definition: TactileSensor.cpp:202
tac_matrix_info_t::res_y
int res_y
Definition: TactileSensor.h:47
TactileSensor::loop
int loop(char *data, int data_len)
Definition: TactileSensor.cpp:320
TactileSensor::getSensorType
std::string getSensorType()
Definition: TactileSensor.cpp:251
tac_system_information_t::sn
unsigned short sn
Definition: TactileSensor.h:58
tac_system_information_t::hw_rev
unsigned char hw_rev
Definition: TactileSensor.h:56
PeriodicFrameData
Definition: TactileSensor.h:70
TactileSensor::getDeviceTag
std::string getDeviceTag()
Definition: TactileSensor.cpp:297
tac_matrix_info_t
Definition: TactileSensor.h:44
TactileSensor::TactileSensor
TactileSensor(std::shared_ptr< AbstractInterface > interface)
Definition: TactileSensor.cpp:31
TactileSensor::getInterfaceInfo
std::string getInterfaceInfo()
Definition: TactileSensor.cpp:325
operator<<
std::ostream & operator<<(std::ostream &strm, const TactileSensor &a)
Definition: TactileSensor.cpp:330