conversion.cpp
Go to the documentation of this file.
2 
4 
5 #include <chrono>
6 #include <cmath>
7 
8 namespace ensenso_conversion
9 {
10 namespace
11 {
12 double const NXLIB_TIMESTAMP_OFFSET = 11644473600;
13 
14 double timeNowAsSeconds()
15 {
16  // TODO Check if this also works with Windows and Mac in ROS2
18  auto nanoseconds = std::chrono::duration_cast<std::chrono::nanoseconds>(t.time_since_epoch()).count();
19  return (double)nanoseconds / 1e09;
20 }
21 
22 double fixTimestamp(double const& timestamp, bool isFileCamera = false)
23 {
24  // Due to a bug in the NxLib of SDK 3.2.489, S-series file cameras have missing timestamps.
25  // TODO Remove this check as soon as we only support SDK versions that include the bug fix (SDK-2860).
26  if (std::isnan(timestamp))
27  {
28  ENSENSO_WARN("NxLib timestamp is \'nan\', using current ROS time instead.");
29  return timeNowAsSeconds();
30  }
31  else if (isFileCamera)
32  {
33  // File camera timestamps are too old for ROS, use the current time instead.
34  return timeNowAsSeconds();
35  }
36 
37  return timestamp - NXLIB_TIMESTAMP_OFFSET;
38 }
39 } // namespace
40 
41 double nxLibToRosTimestamp(double const& timestamp, bool isFileCamera)
42 {
43  return fixTimestamp(timestamp, isFileCamera);
44 }
45 
46 double nxLibToPclTimestamp(double const& timestamp, bool isFileCamera)
47 {
48  // PCL timestamp is in microseconds and Unix time.
49  return nxLibToRosTimestamp(timestamp, isFileCamera) * 1e6;
50 }
51 
52 geometry_msgs::msg::Point32 toRosPoint(NxLibItem const& itemArray, bool convertUnits)
53 {
54  geometry_msgs::msg::Point32 point;
55  if (convertUnits)
56  {
57  point.x = itemArray[0].asDouble() / conversionFactor;
58  point.y = itemArray[1].asDouble() / conversionFactor;
59  point.z = itemArray[2].asDouble() / conversionFactor;
60  }
61  else
62  {
63  point.x = itemArray[0].asDouble();
64  point.y = itemArray[1].asDouble();
65  point.z = itemArray[2].asDouble();
66  }
67 
68  return point;
69 }
70 
71 NxLibItem toEnsensoPoint(geometry_msgs::msg::Point32 const& point, bool convertUnits)
72 {
73  NxLibItem itemPoint;
74  if (convertUnits)
75  {
76  itemPoint[0] = point.x * conversionFactor;
77  itemPoint[1] = point.y * conversionFactor;
78  itemPoint[2] = point.z * conversionFactor;
79  }
80  else
81  {
82  itemPoint[0] = point.x;
83  itemPoint[1] = point.y;
84  itemPoint[2] = point.z;
85  }
86 
87  return itemPoint;
88 }
89 
90 } // namespace ensenso_conversion
NxLibItem toEnsensoPoint(geometry_msgs::msg::Point32 const &point, bool convertUnits=true)
Definition: conversion.cpp:71
double nxLibToPclTimestamp(double const &timestamp, bool isFileCamera=false)
Definition: conversion.cpp:46
geometry_msgs::TransformStamped t
inline ::ros::Time now(ensenso::ros::NodeHandle const &nh)
Definition: time.h:76
void ENSENSO_WARN(T... args)
Definition: logging.h:210
const int conversionFactor
Definition: conversion.h:16
double nxLibToRosTimestamp(double const &timestamp, bool isFileCamera=false)
Definition: conversion.cpp:41
geometry_msgs::msg::Point32 toRosPoint(NxLibItem const &itemArray, bool convertUnits=true)
Definition: conversion.cpp:52


ensenso_camera
Author(s): Ensenso
autogenerated on Sat Jun 3 2023 02:17:04