IPM Motor Simulator

From openinverter.org wiki
Revision as of 14:07, 7 January 2023 by Johu (talk | contribs) (Copy from forum)
Jump to navigation Jump to search

The IPM Motor Simulator - What is it

At its code the simulator is a mathematical model of an Interior Permanent Magnet (IPM) motor. This is wrapped with a Graphical User Interface (GUI) program that allows the voltage stimulus applied to the model, and the resulting motor currents and rotor position of the model, to be graphed. The program also includes hooks to allow the core control code from the OpenInverter (OI) firmware to be used to control the motor. The GUI allows the relevant parameter within the OI firmware, and the motor model parameters, to be sdjusted to see what effect changes may have.


Now the model isn't perfect, and it isn't supposed to be, but it is pretty close and good enough for its intended purpose which is to allow an understanding of the effect of parameter changes to be understood and to provide a safe way to evaluate OI code changes before testing in the real world.


Now because it includes the OI code, and because it is intended that you can try different versions of the OI code, it is available as full source code rather than and executable, i.e. you have to install the development environment/compiler as well as the source code and OI firmware and then build the code before you can use it. The process is pretty straightforward and allows the code to be run on multiple platforms (Linux, Windows and Mac to date), it also allows full source code debugging if you want to use it to develop the code or look for problems. The first thing to do is therefore to install the Qt development environment.

Installing Qt

To quote Wikipedia "Qt is cross-platform software for creating graphical user interfaces as well as cross-platform applications that run on various software and hardware platforms such as Linux, Windows, macOS, Android or embedded systems with little or no change in the underlying codebase while still being a native application with native capabilities and speed.". It comes in both open source and commercial versions and for home use the open source version is fine.


To install download the online installer from https://www.qt.io/download-qt-installer. You will also need to register for a Qt account. The default installation options should be fine. If you want to do a minimal install then you don't need the examples, documents or any extra architecture support although if you plan to use Qt for other work they might be worthwhile. Individual packages can allways be removed or added post install too.


I don't have any screen captures for this but there are plenty of install guides for Qt online.

Installing the Simulator and OpenInverter Software

This assumes that git is already installed, if not you will need to install that first (https://github.com/git-guides/install-git)


Go to the directory where you would like to install and do:

git clone https://github.com/Pete9008/IPMMotorSim

cd IPMMotorSim/

cd IPMMotorSim/

git clone --recurse-submodules https://github.com/jsphuebner/stm32-sine

This will copy the simulator code onto your machine and copy the OpenInverter code into a subdirectory within it. Johannes also has a fork of the repository which already includes the OI code it can be installed by doing a single:

git clone --recurse-submodules https://github.com/jsphuebner/IPMMotorSim.git

Currently the only difference between the two is the way a line of OI code is handled, Johannes automatically comments out a line of code that causes an oscillation in the simulator output but keeps it for real firmware builds. I'm not too keen on this as I believe the line also causes problems in real life and I'd prefer to understand and fix it rather than mask it in the simulator and so I haven't pulled this change. See here for details viewtopic.php?p=49172#p49172

Building the Software

Open Qt, go to 'Open Project' (either in the File menu or on the Home screen), browse to the directory where you installed the simulator and then go down into the 'IPMMotorSim' subfolder twice. In there there should be an 'IPMMotorSim.pro' file. Open this and you will get a 'Configure Project' dialog, just accept the default for this. You should see something like this:

To build the software go to 'Build' at the top and select 'Rebuild Project
IPMMotorSim'. This should do a full build of the simulator software and the IO firmware. On my Qt install (which is a little out of date) this results in 134 warnings. They are non-critical (mostly to do with unused variables in test stubs) and I realy should sort them out but haven't got round to it yet.
With that done you can run the software either by clicking the 'Run' button (green triangle at the bottom left), the 'Start Debugging' button (other green triangle with a bug icon) or by selecting the same from the top menu. With that done you should see something like this
Now on the first run the window positions are not set so the first thing to do is to set the windows up how you like them, this is how I set it up
On subsequent runs these positions are remembered. It's worth noting that the more windows you have active the slower the results are to draw.

The last thing to do is run the simulator to see if everything works, first change the values for Lq to 4 and Lq to 2 (so that it matches the Lq-Ld setting of 2 that has been pulled from the param file) and hit 'Run (1s)', you should see something like this: