Add Reset Function to Simscape Integrator Block

2 views (last 30 days)
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 Comment
Mathew Thorne
Mathew Thorne on 7 Dec 2017
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

Sign in to comment.

Answers (3)

Nicolas Schmit
Nicolas Schmit on 24 Jan 2018
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 on 19 Apr 2022
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 on 9 Jan 2023
The PS Integrator was updated in R2021a to provide this functionality. The source code is available for that block as well.

Products

Community Treasure Hunt

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

Start Hunting!