How come I cannot update the .mat file of "AutotunedSpeed.mat" of the PMSM FOC Autotuner example after the simulation? (see the code of the example below)
8 次查看(过去 30 天)
显示 更早的评论
I am using this MATLAB Example in ordner to autotune a PMSM Motor which is controlled by the Field Oriented Block.
The example I am using is the following:
I changed the parameters of the motor (including the resistance, inductance, permanent flux..) and I tried running the Simscape example through matlab editor / code:
%% Tune Field-Oriented Controllers for a PMSM Using Closed-Loop PID Autotuner Block
% This example shows how to tune a field-oriented controller for a
% PMSM-based electrical-traction drive in just one simulation using the
% Closed-Loop PID Autotuner block.
% Copyright 2018 The MathWorks, Inc.
%% Field-Oriented Control
% In this example, a field-oriented controller for a permanent magnet
% synchronous machine (PMSM) based electrical-traction drive is modeled in
% Simulink(R) using Simscape(TM) Electrical(TM) components. The model is
% based on the Simscape example
% <docid:sps_ug#example-ee_pmsm_traction_drive>.
mdl = 'scdfocpmsmPIDTuning';
open_system(mdl)
%%.....
%%
% To view the modified outer-loop control structure, open the Outer loop
% control subsystem in the PMSM controller subsystem.
controlSubsystem = [mdl '/PMSM controller'];
open_system([controlSubsystem '/Outer loop control'])
%%
% View the modified current controllers in the Inner loop control subsystem.
open_system([controlSubsystem '/Inner loop control'])
%% Configure Autotuner Block
sim(mdl);
save('AutotunedSpeed','SpeedData');
%%%%
% During the autotuning process from 1.0 to 2.6 seconds, the changes in
% current and in motor speed are very small. The motor speed reaches the
% nominal |1000| rpm before the autotuning process begins.
%%%%
% The three PI controllers are tuned with new gains.
%
% * The d-axis PI controller has gains of P = 0.6332 and I = 331.7.
% * The q-axis PI controller has gains of P = 0.937 and I = 351.1.
% * The speed PI controller has gains of P = 32.35 and I = 1322.
%
%%%%
% The same rotor speed reference is applied before and after the autotuning
% process. Plot the rotor speed responses with respect to the nominal
% |1000| rpm before and after tuning the controllers. The speed response
% curves are aligned in time to compare controller performances
% side-by-side.
scdfocpmsmPIDTuningPlotSpeed
%%
The Problem that I am encountering is that after running the matlab code "scdfocpmsmPIDTuningPlotSpeed". I only get an older version of the "AutotunedSpeed" and I cannot see the updated speeds.
Here's the code of the scdfocpmsmPIDTuningPlotSpeed:
% Compare speed output after tuning controller
load('AutotunedSpeed')
speed_ref = SpeedData.signals.values(:,1);
speed_response = SpeedData.signals.values(:,2);
speed_initial_idx = find(SpeedData.time <= 3);
speed_compare_idx = find((SpeedData.time > 0)&(SpeedData.time <= 3));
% Plot a comparison of speed
figure
plot(SpeedData.time(speed_initial_idx), speed_ref(speed_initial_idx),'LineWidth',1);
hold on
plot(SpeedData.time(speed_initial_idx), speed_response(speed_initial_idx),'LineWidth',1);
plot(SpeedData.time(speed_compare_idx), speed_response(speed_compare_idx),'--','LineWidth',1);
title('Speed Response (rpm) of Autotuned Controllers During Acceleration');
legend('Reference','Original Controller','Autotuned Controllers','location','southeast');
grid on
hold off
See the figure from the example model:

The Autotuning itself works. But I just can't seem to get the plot of the 3 signals of the velocity (ref. Signal, vel. Signal with original controllers, and autotuned controllers).
I also chucked if the variables which "Autotunedspeed" contain "SpeedData" comes from the Simscape Model or gets exported through "To Workspace", but I didn't find any Block "To Workspace" nor a variable or a signal with the name "SpeedData" ..
I appreciate any hint or help from you guys! I am not sure how the Autotunedspeed gets updated if there is nothing to find inside the model...
The example/Simscape Model can be seen and opened on the link I added above.
0 个评论
回答(1 个)
CHANDRA BABU GUTTIKONDA
2025-4-17
编辑:CHANDRA BABU GUTTIKONDA
2025-4-17
dear madam,
the original controller and auto tuned controllers are in the same line but there is a small variations in the graph . please check through it . the variations is very less for original controller and autotuned controllers. or vary the proportional and integral values of auto tuned controller.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!