-
Notifications
You must be signed in to change notification settings - Fork 26
/
LUT_generator.m
53 lines (41 loc) · 1.48 KB
/
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
%%% Generate PMT-based lookup table %%%
speed = data.tdot;
phase = data.phi;
torque = data.torque;
mag = data.mag;
%figure;scatter3(data(:,1), data(:,2), data(:,5), 15, data(:,5))
speedvec = speed(1,:);
tmaxvec = torque(1,:);
%%% Create max torque vector %%%
for x = 1:length(speedvec)
s = speedvec(x);
tvec = torque(find(speed==s));
tmax = max(tvec);
phi= phase(find((speed==s).*(torque==tmax)));
tmax_vec(x) = tmax;
phimax_vec(x) = phi;
end
%%% Percent Max Torque %%%
pmt = [0:.01:1]';
[pmt_grid, speed_grid] = meshgrid(pmt, speedvec);
torque_grid = meshgrid(tmax_vec, pmt)';
torque_grid = pmt_grid.*torque_grid;
%figure; surf(speed_grid, pmt_grid, torque_grid); xlabel('Rad/s'); ylabel('PMT'); zlabel('Torque');
%phase_grid = zeros(length(speed_grid(:,1)), length(pmt_grid(1, :)));
%mag_grid = zeros(size(speed_grid(:,1)), size(pmt_grid(1, :)));
for x = 1:length(pmt_grid(1, :))
for j = 1:length(speed_grid(:,1))
t = torque_grid(j, x);
s = speed_grid(j, x);
t_ind = find(speed == s);
tv = torque(t_ind);
pv = phase(t_ind);
mv = mag(t_ind);
phi = interp1(tv, pv, t, 'pchip');
m = interp1(tv, mv, t, 'pchip');
phase_grid(j, x) = phi;
mag_grid(j, x) = m;
end
end
figure;surf(speed_grid, pmt_grid, phase_grid); xlabel('Rad/s'); ylabel('PMT'); zlabel('Phase');
figure;surf(speed_grid, pmt_grid, mag_grid); xlabel('Rad/s'); ylabel('PMT'); zlabel('Current');