Kemp’s Blog

A technical blog about technical things

OpenModelica and Python via CORBA (Part 3: Python wrapper)

Part 1 (getting started) | Part 2 (IDL compilation) | Part 3 (Python wrapper)

The final step in the process is to create a wrapper to allow easy programmatic control of OMC. I have posted a simple wrapper that provides the facilities required by the bouncing ball example here. It is not at the same level as the work by Ganeson et al. of course.

Using this wrapper, the bouncing ball example is much simpler than before, requiring only

import sys
from omc import OMC

omc = OMC()

print omc._send_command("model test end test;")
print omc.list_classes()
print omc.load_file("/usr/share/doc/omc/testmodels/")
print omc.simulate("BouncingBall")
print omc.plot("h")

Note that my wrapper doesn’t provide a specific method for directly injecting things like models. If it did, it would be a redirect to _send_command and so I’ve simply used that for this example.

With this fairly short third part, I will end the series here. Hopefully it provides a useful starting point for more complex projects.