-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_prefilter.cpp
More file actions
45 lines (38 loc) · 1.13 KB
/
command_prefilter.cpp
File metadata and controls
45 lines (38 loc) · 1.13 KB
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
#include "command_prefilter.h"
// Parameters Set Up for Third-Order Command Prefilter
void CommandPrefilter::init(const double& cutoff_freq, const double& sample_interval)
{
fc = cutoff_freq;
T = sample_interval;
tau = 1.0 / (2.0 * PI * fc); // Time Constant
a[0] = 1.0 / (tau * tau * tau); // Coefficients
a[1] = 3.0 / (tau * tau);
a[2] = 3.0 / (tau);
// Initial Conditions for Command Prefilter's States
for (int i = 0; i < 3; i++)
{
xf[i] = 0.0;
y[i] = 0.0;
F[i] = 0.0;
}
}
// Algorithm of Third-Order Command Prefilter
void CommandPrefilter::update(const double& input_sig, double& pos_f, double& vel_f, double& acc_f)
{
// Command Input Signal
r = input_sig;
// Model Equations
F[0] = xf[1];
F[1] = xf[2];
F[2] = -a[0] * xf[0] - a[1] * xf[1] - a[2] * xf[2] + r;
// State-space equations
for (int i = 0; i < 3; i++)
{
y[i] = a[0] * xf[i]; // output equation
xf[i] += T * F[i]; // update (state) equation
}
// Filtered Postion, Velocity, and Acceleration Commands
pos_f = y[0];
vel_f = y[1];
acc_f = y[2];
}