tactile_sensors.hpp
Go to the documentation of this file.
1 
27 #ifndef _TACTILE_SENSORS_HPP_
28 #define _TACTILE_SENSORS_HPP_
29 
30 #include <string>
31 #include <vector>
32 
33 #include <boost/array.hpp>
34 #include <boost/algorithm/string.hpp>
35 #include <boost/algorithm/string/find_iterator.hpp>
36 #include <boost/circular_buffer.hpp>
37 #include <sstream>
38 
39 #include <ros/ros.h>
40 
41 namespace tactiles
42 {
44 {
45 public:
47  {
48  };
49 
51  std::string manufacturer, std::string serial_number,
53  bool software_version_modified, std::string pcb_version)
54  : tactile_data_valid(tactile_data_valid), sample_frequency(sample_frequency),
55  manufacturer(manufacturer), serial_number(serial_number),
56  software_version_current(software_version_current),
57  software_version_server(software_version_server),
58  software_version_modified(software_version_modified),
59  pcb_version(pcb_version)
60  {
61  };
62 
64  {
65  };
66 
67  bool tactile_data_valid;
68 
71  std::string manufacturer;
72  std::string serial_number;
73 
77 
85  void set_software_version(std::string version)
86  {
87  // split the string to fill the different versions
88  std::vector<std::string> splitted_string;
89  boost::split(splitted_string, version, boost::is_any_of("\n"));
90 
91  ROS_DEBUG("Tactile version: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X",
92  static_cast<unsigned char>(version[0]), static_cast<unsigned char>(version[1]),
93  static_cast<unsigned char>(version[2]), static_cast<unsigned char>(version[3]),
94  static_cast<unsigned char>(version[4]), static_cast<unsigned char>(version[5]),
95  static_cast<unsigned char>(version[6]), static_cast<unsigned char>(version[7]),
96  static_cast<unsigned char>(version[8]), static_cast<unsigned char>(version[9]),
97  static_cast<unsigned char>(version[10]), static_cast<unsigned char>(version[11]),
98  static_cast<unsigned char>(version[12]), static_cast<unsigned char>(version[13]),
99  static_cast<unsigned char>(version[14]), static_cast<unsigned char>(version[15]));
100  if (splitted_string.size() >= 3)
101  {
102  software_version_current = convertToInt(splitted_string[0]);
103  software_version_server = convertToInt(splitted_string[1]);
104 
105  if (splitted_string[2] == "No")
106  {
107  software_version_modified = false;
108  }
109  else
110  {
111  software_version_modified = true;
112  }
113  }
114  else
115  {
116  ROS_ERROR("Incorrect tactile sensor version format");
117  software_version_current = 0;
118  software_version_server = 0;
119  software_version_modified = false;
120  }
121  };
122 
129  virtual std::string get_software_version()
130  {
131  // concatenate versions in a string.
132  std::string full_version;
133 
134  std::stringstream ss;
135  if (software_version_modified)
136  {
137  ss << "current: " << software_version_current << " / server: " << software_version_server << " / MODIFIED";
138  }
139  else
140  {
141  ss << "current: " << software_version_current << " / server: " << software_version_server << " / not modified";
142  }
143 
144  full_version = ss.str();
145 
146  return full_version;
147  };
148 
149  std::string pcb_version;
150 
151  inline double convertToInt(std::string const &s)
152  {
153  std::istringstream i(s);
154  int x;
155  if (!(i >> x))
156  {
157  x = -1;
158  }
159  return x;
160  }
161 };
162 
163 class PST3Data
164  :
165  public GenericTactileData
166 {
167 public:
170  {
171  };
172 
173  PST3Data(const PST3Data &pst3)
175  pst3.manufacturer, pst3.serial_number,
179  pst3.pcb_version),
180  pressure(pst3.pressure), temperature(pst3.temperature),
181  debug_1(pst3.debug_1), debug_2(pst3.debug_2),
182  pressure_raw(pst3.pressure_raw), zero_tracking(pst3.zero_tracking), dac_value(pst3.dac_value)
183  {
184  };
185 
186 
187  explicit PST3Data(const GenericTactileData &gtd)
189  gtd.manufacturer, gtd.serial_number,
193  gtd.pcb_version)
194  {
195  };
196 
198  {
199  };
200  int pressure;
202 
203  int debug_1;
204  int debug_2;
205 
208 
210 
217  virtual std::string get_software_version()
218  {
219  // concatenate versions in a string.
220  std::string full_version;
221 
222  std::stringstream ss;
223  ss << "current: " << software_version_current;
224 
225  full_version = ss.str();
226 
227  return full_version;
228  };
229 };
230 
232  :
233  public GenericTactileData
234 {
235 public:
238  {
239  pac_buffer_ = boost::circular_buffer<int16_t>(pac_size_);
240  pac_vector_.reserve(pac_size_);
241  };
242 
243  BiotacData(const BiotacData &btac)
245  btac.manufacturer, btac.serial_number,
249  btac.pcb_version),
250  pac0(btac.pac0), pac1(btac.pac1),
251  pdc(btac.pdc), tac(btac.tac),
252  tdc(btac.tdc)
253  {
254  electrodes = std::vector<int16_t>(btac.electrodes);
255  pac_vector_ = std::vector<int16_t>(btac.pac_vector_);
256  pac_buffer_ = boost::circular_buffer<int16_t>(btac.pac_buffer_);
257  };
258 
259  explicit BiotacData(const GenericTactileData &gtd)
261  gtd.manufacturer, gtd.serial_number,
265  gtd.pcb_version)
266  {
267  pac_buffer_ = boost::circular_buffer<int16_t>(pac_size_);
268  pac_vector_.reserve(pac_size_);
269  };
270 
272  {
273  };
274 
275  std::vector<int16_t> get_pac(bool consume = false)
276  {
277  pac_vector_.clear();
278  pac_vector_.insert(pac_vector_.begin(), pac_buffer_.begin(), pac_buffer_.end());
279  if (consume)
280  {
281  pac_buffer_.clear();
282  }
283  return pac_vector_;
284  }
285 
286  std::vector<int16_t> consume_pac()
287  {
288  return get_pac(true);
289  }
290 
291  int pac0; // always there, in word[0] and 1; int16u (2kHz)
292  int pac1; // int16u
293 
294  int pdc; // int16u in word[2]
295 
296  int tac; // int16u in word[2]
297  int tdc; // int16u in word[2]
298  std::vector<int16_t> electrodes; // int16u in word[2]
299  boost::circular_buffer<int16_t> pac_buffer_; // 2kHz history of int16u/word[2] values. Capacity of 270 samples is
300  // 135ms history
301  static const size_t pac_size_ = 270;
302 
303 private:
304  std::vector<int16_t> pac_vector_;
305 };
306 
307 class UBI0Data
308  :
309  public GenericTactileData
310 {
311 public:
314  {
315  };
316 
317  UBI0Data(const UBI0Data &ubi0)
319  ubi0.manufacturer, ubi0.serial_number,
323  ubi0.pcb_version)
324  {
325  for (unsigned int i = 0; i < ubi0.distal.size(); i++)
326  {
327  distal[i] = ubi0.distal[i];
328  }
329  for (unsigned int i = 0; i < ubi0.middle.size(); i++)
330  {
331  middle[i] = ubi0.middle[i];
332  }
333  for (unsigned int i = 0; i < ubi0.proximal.size(); i++)
334  {
335  proximal[i] = ubi0.proximal[i];
336  }
337  };
338 
339  explicit UBI0Data(const GenericTactileData &gtd)
341  gtd.manufacturer, gtd.serial_number,
345  gtd.pcb_version)
346  {
347  };
348 
350  {
351  };
352 
353 
354  boost::array<uint16_t, 12ul> distal;
355  boost::array<uint16_t, 4ul> middle;
356  boost::array<uint16_t, 4ul> proximal;
357 };
358 
360 {
361 public:
363  {
364  };
365 
367  {
368  for (unsigned int i = 0; i < ubi0.palm.size(); i++)
369  {
370  palm[i] = ubi0.palm[i];
371  }
372  };
373 
375  {
376  };
377 
378  boost::array<uint16_t, 16ul> palm;
379 };
380 
382 {
383  std::string type;
387 };
388 } // namespace tactiles
389 
390 /* For the emacs weenies in the crowd.
391  Local Variables:
392  c-basic-offset: 2
393  End:
394 */
395 
396 #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 Tue Oct 13 2020 03:55:41