Changing gain parameter in matlab function block during simulink simulation

4 views (last 30 days)
Hi, I need to change gain/constant parameter in Simulink during the simulation. Sometimes it need to be changed and sometimes it doesn't, so I try to do it in the Matlab function block. Anyway, I didn't find a solution without a GUI... I already tried set_param function but it doesn't work in matlab function block.
My real issue is to set PD controller until the condition isn't true. Than I need only PID controller no matter the condition.
Thanks for help in advance
function [PD, PID] = PID_switch(PID_set, error)
if PID_set == 0
PD = error;
PID = 0;
else
PID = error;
PD = 0;
end
if condition == 1
PID_set = 1;
end
end

Answers (1)

Umang Pandey
Umang Pandey on 25 Sep 2023
Hi Jan,
As per my understanding, it appears that you are interested in employing the "PD" control block until a specific condition remains unfulfilled. Once this condition is met, the system should transition to the "PID" control block.
To facilitate this, I suggest utilizing the "Switch" block in Simulink. This block enables you to route one of its inputs to its output based on a specified "Threshold" parameter.
For a comprehensive understanding and examples, you may refer to the following documentation:
Best,
Umang

Categories

Find more on General Applications in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!