Reset an integrator at initial value at specific times #53
-
|
Hi @milanofthe ! In my application I would like to reset an integrator a specific times, say t={5, 10.1, 15}. What is the most efficient way of getting this? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
|
@RemDelaporteMathurin Id say using the event system. The blocks have a from pathsim.blocks import Integrator
from pathsim.events import Schedule
#integrator with initial state of 10
itg = Integrator(10)
#callback that resets the integrator to initial state
def reset_itg():
itg.reset()
#build single scheduled event for each event time
events = []
for t in [5, 10.1, 15]:
events.append(
Schedule(
t_start=t,
t_end=t,
func_act=reset_itg
)
)
#add the events to the simulation
# ...I think this is kinda clunky though. PathSim might benefit from a new scheduled event type that can be defined by a list of event times. This would make a lot of sense. |
Beta Was this translation helpful? Give feedback.
-
|
That looks good! Would it be possible to have this reset happen in a similar way to Simulink? See this |
Beta Was this translation helpful? Give feedback.
-
|
@RemDelaporteMathurin you can now use the |
Beta Was this translation helpful? Give feedback.
-
|
@milanofthe is there a way that these events are internal to the block and live there instead of being passed to the |
Beta Was this translation helpful? Give feedback.
@RemDelaporteMathurin Id say using the event system. The blocks have a
Block.reset()method that, for the integrator, resets it to the initial state. You could trigger this with scheduled events. Right now, your example would require three separate events, because they are not evenly spaced like this: