signals-cpp
Loading...
Searching...
No Matches
Integration.h
Go to the documentation of this file.
1#pragma once
2#include "signals/Signal.h"
3
16template<typename IntegratorType>
18{
27 template<typename T, typename BaseSignalSpec, typename TangentSignalSpec>
30 const double& tf,
31 const bool& insertIntoHistory = false)
32 {
33 double t0 = xInt.t();
34 double dt;
35 if (!signal_utils::getTimeDelta(dt, t0, tf))
36 {
37 return false;
38 }
39 return IntegratorType::integrate(xInt, x, t0, tf, insertIntoHistory);
40 }
41
52 template<typename T, typename BaseSignalSpec, typename TangentSignalSpec>
55 const double& >>>>>>> master tf,
56 const double& dt,
57 const bool& insertIntoHistory = false)
58 {
59 double t_k = xInt.t();
60 bool success = true;
61 while (t_k < tf && success)
62 {
63 double dt_k;
64 if (signal_utils::getTimeDelta(dt_k, t_k, tf, dt))
65 {
66 double t_kp1 = t_k + dt_k;
67 success &= IntegratorType::integrate(xInt, x, t_k, t_kp1, insertIntoHistory);
68 t_k = t_kp1;
69 }
70 else
71 {
72 success = false;
73 }
74 }
75 return success;
76 }
77};
78
83{
97 template<typename T, typename BaseSignalSpec, typename TangentSignalSpec>
100 const double& t0,
101 const double& tf,
102 const bool& insertIntoHistory)
103 {
104 double dt = tf - t0;
105 return xInt.update(tf, xInt() + x(tf) * dt, x(tf), insertIntoHistory);
106 }
107};
108
113{
127 template<typename T, typename BaseSignalSpec, typename TangentSignalSpec>
130 const double& t0,
131 const double& tf,
132 const bool& insertIntoHistory)
133 {
134 double dt = tf - t0;
135 return xInt.update(tf, xInt() + (x(t0) + x(tf)) * dt / 2.0, x(tf), insertIntoHistory);
136 }
137};
138
143{
157 template<typename BaseSignalSpec, typename TangentSignalSpec>
160 const double& t0,
161 const double& tf,
162 const bool& insertIntoHistory)
163 {
164 double dt = tf - t0;
165 return xInt.update(tf,
166 xInt() + (x(t0) + 4.0 * x((t0 + tf) / 2.0) + x(tf)) * dt / 6.0,
167 x(tf),
168 insertIntoHistory);
169 }
170};
171
172#define MAKE_INTEGRATOR(IntegratorName) typedef Integrator<IntegratorName##IntegratorSpec> IntegratorName##Integrator;
173
175MAKE_INTEGRATOR(Trapezoidal)
#define MAKE_INTEGRATOR(IntegratorName)
Definition Integration.h:172
Template class for time-series signals with interpolation, extrapolation, and derivative capabilities...
Definition Signal.h:63
double t() const
Get the current time of the signal.
Definition Signal.h:151
bool update(const double &_t, const BaseType &_x, bool insertHistory=false)
Update the signal with a new value at a given time, computing derivative automatically.
Definition Signal.h:270
bool getTimeDelta(double &dt, const double &t0, const double &tf, const double &dt_max=std::numeric_limits< double >::max())
Definition Utils.h:11
Specification for numerically integrating a black box function using Euler's method.
Definition Integration.h:83
static bool integrate(Signal< T, BaseSignalSpec, TangentSignalSpec > &xInt, const Signal< T, TangentSignalSpec, TangentSignalSpec > &x, const double &t0, const double &tf, const bool &insertIntoHistory)
Euler integration implementation.
Definition Integration.h:98
Base type for all integrators.
Definition Integration.h:18
static bool integrate(Signal< T, BaseSignalSpec, TangentSignalSpec > &xInt, const Signal< T, TangentSignalSpec, TangentSignalSpec > &x, const double &tf, const bool &insertIntoHistory=false)
Integrate a signal from the current time to the specified end time.
Definition Integration.h:28
static bool integrate(Signal< T, BaseSignalSpec, TangentSignalSpec > &xInt, const Signal< T, TangentSignalSpec, TangentSignalSpec > &x, const double & > > > > > > > master tf, const double &dt, const bool &insertIntoHistory=false)
Integrate a signal from the current time to the specified end time, chunked up into smaller integrati...
Definition Integration.h:53
Specification for numerically integrating a black box function using Simpson's method.
Definition Integration.h:143
static bool integrate(Signal< BaseSignalSpec, TangentSignalSpec > &xInt, const Signal< TangentSignalSpec, TangentSignalSpec > &x, const double &t0, const double &tf, const bool &insertIntoHistory)
Simpson integration implementation.
Definition Integration.h:158
Specification for numerically integrating a black box function using the Trapezoidal method.
Definition Integration.h:113
static bool integrate(Signal< T, BaseSignalSpec, TangentSignalSpec > &xInt, const Signal< T, TangentSignalSpec, TangentSignalSpec > &x, const double &t0, const double &tf, const bool &insertIntoHistory)
Trapezoidal integration implementation.
Definition Integration.h:128