johbrust / simulink_gym

Gym Interface Wrapper for Simulink Models
https://quire.io/w/Simulink_Gym
MIT License
14 stars 0 forks source link

Variable Step Solver: Multiple outputs at same simulation time #13

Closed gearskill closed 9 months ago

gearskill commented 9 months ago

Hello, I am trying to run a model which uses a variable step solver. The problem is that at certain time steps, the simulation results are numerically very high/low and then they get back to the expected level in the following simulation steps. I think that this might have something to do with the fact that python receives states at the exactly same simulation-timestamp and therefore the variable step solving procedure gets mixed up. Furthermore, I noticed that the output time steps are also mixed up sometimes.

I already set the priority of TCP/In to 1 and TCP/Out to 2. Running the model with a constant input just within Simulink works well. Furthermore, I set the sample time of the TCP/In and TCP/Out to inherit, i.e. -1

Do you have any idea how this issue can be solved?

gearskill commented 9 months ago

I think I solved the problem.

Set the sample times of TCP/In and TCP/Out to be reasonable (e.g. =1) instead of inheriting it.

johbrust commented 8 months ago

Hi and sorry for the late reply!

Setting the sample time for input and output to some fixed value seems like the right idea. Having an interaction between agent and environment with a variable step size (which would be the case if you inherit the sample time) is not useful from a deployment perspective since once the agent is deployed something else than the solver has to decide on the step size. In deployment, you usually set a reasonable fixed time interval (as you already did).