Fawkes API
Fawkes Development Version
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
All
Classes
Namespaces
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
sinusoidal.cpp
1
2
/***************************************************************************
3
* sinusoidal.cpp - Sinusoidal interpolator
4
*
5
* Created: Tue Nov 18 11:27:44 2008
6
* Copyright 2008 Tim Niemueller [www.niemueller.de]
7
* 2008 Graeme McPhillips
8
* 2008 Stephen Marais
9
*
10
****************************************************************************/
11
12
/* This program is free software; you can redistribute it and/or modify
13
* it under the terms of the GNU General Public License as published by
14
* the Free Software Foundation; either version 2 of the License, or
15
* (at your option) any later version. A runtime exception applies to
16
* this software (see LICENSE.GPL_WRE file mentioned below for details).
17
*
18
* This program is distributed in the hope that it will be useful,
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
* GNU Library General Public License for more details.
22
*
23
* Read the full text in the LICENSE.GPL_WRE file in the doc directory.
24
*/
25
26
#include <utils/math/interpolation/sinusoidal.h>
27
28
#include <cmath>
29
30
namespace
fawkes {
31
#if 0
/* just to make Emacs auto-indent happy */
32
}
33
#endif
34
35
/** @class SinusoidalInterpolator <utils/math/interpolation/linear.h>
36
* Sinusoidal value interpolator.
37
* The interpolator creates intermediate points given a starting and and
38
* end point and time constraints. Times are supplied in a discrete unit like
39
* miliseconds or microseconds.
40
* The values are interpolated on a sinusoidal curve with a slow start, the
41
* greatest slope in the middle and then a slow down in the end. This
42
* interpolation is useful for example for smooth servo movements.
43
*
44
* The calculation is executed with the following equation:
45
* \f[
46
* \left(\frac{1}{2} \sin\left(\frac{1}{2} + \frac{t_\mathrm{current}}{t_\mathrm{end}} \pi \right) + \frac{1}{2}\right) \cdot (v_\mathrm{end} - v_\mathrm{start}) + v_\mathrm{start}
47
* \f]
48
*
49
* @author Tim Niemueller
50
* @author Graeme McPhillips
51
* @author Stephen Marais
52
*/
53
54
float
55
SinusoidalInterpolator::interpolate(
float
t_current,
float
t_end,
float
t_step,
56
float
v_start,
float
v_end)
57
{
58
return
( sin((-0.5 + (t_current / t_end)) * M_PI) / 2.0 + 0.5) * (v_end - v_start) + v_start;
59
}
60
61
62
}
// end namespace fawkes
src
libs
utils
math
interpolation
sinusoidal.cpp
Generated by
1.8.7