tactile_sensors.hpp
Go to the documentation of this file.
1 /*
2 * Copyright 2011 Shadow Robot Company Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16 
26 #ifndef _TACTILE_SENSORS_HPP_
27 #define _TACTILE_SENSORS_HPP_
28 
29 #include <string>
30 #include <vector>
31 
32 #include <boost/array.hpp>
33 #include <boost/algorithm/string.hpp>
34 #include <boost/algorithm/string/find_iterator.hpp>
35 #include <boost/circular_buffer.hpp>
36 #include <sstream>
37 
38 #include <ros/ros.h>
39 
40 namespace tactiles
41 {
43 {
44 public:
46  {
47  };
48 
50  std::string manufacturer, std::string serial_number,
52  bool software_version_modified, std::string pcb_version)
53  : tactile_data_valid(tactile_data_valid), sample_frequency(sample_frequency),
54  manufacturer(manufacturer), serial_number(serial_number),
55  software_version_current(software_version_current),
56  software_version_server(software_version_server),
57  software_version_modified(software_version_modified),
58  pcb_version(pcb_version)
59  {
60  };
61 
63  {
64  };
65 
66  bool tactile_data_valid;
67 
70  std::string manufacturer;
71  std::string serial_number;
72 
76 
84  void set_software_version(std::string version)
85  {
86  // split the string to fill the different versions
87  std::vector<std::string> splitted_string;
88  boost::split(splitted_string, version, boost::is_any_of("\n"));
89 
90  ROS_DEBUG("Tactile version: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X",
91  static_cast<unsigned char>(version[0]), static_cast<unsigned char>(version[1]),
92  static_cast<unsigned char>(version[2]), static_cast<unsigned char>(version[3]),
93  static_cast<unsigned char>(version[4]), static_cast<unsigned char>(version[5]),
94  static_cast<unsigned char>(version[6]), static_cast<unsigned char>(version[7]),
95  static_cast<unsigned char>(version[8]), static_cast<unsigned char>(version[9]),
96  static_cast<unsigned char>(version[10]), static_cast<unsigned char>(version[11]),
97  static_cast<unsigned char>(version[12]), static_cast<unsigned char>(version[13]),
98  static_cast<unsigned char>(version[14]), static_cast<unsigned char>(version[15]));
99  if (splitted_string.size() >= 3)
100  {
101  software_version_current = convertToInt(splitted_string[0]);
102  software_version_server = convertToInt(splitted_string[1]);
103 
104  if (splitted_string[2] == "No")
105  {
106  software_version_modified = false;
107  }
108  else
109  {
110  software_version_modified = true;
111  }
112  }
113  else
114  {
115  ROS_ERROR("Incorrect tactile sensor version format");
116  software_version_current = 0;
117  software_version_server = 0;
118  software_version_modified = false;
119  }
120  };
121 
128  virtual std::string get_software_version()
129  {
130  // concatenate versions in a string.
131  std::string full_version;
132 
133  std::stringstream ss;
134  if (software_version_modified)
135  {
136  ss << "current: " << software_version_current << " / server: " << software_version_server << " / MODIFIED";
137  }
138  else
139  {
140  ss << "current: " << software_version_current << " / server: " << software_version_server << " / not modified";
141  }
142 
143  full_version = ss.str();
144 
145  return full_version;
146  };
147 
148  std::string pcb_version;
149 
150  inline double convertToInt(std::string const &s)
151  {
152  std::istringstream i(s);
153  int x;
154  if (!(i >> x))
155  {
156  x = -1;
157  }
158  return x;
159  }
160 };
161 
162 class PST3Data
163  :
164  public GenericTactileData
165 {
166 public:
169  {
170  };
171 
172  PST3Data(const PST3Data &pst3)
174  pst3.manufacturer, pst3.serial_number,
178  pst3.pcb_version),
179  pressure(pst3.pressure), temperature(pst3.temperature),
180  debug_1(pst3.debug_1), debug_2(pst3.debug_2),
181  pressure_raw(pst3.pressure_raw), zero_tracking(pst3.zero_tracking), dac_value(pst3.dac_value)
182  {
183  };
184 
185 
186  explicit PST3Data(const GenericTactileData &gtd)
188  gtd.manufacturer, gtd.serial_number,
192  gtd.pcb_version)
193  {
194  };
195 
197  {
198  };
199  int pressure;
201 
202  int debug_1;
203  int debug_2;
204 
207 
209 
216  virtual std::string get_software_version()
217  {
218  // concatenate versions in a string.
219  std::string full_version;
220 
221  std::stringstream ss;
222  ss << "current: " << software_version_current;
223 
224  full_version = ss.str();
225 
226  return full_version;
227  };
228 };
229 
231  :
232  public GenericTactileData
233 {
234 public:
237  {
238  pac_buffer_ = boost::circular_buffer<int16_t>(pac_size_);
239  pac_vector_.reserve(pac_size_);
240  };
241 
242  BiotacData(const BiotacData &btac)
244  btac.manufacturer, btac.serial_number,
248  btac.pcb_version),
249  pac0(btac.pac0), pac1(btac.pac1),
250  pdc(btac.pdc), tac(btac.tac),
251  tdc(btac.tdc)
252  {
253  electrodes = std::vector<int16_t>(btac.electrodes);
254  pac_vector_ = std::vector<int16_t>(btac.pac_vector_);
255  pac_buffer_ = boost::circular_buffer<int16_t>(btac.pac_buffer_);
256  };
257 
258  explicit BiotacData(const GenericTactileData &gtd)
260  gtd.manufacturer, gtd.serial_number,
264  gtd.pcb_version)
265  {
266  pac_buffer_ = boost::circular_buffer<int16_t>(pac_size_);
267  pac_vector_.reserve(pac_size_);
268  };
269 
271  {
272  };
273 
274  std::vector<int16_t> get_pac(bool consume = false)
275  {
276  pac_vector_.clear();
277  pac_vector_.insert(pac_vector_.begin(), pac_buffer_.begin(), pac_buffer_.end());
278  if (consume)
279  {
280  pac_buffer_.clear();
281  }
282  return pac_vector_;
283  }
284 
285  std::vector<int16_t> consume_pac()
286  {
287  return get_pac(true);
288  }
289 
290  int pac0; // always there, in word[0] and 1; int16u (2kHz)
291  int pac1; // int16u
292 
293  int pdc; // int16u in word[2]
294 
295  int tac; // int16u in word[2]
296  int tdc; // int16u in word[2]
297  std::vector<int16_t> electrodes; // int16u in word[2]
298  boost::circular_buffer<int16_t> pac_buffer_; // 2kHz history of int16u/word[2] values. Capacity of 270 samples is
299  // 135ms history
300  static const size_t pac_size_ = 270;
301 
302 private:
303  std::vector<int16_t> pac_vector_;
304 };
305 
306 class UBI0Data
307  :
308  public GenericTactileData
309 {
310 public:
313  {
314  };
315 
316  UBI0Data(const UBI0Data &ubi0)
318  ubi0.manufacturer, ubi0.serial_number,
322  ubi0.pcb_version)
323  {
324  for (unsigned int i = 0; i < ubi0.distal.size(); i++)
325  {
326  distal[i] = ubi0.distal[i];
327  }
328  for (unsigned int i = 0; i < ubi0.middle.size(); i++)
329  {
330  middle[i] = ubi0.middle[i];
331  }
332  for (unsigned int i = 0; i < ubi0.proximal.size(); i++)
333  {
334  proximal[i] = ubi0.proximal[i];
335  }
336  };
337 
338  explicit UBI0Data(const GenericTactileData &gtd)
340  gtd.manufacturer, gtd.serial_number,
344  gtd.pcb_version)
345  {
346  };
347 
349  {
350  };
351 
352 
353  boost::array<uint16_t, 12ul> distal;
354  boost::array<uint16_t, 4ul> middle;
355  boost::array<uint16_t, 4ul> proximal;
356 };
357 
359 {
360 public:
362  {
363  };
364 
366  {
367  for (unsigned int i = 0; i < ubi0.palm.size(); i++)
368  {
369  palm[i] = ubi0.palm[i];
370  }
371  };
372 
374  {
375  };
376 
377  boost::array<uint16_t, 16ul> palm;
378 };
379 
381 {
382  std::string type;
386 };
387 } // namespace tactiles
388 
389 /* For the emacs weenies in the crowd.
390  Local Variables:
391  c-basic-offset: 2
392  End:
393 */
394 
395 #endif
boost::array< uint16_t, 4ul > middle
GenericTactileData(bool tactile_data_valid, int sample_frequency, std::string manufacturer, std::string serial_number, int software_version_current, int software_version_server, bool software_version_modified, std::string pcb_version)
UBI0PalmData(const UBI0PalmData &ubi0)
BiotacData(const GenericTactileData &gtd)
double convertToInt(std::string const &s)
std::vector< int16_t > electrodes
std::vector< int16_t > pac_vector_
PST3Data(const GenericTactileData &gtd)
BiotacData(const BiotacData &btac)
boost::array< uint16_t, 16ul > palm
std::vector< int16_t > consume_pac()
boost::array< uint16_t, 12ul > distal
void set_software_version(std::string version)
UBI0Data(const GenericTactileData &gtd)
PST3Data(const PST3Data &pst3)
boost::array< uint16_t, 4ul > proximal
UBI0Data(const UBI0Data &ubi0)
virtual std::string get_software_version()
virtual std::string get_software_version()
std::vector< int16_t > get_pac(bool consume=false)
#define ROS_ERROR(...)
boost::circular_buffer< int16_t > pac_buffer_
#define ROS_DEBUG(...)


sr_hardware_interface
Author(s): Ugo Cupcic
autogenerated on Mon Feb 28 2022 23:52:08