Add Reset Function to Simscape Integrator Block

3 次查看(过去 30 天)
I am trying to add a reset input to a custom integrator block using simscape. If the reset input is 1, the integrator will function normally and if the reset input is 0 it will reset to the initial condition. To achieve this I was attempting to set variable x to the initial condition (x0) when "reset == 0" but do not know how to populate the else condition to keep x the same if "reset == 1" ("if" must be accompanied by "else" in simscape language according to documentation). I tried setting x == x but this did not work. The code I have is written below. Any help would be greatly appreciated.
inputs
I = { 0, '1' }; % A:left
r = { 0, '1' }; % r:left
end
outputs
O = { 0, '1' }; % B:right
end
parameters
x0 = { 0, '1' }; % Initial condition
end
variables(Access = public)
x = { 0, '1' };
end
function setup
x = x0;
end
equations
if r <= 0
x == x0; % Reset x
else
%Do nothing
end
x.der == I * { 1, '1/s' };
O == x; % Set output
end
  1 个评论
Mathew Thorne
Mathew Thorne 2017-12-7
Hey,
Did you ever find a solution for this problem?
Using 2014b. Only solution I could think of was having an if statement, and setting the else to integrating a large positive or negative constant till i get close to zero.
But this defiantly not a good solution.
Mat

请先登录,再进行评论。

回答(3 个)

Nicolas Schmit
Nicolas Schmit 2018-1-24
I am not a Simscape developer, but from what I know Simscape will not let you manually reset integrators. A work around is to use a Simulink integrator and Simulink-PS Converter blocks.

David John
David John 2022-4-19
In 2018 it was true that Simscape did not let you reset integrators. In a more recent release, however, you can do it using the attached code at least since R2021a.

Martin
Martin 2023-1-9
The PS Integrator was updated in R2021a to provide this functionality. The source code is available for that block as well.

类别

Help CenterFile Exchange 中查找有关 Nonlinear Operators 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by