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
48typedef 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
57typedef 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
67{
68public:
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{
79public:
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{
92public:
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);
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
124private:
125 std::shared_ptr<AbstractInterface> interface;
126 FrameData getFrameData(Response* response);
127 PeriodicFrameData getPeriodicFrameData(Response* response);
128
129private:
130 friend std::ostream& operator<<(std::ostream&, const TactileSensor&);
131};
132
133std::ostream& operator<<(std::ostream& strm, const TactileSensor& a);
uint8_t data[1]
std::ostream & operator<<(std::ostream &strm, const TactileSensor &a)
std::string getInterfaceInfo()
static void printMatrix(short *matrix, int width, int height)
int getAcquisitionMask(char **mask, int *mask_len)
void startPeriodicFrameAcquisition(unsigned short delay_ms)
tac_system_information_t getSystemInformation()
bool tryGetDeviceTag(std::string &tag)
float readDeviceTemperature()
PeriodicFrameData receicePeriodicFrame()
void setAquisitionWindow(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2)
int loop(char *data, int data_len)
virtual ~TactileSensor()
friend std::ostream & operator<<(std::ostream &, const TactileSensor &)
unsigned short getThreshold()
void setThreshold(short threshold)
TactileSensor(std::shared_ptr< AbstractInterface > interface)
std::string getDeviceTag()
static void printMatrixInfo(tac_matrix_info_t *mi)
tac_matrix_info_t getMatrixInformation()
void tareSensorMatrix(unsigned char operation)
void setFrontEndGain(unsigned char gain)
int setAdvanvedAcquisitionMask(char *mask)
static void printSystemInformation(tac_system_information_t si)
void stopPeriodicFrameAcquisition(void)
std::string getSensorType()
FrameData readSingleFrame()
void setDeviceTag(std::string tag)
unsigned char getFrontEndGain()
std::shared_ptr< std::vector< short > > data
FrameData(std::shared_ptr< std::vector< short > > data, int count)
std::shared_ptr< std::vector< short > > data
unsigned int timestamp
PeriodicFrameData(std::shared_ptr< std::vector< short > > data, int count, unsigned int timestamp)
unsigned short fw_version