-
Notifications
You must be signed in to change notification settings - Fork 0
/
differentiator.cpp
293 lines (251 loc) · 16.3 KB
/
differentiator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#include "differentiator.h"
#include <iostream>
#include <stdexcept>
#include <algorithm>
#include <eigen3/unsupported/Eigen/MatrixFunctions>
#include <boost/math/special_functions/factorials.hpp>
// Differentiator methods
differentiator::differentiator(unsigned int n, double r, double Ts) :
differentiator(n, 1, -1.0, r, 1, 0.0, Ts)
{
// Do nothing
}
differentiator::differentiator(unsigned int n, unsigned int nf, double d, double r, unsigned int m, double mu, double Ts)
{
// Check parameter values
if (n==0) {
throw std::invalid_argument("n must be an integer value greater than 0.");
}
if ((d>0.0) || (d<-1.0)) {
throw std::invalid_argument("d must be a value between -1 and 0.");
}
if (r<0.0) {
throw std::invalid_argument("r must be a positive value.");
}
if ((m!=0) && (m!=1) && (m!=2)) {
throw std::invalid_argument("m must be out of the set {0,1,2}.");
}
if (mu<0.0) {
throw std::invalid_argument("mu must be a positive value.");
}
if (Ts<=0.0) {
throw std::invalid_argument("Ts must be a value greater than 0.");
}
if ((m==2) && (d!=-1)) {
throw std::invalid_argument("Uniform RED (m=2) is only allowed with RED (d=-1).");
}
_d = d;
_r = r;
_mu = mu;
_Ts = Ts;
_n = n;
_nf = nf;
_m = m;
// Initialize internal variables
_sys_n = n+nf+1;
_zp = Eigen::VectorXd::Zero(_sys_n);
_A = Eigen::MatrixXd::Zero(_sys_n,_sys_n);
_A.diagonal(1).setConstant(1.0);
_b = Eigen::VectorXd::Zero(_n+_nf+1);
if (_nf>0) {
_b(_nf-1) = -1.0;
}
_P = Eigen::MatrixXd::Zero(_sys_n+1,_sys_n+1);
_P.block(0,0,_sys_n,_sys_n) = _A;
_P.block(0,_sys_n,_sys_n,1) = _b;
_P = _P*_Ts;
_P = _P.exp();
_Phi = _P.block(0,0,_sys_n,_sys_n);
_bD = _P.block(0,_sys_n,_sys_n,1);
Eigen::VectorXd ones_sys_n(_sys_n);
ones_sys_n.setConstant(1.0);
Eigen::MatrixXd fact_diag = Eigen::MatrixXd::Zero(_sys_n,_sys_n);
for (auto k=0; k<_sys_n; k++) {
fact_diag(k,k) = 1/boost::math::factorial<double>(k);
}
Eigen::MatrixXd U = Eigen::VectorXd::LinSpaced(_sys_n,0.0,_sys_n-1)*ones_sys_n.transpose();
Eigen::MatrixXd Ut = U.transpose();
_U = Eigen::pow(U.array(),Ut.array());
_U = _U*fact_diag;
_V_inv = Eigen::MatrixXd::Zero(_sys_n,_sys_n);
for (auto k=0; k<_sys_n; k++) {
_V_inv(k,k) = 1/std::pow(_Ts,k);
}
_So_inv = (_U.transpose().lu().solve(_V_inv.transpose())).transpose();
_x0 = _z0 = 0.0;
}
differentiator::~differentiator()
{
// Do nothing
}
void differentiator::evaluate(double u)
{
_x0 = err(u, _zp(0));
double z_eig;
if (_m == 2) {
z_eig = disc_eigenvalues_URED(_x0);
}
else {
double s = cont_eigenvalues(_x0);
z_eig = disc_eigenvalues(s);
}
Eigen::VectorXd lambda;
if (_sys_n>11) {
ackerman(lambda, z_eig);
}
else {
ackerman_precomputed(lambda, z_eig);
}
_z0 = _zp(_nf);
_z = _zp.tail(_sys_n-_nf-1);
step(_zp, u, lambda);
}
// Private methods
double differentiator::err(double u, double first_state)
{
if (_nf>0) {
return -first_state;
}
return u-first_state;
}
double differentiator::cont_eigenvalues(double x0)
{
return -_r*std::pow(std::fabs(x0),(double)(_d/(1-_d*(_sys_n-1))));
}
double differentiator::disc_eigenvalues(double s)
{
switch (_m) {
case 0:
if (std::isinf(s)) {
return 0.0;
}
else {
return 1.0 + _Ts*s;
}
break;
case 1:
return std::exp(_Ts*s);
break;
default:
return 0.0;
}
return 0.0;
}
double differentiator::disc_eigenvalues_URED(double x0)
{
double c = std::pow(std::fabs(x0),1.0/(double)_sys_n);
return c/(_Ts*_r*_mu*std::abs(x0)+c+_Ts*_r);
}
void differentiator::ackerman(Eigen::VectorXd& lambda, double z)
{
Eigen::MatrixXd kappa = (_Phi - z*Eigen::MatrixXd::Identity(_sys_n,_sys_n)).pow(_sys_n);
lambda = kappa*_So_inv.block(0,_sys_n,_sys_n,1);
}
void differentiator::ackerman_precomputed(Eigen::VectorXd& lambda, double z)
{
double z0 = z;
switch (_sys_n-1) {
case 1:
lambda = Eigen::VectorXd::Zero(2);
lambda << 2.0-z0-z,
((z-1.0)*(z0-1.0))/_Ts;
break;
case 2:
lambda = Eigen::VectorXd::Zero(3);
lambda << 3.0-z0-2.0*z,
((z-1.0)*(z+3.0*z0+z*z0-5.0))/(2.0*_Ts),
-(std::pow(z-1.0,2.0)*(z0-1.0))/std::pow(_Ts,2.0);
break;
case 3:
lambda = Eigen::VectorXd::Zero(4);
lambda << 4.0-z0-3.0*z,
((z-1.0)*(7.0*z+11.0*z0+5.0*z*z0+2.0*std::pow(z,2.0)*z0+std::pow(z,2.0)-26.0))/(6.0*_Ts),
-(std::pow(z-1.0,2.0)*(2.0*z0+z*z0-3.0))/std::pow(_Ts,2.0),
(std::pow(z-1.0,3.0)*(z0-1.0))/std::pow(_Ts,3.0);
break;
case 4:
lambda = Eigen::VectorXd::Zero(5);
lambda << 5.0-z0-4.0*z,
((z-1.0)*(23.0*z+25.0*z0+13.0*z*z0+7.0*std::pow(z,2.0)*z0+3*std::pow(z,3.0)*z0+5*std::pow(z,2.0)+std::pow(z,3.0)-77.0))/(12.0*_Ts),
-(std::pow(z-1.0,2.0)*(35.0*z0-2.0*z+26.0*z*z0+11.0*std::pow(z,2.0)*z0+std::pow(z,2.0)-71.0))/(12.0*std::pow(_Ts,2.0)),
-(std::pow(z-1.0,3.0)*(z-5.0*z0-3.0*z*z0+7.0))/(2*std::pow(_Ts,3.0)),
-(std::pow(z-1.0,4.0)*(z0-1.0))/std::pow(_Ts,4.0);
break;
case 5:
lambda = Eigen::VectorXd::Zero(6);
lambda << 6.0-z0-5.0*z,
((z-1.0)*(163.0*z+137.0*z0+77.0*z*z0+47.0*std::pow(z,2.0)*z0+27.0*std::pow(z,3.0)*z0+12.0*std::pow(z,4.0)*z0+43.0*std::pow(z,2.0)+13.0*std::pow(z,3.0)+3.0*std::pow(z,4.0)-522.0))/(60.0*_Ts),
-(std::pow(z-1.0,2.0)*(45.0*z0-7.0*z+40.0*z*z0+25.0*std::pow(z,2.0)*z0+10.0*std::pow(z,3.0)*z0+2.0*std::pow(z,2.0)+std::pow(z,3.0)-116.0))/(12.0*std::pow(_Ts,2.0)),
-(std::pow(z-1.0,3.0)*(8.0*z-17.0*z0-16.0*z*z0-7.0*std::pow(z,2.0)*z0+std::pow(z,2.0)+31.0))/(4.0*std::pow(_Ts,3.0)),
(std::pow(z-1.0,4.0)*(z-3.0*z0-2.0*z*z0+4.0))/std::pow(_Ts,4.0),
(std::pow(z-1.0,5.0)*(z0-1.0))/std::pow(_Ts,5.0);
break;
case 6:
lambda = Eigen::VectorXd::Zero(7);
lambda << 7.0-z0-6.0*z,
((z-1.0)*(213.0*z+147.0*z0+87.0*z*z0+57.0*std::pow(z,2.0)*z0+37.0*std::pow(z,3.0)*z0+22.0*std::pow(z,4.0)*z0+10.0*std::pow(z,5.0)*z0+63.0*std::pow(z,2.0)+23.0*std::pow(z,3.0)+8.0*std::pow(z,4.0)+2.0*std::pow(z,5.0)-669.0))/(60.0*_Ts),
-(std::pow(z-1.0,2.0)*(812.0*z0-232.0*z+802.0*z*z0+597.0*std::pow(z,2.0)*z0+352.0*std::pow(z,3.0)*z0+137.0*std::pow(z,4.0)*z0+33.0*std::pow(z,2.0)+38.0*std::pow(z,3.0)+13.0*std::pow(z,4.0)-2552.0))/(180.0*std::pow(_Ts,2.0)),
-(std::pow(z-1.0,3.0)*(39.0*z-49.0*z0-57.0*z*z0-39.0*std::pow(z,2.0)*z0-15.0*std::pow(z,3.0)*z0+9.0*std::pow(z,2.0)+std::pow(z,3.0)+111.0))/(8.0*std::pow(_Ts,3.0)),
(std::pow(z-1.0,4.0)*(26.0*z-35.0*z0-38.0*z*z0-17.0*std::pow(z,2.0)*z0+5.0*std::pow(z,2.0)+59.0))/(6.0*std::pow(_Ts,4.0)),
-(std::pow(z-1.0,5.0)*(3.0*z-7.0*z0-5.0*z*z0+9.0))/(2.0*std::pow(_Ts,5.0)),
-(std::pow(z-1.0,6.0)*(z0-1))/std::pow(_Ts,6.0);
break;
case 7:
lambda = Eigen::VectorXd::Zero(8);
lambda << 8.0-z0-7.0*z,
((z-1.0)*(1851.0*z+1089.0*z0+669.0*z*z0+459.0*std::pow(z,2.0)*z0+319.0*std::pow(z,3.0)*z0+214.0*std::pow(z,4.0)*z0+130.0*std::pow(z,5.0)*z0+60.0*std::pow(z,6.0)*z0+591.0*std::pow(z,2.0)+241.0*std::pow(z,3.0)+101.0*std::pow(z,4.0)+38.0*std::pow(z,5.0)+10.0*std::pow(z,6.0)-5772.0))/(420.0*_Ts),
-(std::pow(z-1.0,2.0)*(938.0*z0-414.0*z+994.0*z*z0+819.0*std::pow(z,2.0)*z0+574.0*std::pow(z,3.0)*z0+329.0*std::pow(z,4.0)*z0+126.0*std::pow(z,5.0)*z0+16.0*std::pow(z,2.0)+61.0*std::pow(z,3.0)+36.0*std::pow(z,4.0)+11.0*std::pow(z,5.0)-3490.0))/(180.0*std::pow(_Ts,2.0)),
-(std::pow(z-1.0,3.0)*(1127.0*z-967.0*z0-1277.0*z*z0-1077.0*std::pow(z,2.0)*z0-647.0*std::pow(z,3.0)*z0-232.0*std::pow(z,4.0)*z0+357.0*std::pow(z,2.0)+77.0*std::pow(z,3.0)+7.0*std::pow(z,4.0)+2632.0))/(120.0*std::pow(_Ts,3.0)),
(std::pow(z-1.0,4.0)*(68.0*z-56.0*z0-77.0*z*z0-56.0*std::pow(z,2.0)*z0-21.0*std::pow(z,3.0)*z0+23.0*std::pow(z,2.0)+4.0*std::pow(z,3.0)+115.0))/(6.0*std::pow(_Ts,4.0)),
-(std::pow(z-1.0,5.0)*(43.0*z-46.0*z0-55.0*z*z0-25.0*std::pow(z,2.0)*z0+10.0*std::pow(z,2.0)+73.0))/(6.0*std::pow(_Ts,5.0)),
(std::pow(z-1.0,6.0)*(2.0*z-4.0*z0-3.0*z*z0+5.0))/std::pow(_Ts,6.0),
(std::pow(z-1.0,7.0)*(z0-1.0))/std::pow(_Ts,7.0);
break;
case 8:
lambda = Eigen::VectorXd::Zero(9);
lambda << 9.0-z0-8.0*z,
((z-1.0)*(4437.0*z+2283.0*z0+1443.0*z*z0+1023.0*std::pow(z,2.0)*z0+743.0*std::pow(z,3.0)*z0+533.0*std::pow(z,4.0)*z0+365.0*std::pow(z,5.0)*z0+225.0*std::pow(z,6.0)*z0+105.0*std::pow(z,7.0)*z0+1497.0*std::pow(z,2.0)+657.0*std::pow(z,3.0)+307.0*std::pow(z,4.0)+139.0*std::pow(z,5.0)+55.0*std::pow(z,6.0)+15.0*std::pow(z,7.0)-13827.0))/(840.0*_Ts),
-(std::pow(z-1.0,2.0)*(29531.0*z0-18254.0*z+32926.0*z*z0+29013.0*std::pow(z,2.0)*z0+22468.0*std::pow(z,3.0)*z0+15293.0*std::pow(z,4.0)*z0+8622.0*std::pow(z,5.0)*z0+3267.0*std::pow(z,6.0)*z0-733.0*std::pow(z,2.0)+2172.0*std::pow(z,3.0)+1787.0*std::pow(z,4.0)+898.0*std::pow(z,5.0)+261.0*std::pow(z,6.0)-127251.0))/(5040.0*std::pow(_Ts,2.0)),
-(std::pow(z-1.0,3.0)*(3777.0*z-2403.0*z0-3457.0*z*z0-3302.0*std::pow(z,2.0)*z0-2442.0*std::pow(z,3.0)*z0-1367.0*std::pow(z,4.0)*z0-469.0*std::pow(z,5.0)*z0+1462.0*std::pow(z,2.0)+442.0*std::pow(z,3.0)+87.0*std::pow(z,4.0)+5.0*std::pow(z,5.0)+7667.0))/(240.0*std::pow(_Ts,3.0)),
(std::pow(z-1.0,4.0)*(5572.0*z-3207.0*z0-5092.0*z*z0-4682.0*std::pow(z,2.0)*z0-2852.0*std::pow(z,3.0)*z0-967.0*std::pow(z,4.0)*z0+2522.0*std::pow(z,2.0)+772.0*std::pow(z,3.0)+127.0*std::pow(z,4.0)+7807.0))/(240.0*std::pow(_Ts,4.0)),
-(std::pow(z-1.0,5.0)*(122.0*z-81.0*z0-125.0*z*z0-95.0*std::pow(z,2.0)*z0-35.0*std::pow(z,3.0)*z0+50.0*std::pow(z,2.0)+10.0*std::pow(z,3.0)+154.0))/(6.0*std::pow(_Ts,5.0)),
(std::pow(z-1.0,6.0)*(42.0*z-39.0*z0-50.0*z*z0-23.0*std::pow(z,2.0)*z0+11.0*std::pow(z,2.0)+59.0))/(4.0*std::pow(_Ts,6.0)),
-(std::pow(z-1.0,7.0)*(5.0*z-9.0*z0-7.0*z*z0+11.0))/(2.0*std::pow(_Ts,7.0)),
-(std::pow(z-1.0,8.0)*(z0-1.0))/std::pow(_Ts,8.0);
break;
case 9:
lambda = Eigen::VectorXd::Zero(10);
lambda << 10.0-z0-9.0*z,
((z-1.0)*(15551.0*z+7129.0*z0+4609.0*z*z0+3349.0*std::pow(z,2.0)*z0+2509.0*std::pow(z,3.0)*z0+1879.0*std::pow(z,4.0)*z0+1375.0*std::pow(z,5.0)*z0+955.0*std::pow(z,6.0)*z0+595.0*std::pow(z,7.0)*z0+280.0*std::pow(z,8.0)*z0+5471.0*std::pow(z,2.0)+2531.0*std::pow(z,3.0)+1271.0*std::pow(z,4.0)+641.0*std::pow(z,5.0)+305.0*std::pow(z,6.0)+125.0*std::pow(z,7.0)+35.0*std::pow(z,8.0)-48610.0))/(2520.0*_Ts),
-(std::pow(z-1.0,2.0)*(32575.0*z0-26477.0*z+37754.0*z*z0+34905.0*std::pow(z,2.0)*z0+28864.0*std::pow(z,3.0)*z0+21689.0*std::pow(z,4.0)*z0+14514.0*std::pow(z,5.0)*z0+8095.0*std::pow(z,6.0)*z0+3044.0*std::pow(z,7.0)*z0-2712.0*std::pow(z,2.0)+2321.0*std::pow(z,3.0)+2566.0*std::pow(z,4.0)+1677.0*std::pow(z,5.0)+788.0*std::pow(z,6.0)+223.0*std::pow(z,7.0)-159826.0))/(5040.0*std::pow(_Ts,2.0)),
(std::pow(z-1.0,3.0)*(180920.0*z0-363543.0*z+276981.0*z*z0+287607.0*std::pow(z,2.0)*z0+240602.0*std::pow(z,3.0)*z0+165702.0*std::pow(z,4.0)*z0+88737.0*std::pow(z,5.0)*z0+29531.0*std::pow(z,6.0)*z0-161922.0*std::pow(z,2.0)-60422.0*std::pow(z,3.0)-17337.0*std::pow(z,4.0)-2931.0*std::pow(z,5.0)+16.0*std::pow(z,6.0)-663941.0))/(15120.0*std::pow(_Ts,3.0)),
(std::pow(z-1.0,4.0)*(9853.0*z-4275.0*z0-7488.0*z*z0-7938.0*std::pow(z,2.0)*z0-6108.0*std::pow(z,3.0)*z0-3363.0*std::pow(z,4.0)*z0-1068.0*std::pow(z,5.0)*z0+5368.0*std::pow(z,2.0)+2198.0*std::pow(z,3.0)+638.0*std::pow(z,4.0)+101.0*std::pow(z,5.0)+12082.0))/(240.0*std::pow(_Ts,4.0)),
-(std::pow(z-1.0,5.0)*(6428.0*z-3013.0*z0-5444.0*z*z0-5334.0*std::pow(z,2.0)*z0-3284.0*std::pow(z,3.0)*z0-1069.0*std::pow(z,4.0)*z0+3534.0*std::pow(z,2.0)+1244.0*std::pow(z,3.0)+229.0*std::pow(z,4.0)+6709.0))/(144.0*std::pow(_Ts,5.0)),
(std::pow(z-1.0,6.0)*(129.0*z-75.0*z0-126.0*z*z0-99.0*std::pow(z,2.0)*z0-36.0*std::pow(z,3.0)*z0+60.0*std::pow(z,2.0)+13.0*std::pow(z,3.0)+134.0))/(4.0*std::pow(_Ts,6.0)),
-(std::pow(z-1.0,7.0)*(172.0*z-145.0*z0-196.0*z*z0-91.0*std::pow(z,2.0)*z0+49.0*std::pow(z,2.0)+211.0))/(12*std::pow(_Ts,7.0)),
(std::pow(z-1.0,8.0)*(3.0*z-5.0*z0-4.0*z*z0+6.0))/std::pow(_Ts,8.0),
(std::pow(z-1.0,9.0)*(z0-1.0))/std::pow(_Ts,9.0);
break;
case 10:
lambda = Eigen::VectorXd::Zero(11);
lambda << 11.0-z0-10.0*z,
((z-1.0)*(17819.0*z+7381.0*z0+4861.0*z*z0+3601.0*std::pow(z,2.0)*z0+2761.0*std::pow(z,3.0)*z0+2131.0*std::pow(z,4.0)*z0+1627.0*std::pow(z,5.0)*z0+1207.0*std::pow(z,6.0)*z0+847.0*std::pow(z,7.0)*z0+532.0*std::pow(z,8.0)*z0+252.0*std::pow(z,9.0)*z0+6479.0*std::pow(z,2.0)+3119.0*std::pow(z,3.0)+1649.0*std::pow(z,4.0)+893.0*std::pow(z,5.0)+473.0*std::pow(z,6.0)+233.0*std::pow(z,7.0)+98.0*std::pow(z,8.0)+28.0*std::pow(z,9.0)-55991.0))/(2520.0*_Ts),
-(std::pow(z-1.0,2.0)*(177133.0*z0-181196.0*z+211686.0*z*z0+202949.0*std::pow(z,2.0)*z0+175852.0*std::pow(z,3.0)*z0+140985.0*std::pow(z,4.0)*z0+104102.0*std::pow(z,5.0)*z0+68899.0*std::pow(z,6.0)*z0+38136.0*std::pow(z,7.0)*z0+14258.0*std::pow(z,8.0)*z0-27739.0*std::pow(z,2.0)+10278.0*std::pow(z,3.0)+16165.0*std::pow(z,4.0)+12728.0*std::pow(z,5.0)+7611.0*std::pow(z,6.0)+3454.0*std::pow(z,7.0)+962.0*std::pow(z,8.0)-976263.0))/(25200.0*std::pow(_Ts,2.0)),
(std::pow(z-1.0,3.0)*(420475.0*z0-1040321.0*z+675075.0*z*z0+744585.0*std::pow(z,2.0)*z0+676405.0*std::pow(z,3.0)*z0+526605.0*std::pow(z,4.0)*z0+346845.0*std::pow(z,5.0)*z0+180175.0*std::pow(z,6.0)*z0+58635.0*std::pow(z,7.0)*z0-514467.0*std::pow(z,2.0)-222035.0*std::pow(z,3.0)-80075.0*std::pow(z,4.0)-21303.0*std::pow(z,5.0)-2669.0*std::pow(z,6.0)+427.0*std::pow(z,7.0)-1748357.0))/(30240.0*std::pow(_Ts,3.0)),
(std::pow(z-1.0,4.0)*(994506.0*z-341693.0*z0-643092.0*z*z0-750990.0*std::pow(z,2.0)*z0-665660.0*std::pow(z,3.0)*z0-462765.0*std::pow(z,4.0)*z0-238632.0*std::pow(z,5.0)*z0-72368.0*std::pow(z,6.0)*z0+617430.0*std::pow(z,2.0)+304040.0*std::pow(z,3.0)+118155.0*std::pow(z,4.0)+33126.0*std::pow(z,5.0)+5084.0*std::pow(z,6.0)+1102859.0))/(15120.0*std::pow(_Ts,4.0)),
-(std::pow(z-1.0,5.0)*(24135.0*z-8591.0*z0-17305.0*z*z0-19830.0*std::pow(z,2.0)*z0-15730.0*std::pow(z,3.0)*z0-8555.0*std::pow(z,4.0)*z0-2565.0*std::pow(z,5.0)*z0+16010.0*std::pow(z,2.0)+7550.0*std::pow(z,3.0)+2445.0*std::pow(z,4.0)+427.0*std::pow(z,5.0)+22009.0))/(288.0*std::pow(_Ts,5.0)),
(std::pow(z-1.0,6.0)*(18188.0*z-7513.0*z0-14948.0*z*z0-15378.0*std::pow(z,2.0)*z0-9548.0*std::pow(z,3.0)*z0-3013.0*std::pow(z,4.0)*z0+11418.0*std::pow(z,2.0)+4388.0*std::pow(z,3.0)+853.0*std::pow(z,4.0)+15553.0))/(240.0*std::pow(_Ts,6.0)),
-(std::pow(z-1.0,7.0)*(1139.0*z-605.0*z0-1085.0*z*z0-875.0*std::pow(z,2.0)*z0-315.0*std::pow(z,3.0)*z0+581.0*std::pow(z,2.0)+133.0*std::pow(z,3.0)+1027.0))/(24.0*std::pow(_Ts,7.0)),
(std::pow(z-1.0,8.0)*(56.0*z-44.0*z0-62.0*z*z0-29.0*std::pow(z,2.0)*z0+17.0*std::pow(z,2.0)+62.0))/(3.0*std::pow(_Ts,8.0)),
-(std::pow(z-1.0,9.0)*(7.0*z-11.0*z0-9.0*z*z0+13.0))/(2*std::pow(_Ts,9.0)),
-(std::pow(z-1.0,10.0)*(z0-1.0))/std::pow(_Ts,10.0);
break;
default:
lambda = Eigen::VectorXd::Zero(_sys_n);
break;
}
}
void differentiator::step(Eigen::VectorXd& z, double u, const Eigen::VectorXd& lambda)
{
z = _Phi*z.eval()+_bD*u+lambda*_x0;
}