MATLAB: Sending PID gain values from Simulink PID block to Matlab workspace

MATLABmatlab workspacepid tuningsending pid gains to workspacesimulinksimulink pid block

Hey Guys
Im in the process of tuning a PID controller. I have written a processing script to analyse the step and frequency response of the system. But I don't want to manually enter the PID gain values in the .m file every time I tune the PID using Simulink.
Is there any way to send the PID gain values from the PID block in Simulink to the Matlab workspace automatically after tuning manually?
I really appreciate any help as this would help me speed up tuning now and in the future.
Thanks E Sunil (TU Delft)

Best Answer

You can retrieve the gain values of PID block in your m-script. See below piece of code.
% Get the values from block
P_str = get_param('PID_Block_Path','P');
I_str = get_param('PID_Block_Path','I');
D_str = get_param('PID_Block_Path','D');
% Convert string to values
P_val = str2double(P_str);
I_val = str2double(I_str);
D_val = str2double(D_str);
% If required send values to base workspace
assignin('base','P_val_base',P_val);
assignin('base','I_val_base',I_val);
assignin('base','D_val_base',D_val);
Related Question