Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5c04e37
Rename file
noguchi-takahiro Jun 7, 2025
f9a610c
Rename fiels
noguchi-takahiro Jun 7, 2025
d55c6fa
Rename files
noguchi-takahiro Jun 7, 2025
98ab9ab
Update simulink file
noguchi-takahiro Jun 7, 2025
199299d
Add low pass fileter
noguchi-takahiro Jun 7, 2025
b73a883
Add observer
noguchi-takahiro Jun 7, 2025
b52fcc4
Discretize only lpf and pll
noguchi-takahiro Jun 7, 2025
13036c2
Discretize observer
noguchi-takahiro Jun 7, 2025
0422069
Add system ID
noguchi-takahiro Jun 7, 2025
6239d59
Rename file
noguchi-takahiro Jun 7, 2025
860b271
Update code
noguchi-takahiro Jun 7, 2025
a36d07b
Clean up plotting function, need to add switch system ID and step
noguchi-takahiro Jun 7, 2025
4611d9f
Merge branch 'add-enc-anirudh' into user/noguchi-takahiro/update-simu…
elsevers Jun 8, 2025
cf35e6c
Update simulink
noguchi-takahiro Jun 8, 2025
bd37f95
Update simulink to switch system ID
noguchi-takahiro Jun 8, 2025
7ee23c2
Update simulink
noguchi-takahiro Jun 8, 2025
5b96b3c
Clean up simulink
noguchi-takahiro Jun 8, 2025
88edda4
Remove unneccesary code
noguchi-takahiro Jun 8, 2025
f5c907f
Update simulink, cleaning up everything
noguchi-takahiro Jun 8, 2025
d7050d6
Merge branch 'add-enc-anirudh' into user/noguchi-takahiro/update-simu…
noguchi-takahiro Jun 8, 2025
4f094ca
Update simulink model structure
noguchi-takahiro Dec 19, 2025
5ebc237
Update code
noguchi-takahiro Dec 19, 2025
48a28ad
Create Reference model of low pass filter
noguchi-takahiro Dec 19, 2025
f3c71b7
Add pll encoder as reference model
noguchi-takahiro Dec 19, 2025
e047a7c
Add reference model
noguchi-takahiro Dec 19, 2025
13b0328
Update simulink model
noguchi-takahiro Dec 19, 2025
5742190
Remove old pll encoder
noguchi-takahiro Dec 19, 2025
b087496
Rename simulink model
noguchi-takahiro Dec 19, 2025
06a3b2f
Add gitignore
noguchi-takahiro Dec 19, 2025
68d06b6
Update m file
noguchi-takahiro Dec 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.

This file was deleted.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
##########
# MATLAB #
##########

# Windows default autosave extension
*.asv

# OSX / *nix default autosave extension
*.m~

# Compiled MEX binaries (all platforms)
*.mex*

# Packaged app and toolbox files
*.mlappinstall
*.mltbx

# Generated helpsearch folders
helpsearch*/

# Simulink code generation folders
slprj/
sccprj/

# Matlab code generation folders
codegen/

# Simulink autosave extension
*.autosave

# Simulink cache files
*.slxc
Binary file not shown.
Binary file not shown.
Binary file not shown.
131 changes: 131 additions & 0 deletions source/getting-started/control-with-amdc/encoder-fb/simulink/setup.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
clear
close all

Ts = 1e-4;
Tsim = 1e-5;


%% Switch winding that you develop
load_system('speedControlSimulation') % load Simulink model
% The input of this function should be 'lowPassFilter', 'pllEncoder', 'observer'
switch_speed_calculation('observer')

Tend = 0.2;

p = 1; % number of pole
speed_cmd = 3000; % rotational speed (r/min)

% Parameters for plant
J_z = 29.54e-6;
b = 4.28e-6;

% Parameters for low pass filter
f_lpf = 100; % low pass fileter cut-off frequency (Hz)
omega_lpf = 2*pi*f_lpf; % low pass fileter cut-off frequency (rad/s)

% Parameters for PLL
pole_1_Hz = -10;
pole_2_Hz = -100;
w1 = 2*pi*pole_1_Hz;
w2 = 2*pi*pole_2_Hz;

f_sf = 10; % motion state fileter cut-off frequency (Hz)
wb_sf = 2*pi*f_sf;
b_o_sf = wb_sf*J_z;
K_io_sf = wb_sf*b;

