Nav2 Navigation Stack - jazzy
jazzy
ROS 2 Navigation Stack
nav2_amcl
include
nav2_amcl
angleutils.hpp
1
/*
2
* Player - One Hell of a Robot Server
3
* Copyright (C) 2000 Brian Gerkey & Kasper Stoy
4
* gerkey@usc.edu kaspers@robotics.usc.edu
5
*
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Lesser General Public
8
* License as published by the Free Software Foundation; either
9
* version 2.1 of the License, or (at your option) any later version.
10
*
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Lesser General Public License for more details.
15
*
16
* You should have received a copy of the GNU Lesser General Public
17
* License along with this library; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
*
20
*/
21
22
#ifndef NAV2_AMCL__ANGLEUTILS_HPP_
23
#define NAV2_AMCL__ANGLEUTILS_HPP_
24
25
#include <math.h>
26
27
namespace
nav2_amcl
28
{
29
30
/*
31
* @class angleutils
32
* @brief Some utilities for working with angles
33
*/
34
class
angleutils
35
{
36
public
:
37
/*
38
* @brief Normalize angles
39
* @brief z Angle to normalize
40
* @return normalized angle
41
*/
42
static
double
normalize(
double
z);
43
44
/*
45
* @brief Find minimum distance between 2 angles
46
* @brief a Angle 1
47
* @brief b Angle 2
48
* @return normalized angle difference
49
*/
50
static
double
angle_diff(
double
a,
double
b);
51
};
52
53
inline
double
54
angleutils::normalize(
double
z)
55
{
56
return
atan2(sin(z), cos(z));
57
}
58
59
inline
double
60
angleutils::angle_diff(
double
a,
double
b)
61
{
62
a = normalize(a);
63
b = normalize(b);
64
double
d1 = a - b;
65
double
d2 = 2 * M_PI - fabs(d1);
66
if
(d1 > 0) {
67
d2 *= -1.0;
68
}
69
if
(fabs(d1) < fabs(d2)) {
70
return
d1;
71
}
else
{
72
return
d2;
73
}
74
}
75
76
}
// namespace nav2_amcl
77
78
#endif
// NAV2_AMCL__ANGLEUTILS_HPP_
nav2_amcl::angleutils
Definition:
angleutils.hpp:35
Generated by
1.9.1