UtilFunctions.h
Go to the documentation of this file.
1 //=================================================================================================
2 // Copyright (c) 2011, Stefan Kohlbrecher, TU Darmstadt
3 // All rights reserved.
4 
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above copyright
10 // notice, this list of conditions and the following disclaimer in the
11 // documentation and/or other materials provided with the distribution.
12 // * Neither the name of the Simulation, Systems Optimization and Robotics
13 // group, TU Darmstadt nor the names of its contributors may be used to
14 // endorse or promote products derived from this software without
15 // specific prior written permission.
16 
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //=================================================================================================
28 
29 #ifndef utilfunctions_h__
30 #define utilfunctions_h__
31 
32 #include <cmath>
34 
35 namespace util{
36 
37 static inline float normalize_angle_pos(float angle)
38 {
39  return fmod(fmod(angle, 2.0f*M_PI) + 2.0f*M_PI, 2.0f*M_PI);
40 }
41 
42 static inline float normalize_angle(float angle)
43 {
44  float a = normalize_angle_pos(angle);
45  if (a > M_PI){
46  a -= 2.0f*M_PI;
47  }
48  return a;
49 }
50 
51 static inline float sqr(float val)
52 {
53  return val*val;
54 }
55 
56 static inline int sign(int x)
57 {
58  return x > 0 ? 1 : -1;
59 }
60 
61 template<typename T>
62 static T toDeg(const T radVal)
63 {
64  return radVal * static_cast<T>(180.0 / M_PI);
65 }
66 
67 template<typename T>
68 static T toRad(const T degVal)
69 {
70  return degVal * static_cast<T>(M_PI / 180.0);
71 }
72 
73 static bool poseDifferenceLargerThan(const Eigen::Vector3f& pose1, const Eigen::Vector3f& pose2, float distanceDiffThresh, float angleDiffThresh)
74 {
75  //check distance
76  if ( ( (pose1.head<2>() - pose2.head<2>()).norm() ) > distanceDiffThresh){
77  return true;
78  }
79 
80  float angleDiff = (pose1.z() - pose2.z());
81 
82  if (angleDiff > M_PI) {
83  angleDiff -= M_PI * 2.0f;
84  } else if (angleDiff < -M_PI) {
85  angleDiff += M_PI * 2.0f;
86  }
87 
88  if (abs(angleDiff) > angleDiffThresh){
89  return true;
90  }
91  return false;
92 }
93 
94 static double getYawFromQuat(const geometry_msgs::Quaternion &quat)
95 {
96  return tf::getYaw(tf::Quaternion(quat.x, quat.y, quat.z, quat.w));
97 }
98 
99 }
100 
101 #endif
f
static double getYaw(const Quaternion &bt_q)
static float sqr(float val)
Definition: UtilFunctions.h:51
static double getYawFromQuat(const geometry_msgs::Quaternion &quat)
Definition: UtilFunctions.h:94
static float normalize_angle_pos(float angle)
Definition: UtilFunctions.h:37
static int sign(int x)
Definition: UtilFunctions.h:56
static float normalize_angle(float angle)
Definition: UtilFunctions.h:42
static T toRad(const T degVal)
Definition: UtilFunctions.h:68
static T toDeg(const T radVal)
Definition: UtilFunctions.h:62
INLINE Rall1d< T, V, S > abs(const Rall1d< T, V, S > &x)
static bool poseDifferenceLargerThan(const Eigen::Vector3f &pose1, const Eigen::Vector3f &pose2, float distanceDiffThresh, float angleDiffThresh)
Definition: UtilFunctions.h:73


hector_mapping
Author(s): Stefan Kohlbrecher
autogenerated on Sat Mar 12 2022 03:57:50