pose_utilities.cpp
Go to the documentation of this file.
2 
3 #include <string>
4 
5 bool poseIsValid(const tf::Pose& pose)
6 {
7  auto origin = pose.getOrigin();
8  if (std::isnan(origin.x()) || std::isnan(origin.y()) || std::isnan(origin.z()))
9  {
10  return false;
11  }
12 
13  auto rotation = pose.getRotation();
14  if (std::isnan(rotation.getAngle()))
15  {
16  return false;
17  }
18 
19  auto rotationAxis = rotation.getAxis();
20  if (std::isnan(rotationAxis.x()) || std::isnan(rotationAxis.y()) || std::isnan(rotationAxis.z()))
21  {
22  return false;
23  }
24 
25  return true;
26 }
27 
28 void writePoseToNxLib(tf::Pose const& pose, NxLibItem const& node)
29 {
30  // Initialize the node to be empty. This is necessary, because there is a bug in some versions of the NxLib that
31  // overwrites the whole transformation node with an identity transformation as soon as a new node in /Links gets
32  // created.
33  node.setNull();
34 
35  if (poseIsValid(pose))
36  {
37  auto origin = pose.getOrigin();
38  node[itmTranslation][0] = origin.x() * 1000; // ROS transformation is in
39  // meters, NxLib expects it to
40  // be in millimeters.
41  node[itmTranslation][1] = origin.y() * 1000;
42  node[itmTranslation][2] = origin.z() * 1000;
43 
44  auto rotation = pose.getRotation();
45  node[itmRotation][itmAngle] = rotation.getAngle();
46 
47  auto rotationAxis = rotation.getAxis();
48  node[itmRotation][itmAxis][0] = rotationAxis.x();
49  node[itmRotation][itmAxis][1] = rotationAxis.y();
50  node[itmRotation][itmAxis][2] = rotationAxis.z();
51  }
52  else
53  {
54  // Use an identity transformation as a reasonable default value.
55  node[itmTranslation][0] = 0;
56  node[itmTranslation][1] = 0;
57  node[itmTranslation][2] = 0;
58 
59  node[itmRotation][itmAngle] = 0;
60  node[itmRotation][itmAxis][0] = 1;
61  node[itmRotation][itmAxis][1] = 0;
62  node[itmRotation][itmAxis][2] = 0;
63  }
64 }
65 
66 tf::Pose poseFromNxLib(NxLibItem const& node)
67 {
68  tf::Pose pose;
69 
70  tf::Point origin;
71  origin.setX(node[itmTranslation][0].asDouble() / 1000); // NxLib
72  // transformation is
73  // in millimeters, ROS
74  // expects it to be in
75  // meters.
76  origin.setY(node[itmTranslation][1].asDouble() / 1000);
77  origin.setZ(node[itmTranslation][2].asDouble() / 1000);
78  pose.setOrigin(origin);
79 
80  tf::Vector3 rotationAxis(node[itmRotation][itmAxis][0].asDouble(), node[itmRotation][itmAxis][1].asDouble(),
81  node[itmRotation][itmAxis][2].asDouble());
82  tf::Quaternion rotation(rotationAxis, node[itmRotation][itmAngle].asDouble());
83  pose.setRotation(rotation);
84 
85  return pose;
86 }
87 
88 tf::Stamped<tf::Pose> poseFromNxLib(NxLibItem const& node, ros::Time const& timestamp, std::string const& frame)
89 {
90  return tf::Stamped<tf::Pose>(poseFromNxLib(node), timestamp, frame);
91 }
92 
93 tf::StampedTransform transformFromPose(geometry_msgs::PoseStamped const& pose, std::string const& childFrame)
94 {
95  tf::StampedTransform transform;
96 
97  poseMsgToTF(pose.pose, transform);
98  transform.stamp_ = pose.header.stamp;
99  transform.frame_id_ = pose.header.frame_id;
100  transform.child_frame_id_ = childFrame;
101 
102  return transform;
103 }
bool poseIsValid(const tf::Pose &pose)
TFSIMD_FORCE_INLINE void setRotation(const Quaternion &q)
tfScalar getAngle() const
tf::StampedTransform transformFromPose(geometry_msgs::PoseStamped const &pose, std::string const &childFrame)
TFSIMD_FORCE_INLINE void setX(tfScalar x)
TFSIMD_FORCE_INLINE void setY(tfScalar y)
TFSIMD_FORCE_INLINE void setZ(tfScalar z)
TFSIMD_FORCE_INLINE const tfScalar & x() const
std::string child_frame_id_
Vector3 getAxis() const
TFSIMD_FORCE_INLINE Vector3 & getOrigin()
tf::Pose poseFromNxLib(NxLibItem const &node)
void writePoseToNxLib(tf::Pose const &pose, NxLibItem const &node)
Quaternion getRotation() const
TFSIMD_FORCE_INLINE void setOrigin(const Vector3 &origin)
std::string frame_id_


ensenso_camera
Author(s): Ensenso
autogenerated on Thu May 16 2019 02:44:23