ros_file_format.h
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2017 Intel Corporation. All Rights Reserved.
3 
4 #pragma once
5 #include <string>
6 #include <chrono>
7 #include "librealsense2/rs.h"
9 #include "sensor_msgs/Imu.h"
10 #include "sensor_msgs/Image.h"
12 #include "std_msgs/UInt32.h"
13 #include "std_msgs/Float32.h"
15 #include "std_msgs/String.h"
20 #include "sensor_msgs/CameraInfo.h"
22 #include "geometry_msgs/Twist.h"
23 #include "geometry_msgs/Accel.h"
24 #include "metadata-parser.h"
25 #include "option.h"
26 #include "l500/l500-depth.h"
27 #include "rosbag/structures.h"
28 #include <regex>
29 #include "stream.h"
30 #include "types.h"
31 #include <vector>
32 
34 {
38 };
39 
40 
41 namespace librealsense
42 {
44  {
45  switch (source)
46  {
56  default: target = rs2_format_to_string(source);
57  }
58  }
59 
60  template <typename T>
61  inline bool convert(const std::string& source, T& target)
62  {
63  if (!try_parse(source, target))
64  {
65  LOG_INFO("Failed to convert source: " << source << " to matching " << typeid(T).name());
66  return false;
67  }
68  return true;
69  }
70 
71  // Specialized methods for selected types
72  template <>
73  inline bool convert(const std::string& source, rs2_format& target)
74  {
75  bool ret = true;
76  std::string source_alias("");
77  bool mapped_format = false;
79  target = RS2_FORMAT_Z16;
80  mapped_format = true;
81  }
83  target = RS2_FORMAT_Y8;
84  mapped_format = true;
85  }
87  target = RS2_FORMAT_Y16;
88  mapped_format = true;
89  }
91  target = RS2_FORMAT_RAW8;
92  mapped_format = true;
93  }
95  target = RS2_FORMAT_UYVY;
96  mapped_format = true;
97  }
102 
103  // formats that need to be mapped to sdk native formats (e.g. MONO16)
104  if (mapped_format)
105  source_alias = std::string(rs2_format_to_string(target));
106  else {
107  // formats that are same as the sdk native formats (e.g.rgb8),
108  // these need to be changed to upper case
109  // because values in sensor_msgs::image_encodings are lower case
110  source_alias = source;
111  std::transform(source_alias.begin(), source_alias.end(), source_alias.begin(), ::toupper);
112  }
113 
114  if (!(ret = try_parse(source_alias, target)))
115  {
116  LOG_INFO("Failed to convert source: " << source << " to matching rs2_format");
117  }
118  return ret;
119  }
120 
121  template <>
122  inline bool convert(const std::string& source, double& target)
123  {
124  target = std::stod(source);
125  return std::isfinite(target);
126  }
127 
128  template <>
129  inline bool convert(const std::string& source, long long& target)
130  {
131  target = std::stoll(source);
132  return true;
133  }
134  /*
135  quat2rot(), rot2quat()
136  ------------------
137 
138  rotation matrix is column major
139  m[3][3] <==> r[9]
140 
141  [00, 01, 02] <==> [ r[0], r[3], r[6] ]
142  m = [10, 11, 12] <==> [ r[1], r[4], r[7] ]
143  [20, 21, 22] <==> [ r[2], r[5], r[8] ]
144  */
145 
146  inline void quat2rot(const geometry_msgs::Transform::_rotation_type& q, float(&r)[9])
147  {
148  r[0] = 1 - 2 * q.y*q.y - 2 * q.z*q.z; // m00 = 1 - 2 * qy2 - 2 * qz2
149  r[3] = 2 * q.x*q.y - 2 * q.z*q.w; // m01 = 2 * qx*qy - 2 * qz*qw
150  r[6] = 2 * q.x*q.z + 2 * q.y*q.w; // m02 = 2 * qx*qz + 2 * qy*qw
151  r[1] = 2 * q.x*q.y + 2 * q.z*q.w; // m10 = 2 * qx*qy + 2 * qz*qw
152  r[4] = 1 - 2 * q.x*q.x - 2 * q.z*q.z; // m11 = 1 - 2 * qx2 - 2 * qz2
153  r[7] = 2 * q.y*q.z - 2 * q.x*q.w; // m12 = 2 * qy*qz - 2 * qx*qw
154  r[2] = 2 * q.x*q.z - 2 * q.y*q.w; // m20 = 2 * qx*qz - 2 * qy*qw
155  r[5] = 2 * q.y*q.z + 2 * q.x*q.w; // m21 = 2 * qy*qz + 2 * qx*qw
156  r[8] = 1 - 2 * q.x*q.x - 2 * q.y*q.y; // m22 = 1 - 2 * qx2 - 2 * qy2
157  }
158 
159  inline void rot2quat(const float(&r)[9], geometry_msgs::Transform::_rotation_type& q)
160  {
161  auto m = (float(&)[3][3])r; // column major
162  float tr[4];
163  tr[0] = ( m[0][0] + m[1][1] + m[2][2]);
164  tr[1] = ( m[0][0] - m[1][1] - m[2][2]);
165  tr[2] = (-m[0][0] + m[1][1] - m[2][2]);
166  tr[3] = (-m[0][0] - m[1][1] + m[2][2]);
167  if (tr[0] >= tr[1] && tr[0]>= tr[2] && tr[0] >= tr[3]) {
168  float s = 2 * std::sqrt(tr[0] + 1);
169  q.w = s/4;
170  q.x = (m[2][1] - m[1][2]) / s;
171  q.y = (m[0][2] - m[2][0]) / s;
172  q.z = (m[1][0] - m[0][1]) / s;
173  } else if (tr[1] >= tr[2] && tr[1] >= tr[3]) {
174  float s = 2 * std::sqrt(tr[1] + 1);
175  q.w = (m[2][1] - m[1][2]) / s;
176  q.x = s/4;
177  q.y = (m[1][0] + m[0][1]) / s;
178  q.z = (m[2][0] + m[0][2]) / s;
179  } else if (tr[2] >= tr[3]) {
180  float s = 2 * std::sqrt(tr[2] + 1);
181  q.w = (m[0][2] - m[2][0]) / s;
182  q.x = (m[1][0] + m[0][1]) / s;
183  q.y = s/4;
184  q.z = (m[1][2] + m[2][1]) / s;
185  } else {
186  float s = 2 * std::sqrt(tr[3] + 1);
187  q.w = (m[1][0] - m[0][1]) / s;
188  q.x = (m[0][2] + m[2][0]) / s;
189  q.y = (m[1][2] + m[2][1]) / s;
190  q.z = s/4;
191  }
192  q.w = -q.w; // column major
193  }
194 
196  {
197  target.translation[0] = source.translation.x;
198  target.translation[1] = source.translation.y;
199  target.translation[2] = source.translation.z;
200  quat2rot(source.rotation, target.rotation);
201  return true;
202  }
203 
205  {
206  target.translation.x = source.translation[0];
207  target.translation.y = source.translation[1];
208  target.translation.z = source.translation[2];
209  rot2quat(source.rotation, target.rotation);
210  return true;
211  }
212 
213  constexpr const char* FRAME_NUMBER_MD_STR = "Frame number";
214  constexpr const char* TIMESTAMP_DOMAIN_MD_STR = "timestamp_domain";
215  constexpr const char* SYSTEM_TIME_MD_STR = "system_time";
216  constexpr const char* MAPPER_CONFIDENCE_MD_STR = "Mapper Confidence";
217  constexpr const char* FRAME_TIMESTAMP_MD_STR = "frame_timestamp";
218  constexpr const char* TRACKER_CONFIDENCE_MD_STR = "Tracker Confidence";
219 
220  class ros_topic
221  {
222  public:
223  static constexpr const char* elements_separator() { return "/"; }
224  static constexpr const char* ros_image_type_str() { return "image"; }
225  static constexpr const char* ros_imu_type_str() { return "imu"; }
226  static constexpr const char* ros_pose_type_str() { return "pose"; }
227 
228  static uint32_t get_device_index(const std::string& topic)
229  {
230  return get_id("device_", get<1>(topic));
231  }
232 
233  static uint32_t get_sensor_index(const std::string& topic)
234  {
235  return get_id("sensor_", get<2>(topic));
236  }
237 
239  {
240  auto stream_with_id = get<3>(topic);
242  convert(stream_with_id.substr(0, stream_with_id.find_first_of("_")), type);
243  return type;
244  }
245 
246  static uint32_t get_stream_index(const std::string& topic)
247  {
248  auto stream_with_id = get<3>(topic);
249  return get_id(stream_with_id.substr(0, stream_with_id.find_first_of("_") + 1), get<3>(topic));
250  }
251 
253  {
255  }
256 
258  {
260  }
261 
263  {
264  return std::stoul(get<5>(topic));
265  }
266 
268  {
269  return get<4>(topic);
270  }
272  {
273  return create_from({ "file_version" });
274  }
276  {
277  return create_from({ device_prefix(device_id), "info" });
278  }
280  {
281  return create_from({ device_prefix(sensor_id.device_index), sensor_prefix(sensor_id.sensor_index), "info" });
282  }
284  {
285  return create_from({ stream_full_prefix(stream_id), "info" });
286  }
288  {
289  return create_from({ stream_full_prefix(stream_id), "info", "camera_info" });
290  }
292  {
293  return create_from({ stream_full_prefix(stream_id), "imu_intrinsic" });
294  }
295 
296  /*version 2 and down*/
298  {
299  return create_from({ device_prefix(sensor_id.device_index), sensor_prefix(sensor_id.sensor_index), "property" });
300  }
301 
302  /*version 3 and up*/
304  {
305  std::string topic_name = rs2_option_to_string(option_type);
306  std::replace(topic_name.begin(), topic_name.end(), ' ', '_');
307  return create_from({ device_prefix(sensor_id.device_index), sensor_prefix(sensor_id.sensor_index), "option", topic_name, "value" });
308  }
309 
311  {
312  return create_from({ device_prefix(sensor_id.device_index), sensor_prefix(sensor_id.sensor_index), "post_processing" });
313  }
314 
316  {
317  return create_from({ device_prefix(sensor_id.device_index), sensor_prefix(sensor_id.sensor_index), "l500_data" });
318  }
319 
320  /*version 3 and up*/
322  {
323  std::string topic_name = rs2_option_to_string(option_type);
324  std::replace(topic_name.begin(), topic_name.end(), ' ', '_');
325  return create_from({ device_prefix(sensor_id.device_index), sensor_prefix(sensor_id.sensor_index), "option", topic_name, "description" });
326  }
327 
329  {
330  assert(stream_id.stream_type == RS2_STREAM_POSE);
331  return create_from({ stream_full_prefix(stream_id), stream_to_ros_type(stream_id.stream_type), "transform", "data" });
332  }
333 
335  {
336  assert(stream_id.stream_type == RS2_STREAM_POSE);
337  return create_from({ stream_full_prefix(stream_id), stream_to_ros_type(stream_id.stream_type), "accel", "data" });
338  }
340  {
341  assert(stream_id.stream_type == RS2_STREAM_POSE);
342  return create_from({ stream_full_prefix(stream_id), stream_to_ros_type(stream_id.stream_type),"twist", "data" });
343  }
344 
346  {
347  return create_from({ stream_full_prefix(stream_id), stream_to_ros_type(stream_id.stream_type), "data" });
348  }
349 
351  {
352  return create_from({ stream_full_prefix(stream_id), stream_to_ros_type(stream_id.stream_type), "metadata" });
353  }
354 
356  {
357  return create_from({ stream_full_prefix(stream_id), "tf", std::to_string(ref_id) });
358  }
359 
361  {
362  return create_from({ "additional_info" });
363  }
364 
366  {
367  return create_from({ device_prefix(stream_id.device_index), sensor_prefix(stream_id.sensor_index), stream_prefix(stream_id.stream_type, stream_id.stream_index) }).substr(1); //substr(1) to remove the first "/"
368  }
369 
371  {
372  return create_from({ device_prefix(sensor_id.device_index), sensor_prefix(sensor_id.sensor_index), "notification", rs2_notification_category_to_string(nc)});
373  }
374 
375  template<uint32_t index>
376  static std::string get(const std::string& value)
377  {
378  size_t current_pos = 0;
379  std::string value_copy = value;
380  uint32_t elements_iterator = 0;
381  const auto seperator_length = std::string(elements_separator()).length();
382  while ((current_pos = value_copy.find(elements_separator())) != std::string::npos)
383  {
384  auto token = value_copy.substr(0, current_pos);
385  if (elements_iterator == index)
386  {
387  return token;
388  }
389  value_copy.erase(0, current_pos + seperator_length);
390  ++elements_iterator;
391  }
392 
393  if (elements_iterator == index)
394  return value_copy;
395 
396  throw std::out_of_range(to_string() << "Requeted index \"" << index << "\" is out of bound of topic: \"" << value << "\"");
397  }
398  private:
400  {
401  switch (type)
402  {
404  case RS2_STREAM_DEPTH:
405  case RS2_STREAM_COLOR:
406  case RS2_STREAM_INFRARED:
407  case RS2_STREAM_FISHEYE:
408  return ros_image_type_str();
409 
410  case RS2_STREAM_GYRO:
411  case RS2_STREAM_ACCEL:
412  return ros_imu_type_str();
413 
414  case RS2_STREAM_POSE:
415  return ros_pose_type_str();
416  }
417  throw io_exception(to_string() << "Unknown stream type when resolving ros type: " << type);
418  }
419  static std::string create_from(const std::vector<std::string>& parts)
420  {
421  std::ostringstream oss;
422  oss << elements_separator();
423  if (parts.empty() == false)
424  {
425  std::copy(parts.begin(), parts.end() - 1, std::ostream_iterator<std::string>(oss, elements_separator()));
426  oss << parts.back();
427  }
428  return oss.str();
429  }
430 
431 
432  static uint32_t get_id(const std::string& prefix, const std::string& str)
433  {
434  if (str.compare(0, prefix.size(), prefix) != 0)
435  {
436  throw std::runtime_error("Failed to get id after prefix \"" + prefix + "\"from string \"" + str + "\"");
437  }
438 
439  std::string id_str = str.substr(prefix.size());
440  return static_cast<uint32_t>(std::stoll(id_str));
441  }
442 
444  {
445  return "device_" + std::to_string(device_id);
446  }
448  {
449  return "sensor_" + std::to_string(sensor_id);
450  }
452  {
453  return std::string(rs2_stream_to_string(type)) + "_" + std::to_string(stream_id);
454  }
455  };
456 
457  class FalseQuery {
458  public:
459  bool operator()(rosbag::ConnectionInfo const* info) const { return false; }
460  };
461 
463  {
464  public:
465  MultipleRegexTopicQuery(const std::vector<std::string>& regexps)
466  {
467  for (auto&& regexp : regexps)
468  {
469  LOG_DEBUG("RegexTopicQuery with expression: " << regexp);
470  _exps.emplace_back(regexp);
471  }
472  }
473 
475  {
476  return std::any_of(std::begin(_exps), std::end(_exps), [info](const std::regex& exp) { return std::regex_search(info->topic, exp); });
477  }
478 
479  private:
480  std::vector<std::regex> _exps;
481  };
482 
484  {
485  public:
487  {
488  }
489 
491  { //Either "image" or "imu" or "pose/transform"
492  return to_string() << ros_topic::ros_image_type_str() << "|" << ros_topic::ros_imu_type_str() << "|" << ros_topic::ros_pose_type_str() << "/transform";
493  }
494 
496  {
497  return to_string() << "/device_" << stream_id.device_index
498  << "/sensor_" << stream_id.sensor_index
499  << "/" << get_string(stream_id.stream_type) << "_" << stream_id.stream_index;
500  }
501 
502  private:
504  };
505 
507  {
508  public:
509  SensorInfoQuery(uint32_t device_index) : RegexTopicQuery(to_string() << "/device_" << device_index << R"RRR(/sensor_(\d)+/info)RRR") {}
510  };
511 
513  {
514  public:
515  //TODO: Improve readability and robustness of expressions
516  FrameQuery() : RegexTopicQuery(to_string() << R"RRR(/device_\d+/sensor_\d+/.*_\d+)RRR" << "/(" << data_msg_types() << ")/data") {}
517  };
518 
520  {
521  public:
523  RegexTopicQuery(to_string() << stream_prefix(stream_id)
524  << "/(" << data_msg_types() << ")/data")
525  {
526  }
527  };
528 
530  {
531  public:
533  RegexTopicQuery(to_string() << stream_prefix(stream_id) << "/tf")
534  {
535  }
536  };
537 
539  {
540  public:
542  RegexTopicQuery(to_string() << R"RRR(/device_\d+/sensor_\d+/option/.*/value)RRR") {}
543  };
544 
546  {
547  public:
549  RegexTopicQuery(to_string() << R"RRR(/device_\d+/sensor_\d+/notification/.*)RRR") {}
550  };
556  {
558  }
559 
561  {
562  return ROS_FILE_VERSION_2;
563  }
564 
566  {
567  return 0; //TODO: change once SDK file supports multiple devices
568  }
569 
571  {
573  }
574 
576  {
577  if (t == rs2rosinternal::TIME_MIN)
579 
581  }
582 
584  {
587 
588  auto secs = std::chrono::duration_cast<std::chrono::duration<double>>(t);
589  return rs2rosinternal::Time(secs.count());
590  }
591 
592  namespace legacy_file_format
593  {
594  constexpr const char* USB_DESCRIPTOR = "{ 0x94b5fb99, 0x79f2, 0x4d66,{ 0x85, 0x06, 0xb1, 0x5e, 0x8b, 0x8c, 0x9d, 0xa1 } }";
595  constexpr const char* DEVICE_INTERFACE_VERSION = "{ 0xafcd9c11, 0x52e3, 0x4258,{ 0x8d, 0x23, 0xbe, 0x86, 0xfa, 0x97, 0xa0, 0xab } }";
596  constexpr const char* FW_VERSION = "{ 0x7b79605b, 0x5e36, 0x4abe,{ 0xb1, 0x01, 0x94, 0x86, 0xb8, 0x9a, 0xfe, 0xbe } }";
597  constexpr const char* CENTRAL_VERSION = "{ 0x5652ffdb, 0xacac, 0x47ea,{ 0xbf, 0x65, 0x73, 0x3e, 0xf3, 0xd9, 0xe2, 0x70 } }";
598  constexpr const char* CENTRAL_PROTOCOL_VERSION = "{ 0x50376dea, 0x89f4, 0x4d70,{ 0xb1, 0xb0, 0x05, 0xf6, 0x07, 0xb6, 0xae, 0x8a } }";
599  constexpr const char* EEPROM_VERSION = "{ 0x4617d177, 0xb546, 0x4747,{ 0x9d, 0xbf, 0x4f, 0xf8, 0x99, 0x0c, 0x45, 0x6b } }";
600  constexpr const char* ROM_VERSION = "{ 0x16a64010, 0xfee4, 0x4c67,{ 0xae, 0xc5, 0xa0, 0x4d, 0xff, 0x06, 0xeb, 0x0b } }";
601  constexpr const char* TM_DEVICE_TYPE = "{ 0x1212e1d5, 0xfa3e, 0x4273,{ 0x9e, 0xbf, 0xe4, 0x43, 0x87, 0xbe, 0xe5, 0xe8 } }";
602  constexpr const char* HW_VERSION = "{ 0x4439fcca, 0x8673, 0x4851,{ 0x9b, 0xb6, 0x1a, 0xab, 0xbd, 0x74, 0xbd, 0xdc } }";
603  constexpr const char* STATUS = "{ 0x5d6c6637, 0x28c7, 0x4a90,{ 0xab, 0x35, 0x90, 0xb2, 0x1f, 0x1a, 0xe6, 0xb8 } }";
604  constexpr const char* STATUS_CODE = "{ 0xe22a94a6, 0xed64, 0x46ea,{ 0x81, 0x52, 0x6a, 0xb3, 0x0b, 0x0e, 0x2a, 0x18 } }";
605  constexpr const char* EXTENDED_STATUS = "{ 0xff6e50db, 0x3c5f, 0x43e7,{ 0xb4, 0x82, 0xb8, 0xc3, 0xa6, 0x8e, 0x78, 0xcd } }";
606  constexpr const char* SERIAL_NUMBER = "{ 0x7d3e44e7, 0x8970, 0x4a32,{ 0x8e, 0xee, 0xe8, 0xd1, 0xd1, 0x32, 0xa3, 0x22 } }";
607  constexpr const char* TIMESTAMP_SORT_TYPE = "{ 0xb409b217, 0xe5cd, 0x4a04,{ 0x9e, 0x85, 0x1a, 0x7d, 0x59, 0xd7, 0xe5, 0x61 } }";
608 
609  constexpr const char* DEPTH = "DEPTH";
610  constexpr const char* COLOR = "COLOR";
611  constexpr const char* INFRARED = "INFRARED";
612  constexpr const char* FISHEYE = "FISHEYE";
613  constexpr const char* ACCEL = "ACCLEROMETER"; //Yes, there is a typo, that's how it is saved.
614  constexpr const char* GYRO = "GYROMETER";
615  constexpr const char* POSE = "rs_6DoF";
616 
617  constexpr uint32_t actual_exposure = 0; // float RS2_FRAME_METADATA_ACTUAL_EXPOSURE
618  constexpr uint32_t actual_fps = 1; // float
619  constexpr uint32_t frame_counter = 2; // float RS2_FRAME_METADATA_FRAME_COUNTER
620  constexpr uint32_t frame_timestamp = 3; // float RS2_FRAME_METADATA_FRAME_TIMESTAMP
621  constexpr uint32_t sensor_timestamp = 4; // float RS2_FRAME_METADATA_SENSOR_TIMESTAMP
622  constexpr uint32_t gain_level = 5; // float RS2_FRAME_METADATA_GAIN_LEVEL
623  constexpr uint32_t auto_exposure = 6; // float RS2_FRAME_METADATA_AUTO_EXPOSURE
624  constexpr uint32_t white_balance = 7; // float RS2_FRAME_METADATA_WHITE_BALANCE
625  constexpr uint32_t time_of_arrival = 8; // float RS2_FRAME_METADATA_TIME_OF_ARRIVAL
626  constexpr uint32_t SYSTEM_TIMESTAMP = 65536; // int64
627  constexpr uint32_t TEMPRATURE = 65537; // float
628  constexpr uint32_t EXPOSURE_TIME = 65538; // uint32_t
629  constexpr uint32_t FRAME_LENGTH = 65539; // uint32_t
630  constexpr uint32_t ARRIVAL_TIMESTAMP = 65540; // int64
631  constexpr uint32_t CONFIDENCE = 65541; // uint32
632 
634  {
635  switch (type)
636  {
637  case actual_exposure: res = RS2_FRAME_METADATA_ACTUAL_EXPOSURE; break;
638  //Not supported case actual_fps: ;
639  case frame_counter: res = RS2_FRAME_METADATA_FRAME_COUNTER; break;
640  case frame_timestamp: res = RS2_FRAME_METADATA_FRAME_TIMESTAMP; break;
641  case sensor_timestamp: res = RS2_FRAME_METADATA_SENSOR_TIMESTAMP; break;
642  case gain_level: res = RS2_FRAME_METADATA_GAIN_LEVEL; break;
643  case auto_exposure: res = RS2_FRAME_METADATA_AUTO_EXPOSURE; break;
644  case white_balance: res = RS2_FRAME_METADATA_WHITE_BALANCE; break;
645  case time_of_arrival: res = RS2_FRAME_METADATA_TIME_OF_ARRIVAL; break;
646  //Not supported here case SYSTEM_TIMESTAMP:
647  //Not supported case TEMPRATURE: res = RS2_FRAME_METADATA_;
648  case EXPOSURE_TIME: res = RS2_FRAME_METADATA_SENSOR_TIMESTAMP; break;
649  //Not supported case FRAME_LENGTH: res = RS2_FRAME_METADATA_;
650  case ARRIVAL_TIMESTAMP: res = RS2_FRAME_METADATA_TIME_OF_ARRIVAL; break;
651  //Not supported case CONFIDENCE: res = RS2_FRAME_METADATA_;
652  default:
653  return false;
654  }
655  return true;
656  }
658  {
659  switch (source)
660  {
661  case 0 /*camera*/: //[[fallthrough]]
662  case 1 /*microcontroller*/ :
664  case 2: return RS2_TIMESTAMP_DOMAIN_SYSTEM_TIME;
665  }
666  throw std::runtime_error(to_string() << "Unknown timestamp domain: " << source);
667  }
668 
670  {
671  const size_t number_of_hexadecimal_values_in_a_guid = 11;
672  const std::string left_group = R"RE(\s*(0x[0-9a-fA-F]{1,8})\s*,\s*(0x[0-9a-fA-F]{1,4})\s*,\s*(0x[0-9a-fA-F]{1,4})\s*,\s*)RE";
673  const std::string right_group = R"RE(\s*(0x[0-9a-fA-F]{1,2})\s*,\s*(0x[0-9a-fA-F]{1,2})\s*,\s*(0x[0-9a-fA-F]{1,2})\s*,\s*(0x[0-9a-fA-F]{1,2})\s*,\s*(0x[0-9a-fA-F]{1,2})\s*,\s*(0x[0-9a-fA-F]{1,2})\s*,\s*(0x[0-9a-fA-F]{1,2})\s*,\s*(0x[0-9a-fA-F]{1,2})\s*)RE";
674  const std::string guid_regex_pattern = R"RE(\{)RE" + left_group + R"RE(\{)RE" + right_group + R"RE(\}\s*\})RE";
675  //The GUID pattern looks like this: "{ 0x________, 0x____, 0x____, { 0x__, 0x__, 0x__, ... , 0x__ } }"
676 
677  std::regex reg(guid_regex_pattern, std::regex_constants::icase);
678  const std::map<rs2_camera_info, const char*> legacy_infos{
679  { RS2_CAMERA_INFO_SERIAL_NUMBER , SERIAL_NUMBER },
680  { RS2_CAMERA_INFO_FIRMWARE_VERSION , FW_VERSION },
681  { RS2_CAMERA_INFO_PHYSICAL_PORT , USB_DESCRIPTOR },
682  };
683  for (auto&& s : legacy_infos)
684  {
685  if (std::regex_match(s.second, reg))
686  {
687  out = s.first;
688  return true;
689  }
690  }
691  return false;
692  }
693 
694  constexpr uint32_t file_version()
695  {
696  return 1u;
697  }
698 
700  {
701  return file_version();
702  }
703 
705  {
706  //Other than 6DOF, streams are in the form of "<stream_type><stream_index>" where "stream_index" is empty for index 0/1 and the actual number for 2 and above
707  //6DOF is in the form "rs_6DoF<stream_index>" where "stream_index" is a zero based index
709  switch (source.type)
710  {
711  case RS2_STREAM_DEPTH: name = DEPTH; break;
712  case RS2_STREAM_COLOR: name = COLOR; break;
713  case RS2_STREAM_INFRARED: name = INFRARED; break;
714  case RS2_STREAM_FISHEYE: name = FISHEYE; break;
715  case RS2_STREAM_GYRO: name = GYRO; break;
716  case RS2_STREAM_ACCEL: name = ACCEL; break;
717  case RS2_STREAM_POSE: name = POSE; break;
718  default:
719  throw io_exception(to_string() << "Unknown stream type : " << source.type);
720  }
721  if (source.type == RS2_STREAM_POSE)
722  {
723  return name + std::to_string(source.index);
724  }
725  else
726  {
727  if (source.index == 1)
728  {
729  throw io_exception(to_string() << "Unknown index for type : " << source.type << ", index = " << source.index);
730  }
731  return name + (source.index == 0 ? "" : std::to_string(source.index));
732  }
733  }
734 
736  {
737  stream_descriptor retval{};
738  auto starts_with = [source](const std::string& s) {return source.find(s) == 0; };
739  std::string type_str;
740  if (starts_with(DEPTH))
741  {
742  retval.type = RS2_STREAM_DEPTH;
743  type_str = DEPTH;
744  }
745  else if (starts_with(COLOR))
746  {
747  retval.type = RS2_STREAM_COLOR;
748  type_str = COLOR;
749  }
750  else if (starts_with(INFRARED))
751  {
752  retval.type = RS2_STREAM_INFRARED;
753  type_str = INFRARED;
754  }
755  else if (starts_with(FISHEYE))
756  {
757  retval.type = RS2_STREAM_FISHEYE;
758  type_str = FISHEYE;
759  }
760  else if (starts_with(ACCEL))
761  {
762  retval.type = RS2_STREAM_ACCEL;
763  type_str = ACCEL;
764  }
765  else if (starts_with(GYRO))
766  {
767  retval.type = RS2_STREAM_GYRO;
768  type_str = GYRO;
769  }
770  else if (starts_with(POSE))
771  {
772  retval.type = RS2_STREAM_POSE;
773  auto index_str = source.substr(std::string(POSE).length());
774  retval.index = std::stoi(index_str);
775  return retval;
776  }
777  else
778  throw io_exception(to_string() << "Unknown stream type : " << source);
779 
780  auto index_str = source.substr(type_str.length());
781  if (index_str.empty())
782  {
783 
784  retval.index = 0;
785  }
786  else
787  {
788  int index = std::stoi(index_str);
789  assert(index != 1);
790  retval.index = index;
791  }
792  return retval;
793  }
794 
796  {
797  public:
798  //Possible patterns:
799  // /camera/<CAMERA_STREAM_TYPE><id>/image_raw/0
800  // /camera/rs_6DoF<id>/0
801  // /imu/ACCELEROMETER/imu_raw/0
802  // /imu/GYROMETER/imu_raw/0
804  to_string() << R"RRR(/(camera|imu)/.*/(image|imu)_raw/\d+)RRR" ,
805  to_string() << R"RRR(/camera/rs_6DoF\d+/\d+)RRR" }) {}
806  };
807 
808  inline bool is_camera(rs2_stream s)
809  {
810  return
811  s == RS2_STREAM_DEPTH ||
812  s == RS2_STREAM_COLOR ||
813  s == RS2_STREAM_INFRARED ||
814  s == RS2_STREAM_FISHEYE ||
815  s == RS2_STREAM_POSE;
816  }
817 
819  {
820  public:
823  << (is_camera(stream_id.stream_type) ? "/camera/" : "/imu/")
824  << stream_type_to_string({ stream_id.stream_type, (int)stream_id.stream_index})
825  << ((stream_id.stream_type == RS2_STREAM_POSE) ? "/" : (is_camera(stream_id.stream_type)) ? "/image_raw/" : "/imu_raw/")
826  << stream_id.sensor_index)
827  {
828  }
829  };
830 
832  {
833  public:
836  << (is_camera(stream_id.stream_type) ? "/camera/" : "/imu/")
837  << stream_type_to_string({ stream_id.stream_type, (int)stream_id.stream_index })
838  << "/rs_frame_info_ext/" << stream_id.sensor_index)
839  {
840  }
841  };
843  {
844  auto stream = parse_stream_type(ros_topic::get<2>(topic));
845  uint32_t sensor_index;
846  if(stream.type == RS2_STREAM_POSE)
847  sensor_index = static_cast<uint32_t>(std::stoll(ros_topic::get<3>(topic)));
848  else
849  sensor_index = static_cast<uint32_t>(std::stoll(ros_topic::get<4>(topic)));
850 
851  return device_serializer::stream_identifier{ 0u, static_cast<uint32_t>(sensor_index), stream.type, static_cast<uint32_t>(stream.index) };
852  }
853 
855  {
856  return "/FILE_VERSION";
857  }
858  }
859 }
rs2_camera_info
Read-only strings that can be queried from the device. Not all information attributes are available o...
Definition: rs_sensor.h:22
constexpr uint32_t get_file_version()
static std::string frame_data_topic(const device_serializer::stream_identifier &stream_id)
const char * rs2_format_to_string(rs2_format format)
Definition: rs.cpp:1263
SensorInfoQuery(uint32_t device_index)
constexpr uint32_t ARRIVAL_TIMESTAMP
GLuint GLuint end
constexpr uint32_t file_version()
void rot2quat(const float(&r)[9], geometry_msgs::Transform::_rotation_type &q)
static std::string post_processing_blocks_topic(const device_serializer::sensor_identifier &sensor_id)
constexpr const char * FRAME_NUMBER_MD_STR
constexpr const char * DEPTH
static std::string l500_data_blocks_topic(const device_serializer::sensor_identifier &sensor_id)
const char * get_string(rs2_rs400_visual_preset value)
GLuint const GLchar * name
static std::string sensor_info_topic(const device_serializer::sensor_identifier &sensor_id)
StreamQuery(const device_serializer::stream_identifier &stream_id)
rs2_option
Defines general configuration controls. These can generally be mapped to camera UVC controls...
Definition: rs_option.h:22
GLdouble s
static std::string get_option_name(const std::string &topic)
device_serializer::nanoseconds to_nanoseconds(const rs2rosinternal::Time &t)
const GLfloat * m
Definition: glext.h:6814
constexpr const char * TM_DEVICE_TYPE
float translation[3]
Definition: rs_sensor.h:99
static std::string stream_to_ros_type(rs2_stream type)
rs2rosinternal::Time to_rostime(const device_serializer::nanoseconds &t)
const char * rs2_option_to_string(rs2_option option)
Definition: rs.cpp:1265
constexpr const char * FRAME_TIMESTAMP_MD_STR
constexpr const char * TIMESTAMP_SORT_TYPE
static std::string stream_extrinsic_topic(const device_serializer::stream_identifier &stream_id, uint32_t ref_id)
static uint32_t get_device_index(const std::string &topic)
GLfloat value
static uint32_t get_sensor_index(const std::string &topic)
static std::string video_stream_info_topic(const device_serializer::stream_identifier &stream_id)
constexpr const char * ACCEL
void convert(rs2_format source, std::string &target)
static std::string additional_info_topic()
static uint32_t get_id(const std::string &prefix, const std::string &str)
static std::string device_info_topic(uint32_t device_id)
GLsizei const GLchar *const * string
constexpr const char * TRACKER_CONFIDENCE_MD_STR
Exposes librealsense functionality for C compilers.
bool convert_metadata_type(uint64_t type, rs2_frame_metadata_value &res)
float rotation[9]
Definition: rs_sensor.h:98
static std::string device_prefix(uint32_t device_id)
GLuint index
GLdouble t
static device_serializer::stream_identifier get_stream_identifier(const std::string &topic)
def info(name, value, persistent=False)
Definition: test.py:301
not_this_one begin(...)
RegexTopicQuery(std::string const &regexp)
std::string stream_type_to_string(const stream_descriptor &source)
static device_serializer::sensor_identifier get_sensor_identifier(const std::string &topic)
GLdouble GLdouble r
constexpr const char * HW_VERSION
static std::string stream_prefix(const device_serializer::stream_identifier &stream_id)
unsigned int uint32_t
Definition: stdint.h:80
static constexpr const char * ros_pose_type_str()
constexpr uint32_t get_maximum_supported_legacy_file_version()
static std::string pose_accel_topic(const device_serializer::stream_identifier &stream_id)
bool operator()(rosbag::ConnectionInfo const *info) const
constexpr const char * DEVICE_INTERFACE_VERSION
constexpr const char * EEPROM_VERSION
constexpr const char * SERIAL_NUMBER
Time representation. May either represent wall clock time or ROS clock time.
Definition: time.h:177
GLenum target
Definition: glext.h:1565
static std::string notification_topic(const device_serializer::sensor_identifier &sensor_id, rs2_notification_category nc)
unsigned __int64 uint64_t
Definition: stdint.h:90
constexpr const char * FW_VERSION
FrameInfoExt(const device_serializer::stream_identifier &stream_id)
_rotation_type rotation
Definition: Transform.h:44
uint64_t toNSec() const
Definition: time.h:163
const std::string TYPE_16UC1
bool info_from_string(const std::string &str, rs2_camera_info &out)
rs2_format
A stream&#39;s format identifies how binary data is encoded within a frame.
Definition: rs_sensor.h:59
static std::string file_version_topic()
ros_file_versions
void quat2rot(const geometry_msgs::Transform::_rotation_type &q, float(&r)[9])
constexpr const char * INFRARED
static constexpr const char * ros_imu_type_str()
static std::string property_topic(const device_serializer::sensor_identifier &sensor_id)
constexpr const char * SYSTEM_TIME_MD_STR
ExtrinsicsQuery(const device_serializer::stream_identifier &stream_id)
static std::string stream_prefix(rs2_stream type, uint32_t stream_id)
static std::string imu_intrinsic_topic(const device_serializer::stream_identifier &stream_id)
constexpr const char * STATUS
constexpr const char * MAPPER_CONFIDENCE_MD_STR
constexpr const char * COLOR
rs2_stream
Streams are different types of data provided by RealSense devices.
Definition: rs_sensor.h:42
StreamQuery(const device_serializer::stream_identifier &stream_id)
constexpr const char * TIMESTAMP_DOMAIN_MD_STR
std::chrono::duration< uint64_t, std::nano > nanoseconds
constexpr const char * EXTENDED_STATUS
constexpr const char * FISHEYE
static std::string pose_twist_topic(const device_serializer::stream_identifier &stream_id)
bool operator()(rosbag::ConnectionInfo const *info) const
static std::string frame_metadata_topic(const device_serializer::stream_identifier &stream_id)
Cross-stream extrinsics: encodes the topology describing how the different devices are oriented...
Definition: rs_sensor.h:96
LOG_INFO("Log message using LOG_INFO()")
static constexpr const char * ros_image_type_str()
stream_descriptor parse_stream_type(const std::string &source)
MultipleRegexTopicQuery(const std::vector< std::string > &regexps)
GLdouble GLdouble GLdouble q
constexpr device_serializer::nanoseconds get_static_file_info_timestamp()
constexpr const char * USB_DESCRIPTOR
static uint32_t get_stream_index(const std::string &topic)
static std::string option_value_topic(const device_serializer::sensor_identifier &sensor_id, rs2_option option_type)
const char * rs2_stream_to_string(rs2_stream stream)
Definition: rs.cpp:1262
ROSTIME_DECL const Time TIME_MIN
rs2_notification_category
Category of the librealsense notification.
Definition: rs_types.h:17
int stream_id
Definition: sync.h:17
GLenum type
int min(int a, int b)
Definition: lz4s.c:73
long long stoll(const std::string &value)
constexpr uint32_t get_minimum_supported_file_version()
constexpr const char * CENTRAL_PROTOCOL_VERSION
static uint32_t get_extrinsic_group_index(const std::string &topic)
static rs2_stream get_stream_type(const std::string &topic)
static std::string option_description_topic(const device_serializer::sensor_identifier &sensor_id, rs2_option option_type)
GLsizei GLsizei GLchar * source
constexpr const char * ROM_VERSION
bool starts_with(const std::string &s, const std::string &prefix)
Definition: os.cpp:343
double stod(const std::string &value)
int stoi(const std::string &value)
_translation_type translation
Definition: Transform.h:41
static std::string sensor_prefix(uint32_t sensor_id)
GLenum GLuint GLenum GLsizei length
GLuint res
Definition: glext.h:8856
constexpr const char * STATUS_CODE
static std::string data_msg_types()
static constexpr const char * elements_separator()
static std::string pose_transform_topic(const device_serializer::stream_identifier &stream_id)
const char * rs2_notification_category_to_string(rs2_notification_category category)
Definition: rs.cpp:1268
GLuint GLenum GLenum transform
Definition: glext.h:11553
#define LOG_DEBUG(...)
Definition: src/types.h:239
constexpr const char * CENTRAL_VERSION
::std_msgs::Time_< std::allocator< void > > Time
Definition: Time.h:47
static std::string create_from(const std::vector< std::string > &parts)
rs2_frame_metadata_value
Per-Frame-Metadata is the set of read-only properties that might be exposed for each individual frame...
Definition: rs_frame.h:29
void copy(void *dst, void const *src, size_t size)
Definition: types.cpp:836
static std::string stream_info_topic(const device_serializer::stream_identifier &stream_id)
unsigned long stoul(const std::string &value)
static std::string stream_full_prefix(const device_serializer::stream_identifier &stream_id)
std::string to_string(T value)
rs2_timestamp_domain
Specifies the clock in relation to which the frame timestamp was measured.
Definition: rs_frame.h:19


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:40