Category Archives: Coding

Packaging a Python app for Windows

This post gives an overview of the steps to package a Python application for distribution to Windows users in such a way that they don’t have to worry about installing Python, additional modules, and so on. This is significantly more convenient if they are not an experienced computer user, or if they simply have no need for Python otherwise. My particular approach is based around a combination of PyInstaller (to create a Windows executable) and NSIS (to create the installer). I’m not an expert in this and in fact this is my first experimentation outside of py2exe, so your own judgement should be applied. However, this technique worked for me and seems to have been used by people previously (for example, this Stack Overflow answer).

Continue reading

Modelica external C functions

This post looks into getting external functions working in OpenModelica and, to an extent, Dymola. There are a couple of approaches and I hope to give you a better idea of what to look out for when you come to implement your functions.

You may have noticed that my series on Modelica socket communication stalled somewhat after only one part. Originally, this post was going to be part 2 of the series, but it has become somewhat more general, so I’m posting it as a separate thing.

Continue reading

Plotting hardware stats via plotly

I recently signed up to try the beta of Plotly (@plotlygraphs) and decided to try it out by plotting the temperature, CPU load and RAM usage of a Raspberry Pi. Temperature, particularly, was of interest to me as I intend to stream video from the camera module, which makes heavy use of both the GPU and CPU. Plotly provide a Python API, which suits me perfectly.

Continue reading

Modelica socket communication (Part 1: socket library)

Now that I’ve demonstrated a method of using the OpenModelica CORBA interface to set up and run simulations, I will move on to a way of passing data out of and in to a running simulation (for example, to use a control algorithm that is more easily implemented in another language). I will use sockets for this as they are one of the simplest and most generic communication methods available.

The first step in setting up socket communication within a Modelica simulation is to create a socket library that can be called from the simulation code. Fortunately, this is very simple C code. You can find the relevant code here.

Continue reading

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.

Continue reading

OpenModelica and Python via CORBA (Part 2: IDL compilation)

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

In part 1 I showed you how to get set up with the omniORB library/tools to communicate with OMC from Python. This post will show how to compile an IDL file to provide the appropriate interface to your script. This post assumes that the environment variables from last time are still set up and that you have OMC running with the +d=interactiveCorba parameter.

Continue reading

OpenModelica and Python via CORBA (Part 1: getting started)

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

In this post I’m going to be walking through the process of setting up omniORB with Python for the purpose of interacting with the CORBA interface provided by the OpenModelica compiler (OMC). This allows OMC to be controlled from a Python script (loading simulations, changing parameters, etc). While the intention of this post is specifically that of interacting with OMC, the installation of omniORB will be the same in other situations. Note though that you may require additional setup in these other situations, for omniNames for example. I will be showing the setup process for Linux (and specifically, Mint/Ubuntu). I will assume that OpenModelica is already installed.

Continue reading

Python tips – List iteration and item removal

Occasionally my code is required to work through a list and delete items that are not wanted. Take, for example, the case of appending the data from two CSV files to create a new file with both sets of data in. It may be that they don’t have exactly the same columns in, but the common columns are the only ones you are interested in anyway. This is slightly more complex than simply ‘cat’ing the source files into the target file, so let’s assume you want to knock together a quick Python script to do it. I will first present the easy but wrong way to do it and then show how to adjust it to be correct.

Continue reading