-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathPMT_LUT_generator.m
116 lines (102 loc) · 3.91 KB
/
PMT_LUT_generator.m
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
format compact
clear
%%% Generate a Percent Max Torque lookup table %%%
n = 200; % Phase intervals
n2 = 5; % Torque intervals
n3 = 5; % Velocity intervals
tdot_max = 1;
mag_max = 40;
tdot = linspace(0.01, tdot_max, n3);
phase_min = pi/2;
phase_max = pi;
%phase_max = 2*pi;
pmi = linspace(0, 1, n2); %Percent Max current. Easier to generate table this way, then interpolate torques
mag_vec = linspace(1, mag_max, n2);
phase = linspace(phase_min, phase_max, n);
torque_vec = zeros(length(n), 4);
% mag_log_vec = zeros(length(n2)*length(n3), 1);
% phi_max_vec = zeros(length(n2)*length(n3), 1);
% torque_max_vec = zeros(length(n2)*length(n3), 1);
% tdot_vec = zeros(length(n2)*length(n3), 1);
% i_mag_vec = zeros(length(n2)*length(n3), 1);
%%% Find max achievable current and pos/neg torques vs speed %%%
for k = 1:n3
tic
parfor x = 1:n
[t, t_pm, t_rel, i_mag] = motor_fun(mag_max, phase(x), tdot(k));
torque_vec(x,:) = [t, t_pm, t_rel, i_mag];
end
t_max = max(torque_vec(:,1));
t_min = min(torque_vec(:,1));
ind_max = find(torque_vec(:,1) == t_max);
%ind_min = find(torque_vec(:,1) == t_min);
phi_max = phase(ind_max);
%phi_min = phase(ind_min)
i_mag_max = torque_vec(ind_max,4);
%i_mag_min = torque_vec(ind_min, 4);
t_max_vec(k) = t_max;
%t_min_vec(k) = t_min;
phi_max_vec(k) = phi_max;
%phi_min_vec(k) = phi_min;
i_mag_max_vec(k) = i_mag_max;
%i_mag_min_vec(k) = i_mag_min;
i_max_vec(k) = i_mag_max;%max(i_mag_max, i_mag_min);
toc
k
end
figure;scatter(phase, torque_vec(:,1));
%figure;plot(tdot, t_max_vec); title('Max Torque')
%figure;plot(tdot, phi_max_vec); title('Max Phase')
%figure;plot(tdot, i_mag_max_vec); title('Max Current')%figure;plot(tdot, t_max_vec, tdot, t_min_vec); title('Max/Min Torque')
%figure;plot(tdot, phi_max_vec, tdot, phi_min_vec); title('Max/Min Phase')
%figure;plot(tdot, i_mag_max_vec, tdot, i_mag_min_vec); title('Max/Min Current')
%{
for k = 1:n3
for j = 1:n2
parfor x = 1:n
[t, t_pm, t_rel, i_mag] = motor_fun(i_max_vec(k)*pmi(j), phase(x), tdot(k));
torque_vec(x,:) = [t, t_pm, t_rel, i_mag];
end
t_max = max(torque_vec(:,1));
%t_min = min(torque_vec(:,1));
ind_max = find(torque_vec(:,1) == t_max);
ind_max = ind_max(1);
%ind_min = find(torque_vec(:,1) == t_min);
%ind_min = ind_min(1);
phi_max = phase(ind_max);
%phi_min = phase(ind_min);
t_max_mat(k, j) = t_max;
%t_min_mat(k, j) = t_min;
phi_max_mat(k, j) = phi_max;
%phi_min_mat(k, j) = phi_min;
end
k
end
[pmi_grid, tdot_grid] = meshgrid(pmi, tdot);
figure; surf(tdot_grid, pmi_grid, t_max_mat); title('Max torque');
%figure; surf(tdot_grid, pmi_grid, t_min_mat); title('Min torque');
figure; surf(tdot_grid, pmi_grid, phi_max_mat); title('Max phase');
%figure; surf(tdot_grid, pmi_grid, phi_min_mat); title('Min phase');
%figure; surf(tdot_grid, pmi_grid, t_max_mat); surf(tdot_grid, pmi_grid, t_min_mat); hold all; title('Torque Envelope');
data.tmax = t_max_mat;
%data.t_min = t_min_mat;
data.phi_max = phi_max_mat;
%data.phi_min = phi_min_mat;
data.pmi = pmi_grid;
data.tdot = tdot_grid;
% figure;plotyy(tdot, phi_max_vec, tdot, torque_max_vec);
% data = [tdot', phi_max_vec'];
% save('2d_lut.mat', 'data');
% figure;scatter3(tdot_vec, mag_log_vec, phi_max_vec, 20, phi_max_vec, 'filled');
% view(0, 90); colorbar();
% xlabel('Rad/s'); ylabel('Current Command'); zlabel('Phase');
% figure;scatter3(tdot_vec, mag_log_vec, torque_max_vec, 20, torque_max_vec, 'filled');
% view(0, 90); colorbar();
% xlabel('Rad/s'); ylabel('Current Command'); zlabel('Torque');
% figure;scatter3(tdot_vec, i_mag_vec, torque_max_vec, 20, torque_max_vec, 'filled');
% view(0, 90); colorbar();
% xlabel('Rad/s'); ylabel('Current'); zlabel('Torque');
%
% data = [tdot_vec, mag_log_vec, i_mag_vec, phi_max_vec, torque_max_vec];
% save('2d_lut.mat', 'data');
%}