YAMS
Yet Another Mechanism System
Loading...
Searching...
No Matches
TrackingDifferentiator.hpp
Go to the documentation of this file.
1// Copyright (c) 2026 Yet Another Software Suite
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
4#pragma once
5
6#include <vector>
7
8#include <wpi/units/time.hpp>
9
10namespace yams::math {
11
52 public:
54 enum class Method {
60 };
61
70 TrackingDifferentiator(Method method, wpi::units::second_t dt, std::vector<double> params = {});
71
78 void SetParameters(std::vector<double> params);
79
86 void SetSampleTime(wpi::units::second_t dt);
87
93 void Update(double reference);
94
100 void Reset(double initialValue);
101
103 double GetY() const { return m_y; }
105 double GetYd() const { return m_yd; }
107 double GetYdd() const { return m_ydd; }
109 Method GetMethod() const { return m_method; }
110
111 private:
113 double Param(size_t index, double defaultValue) const;
115 void ValidateParams(double dt) const;
116
117 void UpdateEuler(double reference);
118 void UpdateTod(double reference);
119 void UpdateLd(double reference);
120 void UpdateRed(double reference);
121 void UpdateIntd(double reference);
122
123 Method m_method;
124 double m_dt;
125 std::vector<double> m_params;
126
127 double m_prevY{0.0};
128 double m_prevYd{0.0};
129 double m_v1{0.0};
130 double m_v2{0.0};
131 double m_y{0.0};
132 double m_yd{0.0};
133 double m_ydd{0.0};
134};
135
136} // namespace yams::math
void Update(double reference)
double GetY() const
Definition TrackingDifferentiator.hpp:103
void Reset(double initialValue)
Method
Definition TrackingDifferentiator.hpp:54
@ INTD
Saturating differentiator; alpha, beta, gamma, r, defaults 0.5, 1, 1, 1.
Definition TrackingDifferentiator.hpp:59
@ EULER
First order exponential smoothing; alpha in [0, 1], default 0.9.
Definition TrackingDifferentiator.hpp:55
@ RED
Super-twisting differentiator; lambda1, lambda2, default 1 each.
Definition TrackingDifferentiator.hpp:58
@ LD
Linear differentiator; lambda greater than 0, default 1.
Definition TrackingDifferentiator.hpp:57
@ TOD
Bang-bang time optimal differentiator; r greater than 0, default 1.
Definition TrackingDifferentiator.hpp:56
double GetYd() const
Definition TrackingDifferentiator.hpp:105
void SetParameters(std::vector< double > params)
Method GetMethod() const
Definition TrackingDifferentiator.hpp:109
void SetSampleTime(wpi::units::second_t dt)
double GetYdd() const
Definition TrackingDifferentiator.hpp:107
TrackingDifferentiator(Method method, wpi::units::second_t dt, std::vector< double > params={})
Definition ADRCConfig.hpp:24