61template<
typename T,
typename BaseSignalSpec,
typename TangentSignalSpec>
65 using BaseType =
typename BaseSignalSpec::Type;
115 this->xdot_ = other.xdot_;
116 this->signalHistory_ = other.signalHistory_;
117 this->needsSort_ = other.needsSort_;
127 for (
auto signalDP : signalHistory_)
129 signalDot.
update(signalDP.t, signalDP.xdot,
true);
135 template<
typename S,
typename BSS,
typename TSS>
138 template<
typename S,
typename BSS,
typename TSS>
141 template<
typename S,
typename BSS,
typename TSS>
144 template<
typename S,
typename BSS,
typename TSS>
199 std::vector<BaseType>
operator()(
const std::vector<double>&
t)
const
201 std::vector<BaseType> xInterp;
202 for (
size_t i = 0; i <
t.size(); i++)
204 xInterp.push_back(xAt(
t[i]));
214 std::vector<TangentType>
dot(
const std::vector<double>&
t)
const
216 std::vector<TangentType> xDotInterp;
217 for (
size_t i = 0; i <
t.size(); i++)
219 xDotInterp.push_back(xDotAt(
t[i]));
257 x_ = BaseSignalSpec::ZeroType();
258 xdot_ = TangentSignalSpec::ZeroType();
259 signalHistory_.clear();
273 if (!calculateDerivative(_t, _x, _xdot))
277 return update(_t, _x, _xdot, insertHistory);
295 if (insertIntoHistory(_t, _x, _xdot))
318 bool update(
const std::vector<double>& _tHistory,
const std::vector<BaseType>& _xHistory)
320 size_t nTH = _tHistory.size();
321 size_t nXH = _xHistory.size();
326 for (
size_t i = 0; i < nXH; i++)
329 if (!calculateDerivative(_tHistory[i], _xHistory[i], _xdot))
333 if (!insertIntoHistory(_tHistory[i], _xHistory[i], _xdot))
353 bool update(
const std::vector<double>& _tHistory,
354 const std::vector<BaseType>& _xHistory,
355 const std::vector<TangentType>& _xdotHistory)
357 size_t nTH = _tHistory.size();
358 size_t nXH = _xHistory.size();
359 size_t nXDH = _xdotHistory.size();
360 if (nXH != nXDH || nXDH != nTH)
364 for (
size_t i = 0; i < nXH; i++)
366 if (!insertIntoHistory(_tHistory[i], _xHistory[i], _xdotHistory[i]))
385 return BaseSignalSpec::ZeroType();
394 return TangentSignalSpec::ZeroType();
404 return BaseSignalSpec::Norm(x);
414 return TangentSignalSpec::Norm(x);
421 std::vector<SignalDP> signalHistory_;
432 if (signalHistory_.size() > 0)
434 double mostRecentTime = signalHistory_[signalHistory_.size() - 1].t;
435 if (_t == mostRecentTime)
439 else if (_t < mostRecentTime)
444 signalHistory_.push_back({_t, _x, _xdot});
454 else if (signalHistory_.size() > 0)
456 int idx = getInterpIndex(
t);
457 if (idx < 0 || idx >=
static_cast<int>(signalHistory_.size()))
462 return BaseSignalSpec::NansType();
467 return signalHistory_[0].x;
471 return signalHistory_[signalHistory_.size() - 1].x;
476 return BaseSignalSpec::ZeroType();
487 dy = TangentSignalSpec::ZeroType();
491 double t1 = tAtIdx(idx);
492 double t2 = tAtIdx(idx + 1);
495 dy = (
t - t1) / (t2 - t1) * (y2 - y1);
499 double t0 = tAtIdx(idx - 1);
500 double t1 = tAtIdx(idx);
501 double t2 = tAtIdx(idx + 1);
502 double t3 = tAtIdx(idx + 2);
508 (
t - t1) / (t2 - t1) *
509 ((y2 - y1) + (t2 -
t) / (2. * (t2 - t1) * (t2 - t1)) *
510 (((t2 -
t) * (t2 * (y1 - y0) + t0 * (y2 - y1) - t1 * (y2 - y0))) / (t1 - t0) +
511 ((
t - t1) * (t3 * (y2 - y1) + t2 * (y3 - y1) - t1 * (y3 - y2))) / (t3 - t2)));
520 return BaseSignalSpec::ZeroType();
530 else if (signalHistory_.size() > 0)
532 int idx = getInterpIndex(
t);
533 if (idx < 0 || idx >=
static_cast<int>(signalHistory_.size()))
538 return TangentSignalSpec::NansType();
543 return signalHistory_[0].xdot;
547 return signalHistory_[signalHistory_.size() - 1].xdot;
552 return TangentSignalSpec::ZeroType();
563 dy = TangentSignalSpec::ZeroType();
567 double t1 = tAtIdx(idx);
568 double t2 = tAtIdx(idx + 1);
571 dy = (
t - t1) / (t2 - t1) * (y2 - y1);
575 double t0 = tAtIdx(idx - 1);
576 double t1 = tAtIdx(idx);
577 double t2 = tAtIdx(idx + 1);
578 double t3 = tAtIdx(idx + 2);
584 (
t - t1) / (t2 - t1) *
585 ((y2 - y1) + (t2 -
t) / (2. * (t2 - t1) * (t2 - t1)) *
586 (((t2 -
t) * (t2 * (y1 - y0) + t0 * (y2 - y1) - t1 * (y2 - y0))) / (t1 - t0) +
587 ((
t - t1) * (t3 * (y2 - y1) + t2 * (y3 - y1) - t1 * (y3 - y2))) / (t3 - t2)));
596 return TangentSignalSpec::ZeroType();
601 int getInterpIndex(
const double&
t)
const
603 if (
t < signalHistory_[0].
t)
607 else if (
t > signalHistory_[signalHistory_.size() - 1].t)
609 return static_cast<int>(signalHistory_.size());
613 for (
size_t i = 0; i < signalHistory_.size(); i++)
615 double t_i = signalHistory_[i].t;
616 double t_ip1 = tAtIdx(i + 1);
617 if (t_i <= t && t_ip1 >
t)
619 return static_cast<int>(i);
626 double tAtIdx(
const int& idx)
const
630 return signalHistory_[0].t +
static_cast<double>(idx);
632 else if (idx >= signalHistory_.size())
634 return signalHistory_[signalHistory_.size() - 1].t +
635 static_cast<double>(idx -
static_cast<int>(signalHistory_.size() - 1));
639 return signalHistory_[idx].t;
643 BaseType xAtIdx(
const int& idx)
const
647 return signalHistory_[0].x;
649 else if (idx >= signalHistory_.size())
651 return signalHistory_[signalHistory_.size() - 1].x;
655 return signalHistory_[idx].x;
663 return signalHistory_[0].xdot;
665 else if (idx >= signalHistory_.size())
667 return signalHistory_[signalHistory_.size() - 1].xdot;
671 return signalHistory_[idx].xdot;
678 const static double sigma = 0.05;
685 const double dt = _t - t_;
690 _xdot = (2. * sigma - dt) / (2. * sigma + dt) * xdot_ + 2. / (2. * sigma + dt) * dx;
699 _xdot = TangentSignalSpec::ZeroType();
711template<
typename T,
typename BaseSignalSpec,
typename TangentSignalSpec>
717 lpr.xdot_ += r.
dot(l.
t());
718 for (
auto& signalDP : lpr.signalHistory_)
720 signalDP.x += r(signalDP.t);
721 signalDP.xdot += r.
dot(signalDP.t);
732template<
typename T,
typename BaseSignalSpec,
typename TangentSignalSpec>
740 lmr.needsSort_ = l.needsSort_;
742 lmr.x_ = l() - r(l.
t());
743 lmr.xdot_ = l.
dot() - r.
dot(l.
t());
744 std::vector<double> tHistory;
745 std::vector<typename TangentSignalSpec::Type> xHistory;
746 std::vector<typename TangentSignalSpec::Type> xdotHistory;
747 for (
auto& signalDP : l.signalHistory_)
749 tHistory.push_back(signalDP.t);
750 xHistory.push_back(signalDP.x - r(signalDP.t));
751 xdotHistory.push_back(signalDP.xdot - r.
dot(signalDP.t));
753 lmr.
update(tHistory, xHistory, xdotHistory);
763template<
typename T,
typename BaseSignalSpec,
typename TangentSignalSpec>
770 for (
auto& signalDP : lr.signalHistory_)
784template<
typename T,
typename BaseSignalSpec,
typename TangentSignalSpec>
791 for (
auto& signalDP : lr.signalHistory_)
837template<
typename T,
size_t d>
853 return Type::Constant(std::numeric_limits<T>::quiet_NaN());
870template<
typename T,
typename ManifoldType>
879 return Type::identity();
895 return ManifoldType::Log(a).norm();
905 os <<
"ScalarSignal at t=" << x.
t() <<
": " << x();
909template<
typename T,
size_t d>
912template<
typename T,
size_t d>
915 os <<
"VectorSignal at t=" << x.
t() <<
": " << x().transpose();
919template<
typename T,
typename ManifoldType,
size_t d>
922template<
typename T,
typename ManifoldType,
size_t d>
925 os <<
"ManifoldSignal at t=" << x.
t() <<
": " << x();
929#define MAKE_VECTOR_SIGNAL(Dimension) \
930 template<typename T> \
931 using Vector##Dimension##Signal = VectorSignal<T, Dimension>; \
932 typedef Vector##Dimension##Signal<double> Vector##Dimension##dSignal;
934#define MAKE_MANIF_SIGNAL(Manif, Dimension) \
935 template<typename T> \
936 using Manif##Signal = ManifoldSignal<T, Manif<T>, Dimension>; \
937 typedef Manif##Signal<double> Manif##dSignal;
Signal< T, VectorSignalSpec< T, d >, VectorSignalSpec< T, d > > VectorSignal
Definition Signal.h:910
DerivativeMethod
Methods for computing numerical derivatives of signals.
Definition Signal.h:37
@ FINITE_DIFF
Definition Signal.h:39
@ DIRTY
Definition Signal.h:38
#define MAKE_VECTOR_SIGNAL(Dimension)
Definition Signal.h:929
std::ostream & operator<<(std::ostream &os, const ScalarSignal< T > &x)
Definition Signal.h:903
Signal< T, BaseSignalSpec, TangentSignalSpec > operator+(const Signal< T, BaseSignalSpec, TangentSignalSpec > &l, const Signal< T, TangentSignalSpec, TangentSignalSpec > &r)
Add a tangent signal to a base signal.
Definition Signal.h:712
ScalarSignal< double > ScalardSignal
Definition Signal.h:939
Signal< T, ManifoldSignalSpec< T, ManifoldType >, VectorSignalSpec< T, d > > ManifoldSignal
Definition Signal.h:920
ExtrapolationMethod
Methods for extrapolating signal values outside the defined time range.
Definition Signal.h:27
@ ZEROS
Definition Signal.h:29
@ CLOSEST
Definition Signal.h:30
@ NANS
Definition Signal.h:28
InterpolationMethod
Methods for interpolating signal values between discrete time points.
Definition Signal.h:17
@ CUBIC_SPLINE
Definition Signal.h:20
@ ZERO_ORDER_HOLD
Definition Signal.h:18
@ LINEAR
Definition Signal.h:19
Signal< T, TangentSignalSpec, TangentSignalSpec > operator-(const Signal< T, BaseSignalSpec, TangentSignalSpec > &l, const Signal< T, BaseSignalSpec, TangentSignalSpec > &r)
Subtract one signal from another, producing a tangent signal.
Definition Signal.h:733
Signal< T, BaseSignalSpec, TangentSignalSpec > operator*(const double &l, const Signal< T, BaseSignalSpec, TangentSignalSpec > &r)
Multiply a signal by a scalar from the left.
Definition Signal.h:764
Signal< T, ScalarSignalSpec< T >, ScalarSignalSpec< T > > ScalarSignal
Definition Signal.h:900
#define MAKE_MANIF_SIGNAL(Manif, Dimension)
Definition Signal.h:934
Template class for time-series signals with interpolation, extrapolation, and derivative capabilities...
Definition Signal.h:63
static TangentType tangentZero()
Definition Signal.h:392
void setDerivativeMethod(DerivativeMethod method)
Definition Signal.h:246
static T baseNorm(const BaseType &x)
Definition Signal.h:402
double t() const
Get the current time of the signal.
Definition Signal.h:151
bool update(const double &_t, const BaseType &_x, const TangentType &_xdot, bool insertHistory=false)
Definition Signal.h:288
Signal(const Signal &other)
Definition Signal.h:108
void setExtrapolationMethod(ExtrapolationMethod method)
Definition Signal.h:237
friend Signal< S, BSS, TSS > operator*(const double &l, const Signal< S, BSS, TSS > &r)
std::vector< BaseType > operator()(const std::vector< double > &t) const
Definition Signal.h:199
friend Signal< S, BSS, TSS > operator*(const Signal< S, BSS, TSS > &l, const double &r)
friend Signal< S, TSS, TSS > operator-(const Signal< S, BSS, TSS > &l, const Signal< S, BSS, TSS > &r)
struct Signal::@053250032031010315204017007310244260026177164207 SignalDPComparator
Comparator for sorting signal data points by time.
void setInterpolationMethod(InterpolationMethod method)
Definition Signal.h:228
static BaseType baseZero()
Definition Signal.h:383
BaseType operator()(const double &t) const
Definition Signal.h:179
ExtrapolationMethod extrapolationMethod
Definition Signal.h:90
Signal()
Default constructor initializing with LINEAR interpolation, ZEROS extrapolation, and DIRTY derivative...
Definition Signal.h:96
static T tangentNorm(const TangentType &x)
Definition Signal.h:412
std::vector< TangentType > dot(const std::vector< double > &t) const
Definition Signal.h:214
typename BaseSignalSpec::Type BaseType
Definition Signal.h:65
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
InterpolationMethod interpolationMethod
Definition Signal.h:89
bool update(const std::vector< double > &_tHistory, const std::vector< BaseType > &_xHistory, const std::vector< TangentType > &_xdotHistory)
Definition Signal.h:353
void reset()
Reset the signal to initial state, clearing all history.
Definition Signal.h:254
bool update(const std::vector< double > &_tHistory, const std::vector< BaseType > &_xHistory)
Definition Signal.h:318
BaseType operator()() const
Get the current signal value.
Definition Signal.h:160
typename TangentSignalSpec::Type TangentType
Definition Signal.h:66
TangentType dot() const
Get the current time derivative of the signal.
Definition Signal.h:169
Signal< T, ScalarSignalSpec< T >, ScalarSignalSpec< T > > dotSignal()
Definition Signal.h:124
DerivativeMethod derivativeMethod
Definition Signal.h:91
TangentType dot(const double &t) const
Definition Signal.h:189
friend Signal< S, BSS, TSS > operator+(const Signal< S, BSS, TSS > &l, const Signal< S, TSS, TSS > &r)
Type specification for manifold-valued signals (e.g., SO2, SO3, SE2, SE3).
Definition Signal.h:872
static Type NansType()
Returns manifold element with NaN values.
Definition Signal.h:884
static T Norm(const Type &a)
Compute the norm of a manifold element via its logarithmic map.
Definition Signal.h:893
ManifoldType Type
Definition Signal.h:873
static Type ZeroType()
Returns identity element of the manifold.
Definition Signal.h:877
Type specification for scalar-valued signals.
Definition Signal.h:805
static Type NansType()
Returns NaN value for the scalar type.
Definition Signal.h:817
T Type
Definition Signal.h:806
static Type ZeroType()
Returns zero value for the scalar type.
Definition Signal.h:810
static T Norm(const Type &a)
Compute the norm (absolute value) of a scalar.
Definition Signal.h:826
Data point structure storing time, value, and derivative.
Definition Signal.h:72
TangentType xdot
Definition Signal.h:75
BaseType x
Definition Signal.h:74
double t
Definition Signal.h:73
Type specification for vector-valued signals.
Definition Signal.h:839
static Type NansType()
Returns vector filled with NaN values.
Definition Signal.h:851
static Type ZeroType()
Returns zero vector.
Definition Signal.h:844
static T Norm(const Type &a)
Compute the Euclidean norm of a vector.
Definition Signal.h:860
Matrix< T, d, 1 > Type
Definition Signal.h:840