% Parameters for chirp signal
f_init = 0.1; % initial frequency of chirp [Hz]
f_target = 1000; % chirp frequency at target time [Hz]

% Parameters for speed control
fb_speed = 100;
omega_b_speed = 2*pi*fb_speed;
Kp_speed = omega_b_speed*J_z;
Ki_speed = omega_b_speed*b;

%% Run simulation
% set_param('compute_speed/Speed Controller LPF', 'Commented', 'off');
% set_param('compute_speed/Speed Controller PLL', 'Commented', 'on');
% set_param('compute_speed/Speed Control Observer', 'Commented', 'on');
sim('speedControlSimulation.slx');
run1 = Simulink.sdi.Run.getLatest;

% set_param('compute_speed/Speed Controller LPF', 'Commented', 'on');
% set_param('compute_speed/Speed Controller PLL', 'Commented', 'off');
% set_param('compute_speed/Speed Control Observer', 'Commented', 'on');
% sim('compute_speed.slx');
% run2 = Simulink.sdi.Run.getLatest;
%
% set_param('compute_speed/Speed Controller LPF', 'Commented', 'on');
% set_param('compute_speed/Speed Controller PLL', 'Commented', 'on');
% set_param('compute_speed/Speed Control Observer', 'Commented', 'off');
% sim('compute_speed.slx');
% run3 = Simulink.sdi.Run.getLatest;

%% Post processing
% List of variables to extract
% obj2ext = {'time', 'omega_raw', 'omega_lpf', 'omega_pll', 'omega_sf'};
obj2ext = {'time', 'omega'};
% runs = {run1, run2, run3};
runs = {run1};

for r = 1:1
runObj = runs{r};
for i = 1:length(obj2ext)
sigID = getSignalIDsByName(runObj, obj2ext{i});
if ~isempty(sigID)
sig_obj{r}.(obj2ext{i}) = Simulink.sdi.getSignal(sigID);
sig_val{r}.(obj2ext{i}) = sig_obj{r}.(obj2ext{i}).Values.Data;
time{r} = sig_obj{r}.(obj2ext{i}).Values.Time;
end
end
end

%% Plot figure
width = 2*5.43;
height = 1.2*3*4.38/3/2;
set(0,'units','inches');
Inch_SS = get(0,'screensize');
lw = 1; % line width

figure1 = figure;
% Plot omega
hold on;
% plot(time{3}, squeeze(sig_val{3}.omega_raw), 'Color', 'k', 'LineWidth', lw);
plot(time{1}, squeeze(sig_val{1}.omega), 'Color', 'r', 'LineWidth', lw);
% plot(time{2}, squeeze(sig_val{2}.omega_pll), 'Color', 'b', 'LineWidth', lw);
% plot(time{3}, squeeze(sig_val{3}.omega_sf), '--', 'Color', 'g', 'LineWidth', lw);
xlabel('Time [s]','Interpreter','latex');
ylabel('$\Omega$ (rad/s)','Interpreter','latex');
xlim([0 Tend]);
% ylim([0 400]);
% legend('$\Omega_{\mathrm{raw}}$','$\Omega_{\mathrm{lpf}}$', '$\Omega_{\mathrm{pll}}$', '$\Omega_{\mathrm{sf}}$', 'Interpreter','latex','Location','east');

set(findall(gcf, '-property', 'FontName'), 'FontName', 'Times New Roman');

set(figure1,'Units','inches','Position',[(Inch_SS(3)-width)/2 (Inch_SS(4)-height)/2 width height]);
print(figure1, '-dsvg','-noui','plot_results');
print(figure1, '-dpng','-r300','plot_results');

function switch_speed_calculation(speed_calculation_type)
% Define maps for speed calculation models
speed_calculation_models = containers.Map( ...
{'lowPassFilter', 'pllEncoder', 'observer'}, ...
{'lowPassFilter', 'pllEncoder', 'observer'} ...
);

if ~isKey(speed_calculation_models, speed_calculation_type)
error('Unknown speed calculation type: %s. Choose from: %s', speed_calculation_type, strjoin(keys(speed_calculation_models), ', '));
end

speed_calculation_name = speed_calculation_models(speed_calculation_type);

% Load the referenced models
load_system(speed_calculation_name);

% Update the reference blocks
set_param('speedControlSimulation', 'ModelName', speed_calculation_name);

fprintf('Speed calculation block has been switched to referenced model of %s and %s\n', controller_name);
end
Binary file not shown.