Repository navigation
Expand file tree
/
Copy pathexample2.m
More file actions
85 lines (63 loc) · 1.83 KB
/
Copy pathexample2.m
File metadata and controls
85 lines (63 loc) · 1.83 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
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
% Example of usage. See the GitHub readme for more comments.
%
% https://github.com/sadda/Minimum_Effort_Control
clear all;
close all;
addpath("src")
%% Settings
plot_figure = true;
kappas = linspace(0.4, 0.01, 40);
%% Input: Clarke's transform A
phi5 = 2/5*pi;
A_orig = 2/5*[1, cos(phi5), cos(2*phi5), cos(-2*phi5), cos(-phi5); ...
0, sin(phi5), sin(2*phi5), sin(-2*phi5), sin(-phi5); ...
1, cos(2*phi5), cos(-phi5), cos(phi5), cos(-2*phi5); ...
0, sin(2*phi5), sin(-phi5), sin(phi5), sin(-2*phi5)];
A = A_orig([1 2],:);
B = [A_orig([3 4],:); -A_orig([3 4],:)];
%% Input: Required voltage y
ts = 0:100e-6:0.06;
omega = 2*pi*50;
Um = 230*sqrt(2);
n_y = size(A,1) + size(B,1);
n_x = size(A,2);
n_t = length(ts);
n_k = length(kappas);
ys = zeros(n_y, n_t, n_k);
for i = 1:length(kappas)
for k = 1:n_t
wt = omega*ts(k);
ys(1,k,i) = Um*cos(wt);
ys(2,k,i) = Um*sin(wt);
ys(3,k,i) = abs(kappas(i)*Um*cos(3*wt));
ys(4,k,i) = abs(kappas(i)*Um*sin(3*wt));
ys(5,k,i) = ys(3,k,i);
ys(6,k,i) = ys(4,k,i);
end
end
%% Output: Precompute offline part
pars = Pars(A, B);
solver = Solver(pars);
%% Output: Get a solution for every time
xs = zeros(n_x, n_t, n_k);
for i = 1:length(kappas)
for k = 1:n_t
xs(:,k,i) = solver.min_effort(ys(:,k,i));
end
end
%% Plot the results
if plot_figure
for i = 1:length(kappas)
y_lim = [-400 400];
h = plot_figures(ts, xs(:,:,i), A, B, Um, y_lim, kappas(i));
filename = 'figures/kappa.gif';
frame = getframe(h);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
if i == 1
imwrite(imind,cm,filename,'gif','Loopcount',inf);
else
imwrite(imind,cm,filename,'gif','WriteMode','append','DelayTime',0.1);
end
end
end