FMPy icon indicating copy to clipboard operation
FMPy copied to clipboard

Add Real Time option

Open moxxensen opened this issue 4 years ago • 6 comments

To test FMU's sometimes it is helpful to simulate it in Real Time

moxxensen avatar Nov 22 '21 13:11 moxxensen

I'm looking a way to simulate FMU sample by sample, instead of simulating all the way from start to stop time. It looks like high-level fmpy.simulate_fmu(fmu) does not suppose to support that. Is there a recommended way to do that with fmpy? I assumed that #341 issue is exactly about that and would like to know more about the implementation possibilities or future features.

In order to give more details, here is example of my application: I need to design and implement a regulator, that controls a complex plant. The plant is exported as FMU model with corresponding inputs and outputs. The regulator will be developed in python/scipy first and then will be reimplemented in C++ for an end user application. But it need to be tested in sample-by-sample basis: plant model generates single output, the regulator reads plant's output and generates single sample of control as next plant's input and so on.

Robotics010 avatar Apr 20 '22 15:04 Robotics010

@Robotics010, the easiest way to achieve this, is to write a custom simulation loop. You can use custom_input.py as a starting point.

t-sommer avatar Apr 22 '22 14:04 t-sommer

Thanks @t-sommer, I didn't note this example. I'll post here later about the result.

Robotics010 avatar Apr 22 '22 14:04 Robotics010

Yey! I've got custom_input.py example adapted to my application. Thanks for a reference.

What @moxxensen did mean more by Add Real Time option? It looks like sample-by-sample behavior already has been implemented. If so, the issue can be closed. Or there is something need to be developed further among Real-Time support features?

Robotics010 avatar Apr 27 '22 13:04 Robotics010

What @moxxensen did mean more by Add Real Time option?

Real Time as in "synchronous with the wall clock time".

t-sommer avatar Apr 27 '22 15:04 t-sommer

Hi @t-sommer , PROBLEM: We cannot produce reliable co-simulation (CS) fmu's from our modelling tool. We can produce ME fmu's. A CS fmu is needed so that we can either:

  1. use it in our real-time toolset (using fmi-adapter for ROS), or
  2. be able to write our own custom Python script around the doStep method and include it in a node for ROS.

QUESTION: Since we can produce very reliable simulations by coupling our model-exchange (ME) fmu's to your CVODE solver in FMPy (thank you!!!!), we would like to know if there is any existing way we can export these ME fmu's + CVODE solver as CS fmu's from FMPy? Or are there examples of coupling something like doStep to use an ME fmu?

If NO to both questions, we will try to dig more and see how to create our own CS fmu's, so any clues would be helpful.

Thanks again for your wonderful toolset!

githubfrond avatar Aug 11 '22 01:08 githubfrond