Main Page
Namespaces
Namespace List
Namespace Members
All
Enumerations
Enumerator
Classes
Class List
Class Hierarchy
Class Members
All
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Functions
a
b
c
d
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
x
y
z
~
Variables
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
Enumerations
Enumerator
Files
File List
File Members
All
a
b
d
f
g
m
n
q
r
s
t
v
x
y
Functions
Typedefs
Macros
include
rm_common
linear_interpolation.h
Go to the documentation of this file.
1
//
2
// Created by yezi on 22-5-21.
3
//
4
5
#pragma once
6
#include <vector>
7
#include <
ros/ros.h
>
8
9
namespace
rm_common
10
{
11
class
LinearInterp
12
{
13
public
:
14
LinearInterp
() =
default
;
15
void
init
(
XmlRpc::XmlRpcValue
& config)
16
{
17
ROS_ASSERT
(config.
getType
() ==
XmlRpc::XmlRpcValue::TypeArray
);
18
for
(
int
i = 0; i < config.
size
(); i++)
19
{
20
ROS_ASSERT
(config[i].getType() ==
XmlRpc::XmlRpcValue::TypeArray
);
21
ROS_ASSERT
(config[i].size() == 2);
22
ROS_ASSERT
(config[i][0].getType() ==
XmlRpc::XmlRpcValue::TypeDouble
||
23
config[i][0].getType() ==
XmlRpc::XmlRpcValue::TypeInt
);
24
ROS_ASSERT
(config[i][1].getType() ==
XmlRpc::XmlRpcValue::TypeDouble
||
25
config[i][1].getType() ==
XmlRpc::XmlRpcValue::TypeInt
);
26
if
(!
input_vector_
.empty())
27
if
((
double
)config[i][0] <
input_vector_
.back())
28
{
29
ROS_ERROR
(
"Please sort the point's abscissa from smallest to largest. %lf < %lf"
, (
double
)config[i][0],
30
input_vector_
.back());
31
return
;
32
}
33
input_vector_
.push_back(config[i][0]);
34
output_vector_
.push_back(config[i][1]);
35
}
36
}
37
double
output
(
double
input)
38
{
39
if
(input >=
input_vector_
.back())
40
return
output_vector_
.back();
41
else
if
(input <=
input_vector_
.front())
42
return
output_vector_
.front();
43
for
(
size_t
i = 0; i <
input_vector_
.size(); i++)
44
{
45
if
(input >=
input_vector_
[i] && input <=
input_vector_
[i + 1])
46
return
output_vector_
[i] +
47
((
output_vector_
[i + 1] -
output_vector_
[i]) / (
input_vector_
[i + 1] -
input_vector_
[i])) *
48
(input -
input_vector_
[i]);
49
}
50
ROS_ERROR
(
"The point's abscissa aren't sorted from smallest to largest."
);
51
return
0;
52
}
53
54
private
:
55
std::vector<double>
input_vector_
;
56
std::vector<double>
output_vector_
;
57
};
58
}
// namespace rm_common
XmlRpc::XmlRpcValue::size
int size() const
rm_common::LinearInterp
Definition:
linear_interpolation.h:11
ros.h
rm_common::LinearInterp::output
double output(double input)
Definition:
linear_interpolation.h:37
XmlRpc::XmlRpcValue::TypeInt
TypeInt
rm_common::LinearInterp::output_vector_
std::vector< double > output_vector_
Definition:
linear_interpolation.h:56
XmlRpc::XmlRpcValue::TypeDouble
TypeDouble
rm_common
Definition:
calibration_queue.h:43
rm_common::LinearInterp::LinearInterp
LinearInterp()=default
XmlRpc::XmlRpcValue::getType
const Type & getType() const
XmlRpc::XmlRpcValue::TypeArray
TypeArray
ROS_ERROR
#define ROS_ERROR(...)
ROS_ASSERT
#define ROS_ASSERT(cond)
rm_common::LinearInterp::input_vector_
std::vector< double > input_vector_
Definition:
linear_interpolation.h:55
rm_common::LinearInterp::init
void init(XmlRpc::XmlRpcValue &config)
Definition:
linear_interpolation.h:15
XmlRpc::XmlRpcValue
rm_common
Author(s):
autogenerated on Sun Apr 6 2025 02:22:01