1/18/2016, Love that new code smell

So I started writing the MPF interface for the OPP hardware.  Brian offered to write the interface, but I know a lot more about the OPP hardware so I think that it is just as easy for me to write it and get it correct and optimize it properly.  I didn’t want to get into a situation where Brian spent a bunch of his time, I looked at the code and wasn’t happy with it, and rewrote it myself.  That would waste both of our time.

Installing MPF did not go as smoothly as possible.  MPF assumes that it is the first time that Python, Pygame, and PySerial are installed on a machine.  I had older versions of all three of these programs, so when I tried to start the demo machine in MPF it failed.  “DLL load failed: %1 is not a valid Win32 application.”  I’m was thinking to myself, oh great, I’ve just set myself on a couple day hunt and peck to try and figure out what went wrong.  Luckily it simply required uninstalling PyGame and reinstalling it again over the the new version of Python.  (I blame this issue on upgrading from Python 2.7.6 to 2.7.10).  I then had trouble running TK.  (import TKinter was giving the same issue as above.)  I uninstalled Python 2.7.10 and reinstalled it again, and now I was able to import TKinter.  MPF does not use TKinter, but my pinball framework uses it for running the debugging window.  I was happy to see that I could now run both frameworks successfully.  Last configuration change I had to make was to allow Python connections through my computer’s firewall.  MPF BCP connect sockets using a local loopback connection.  These were actively rejected on my laptop (Win 7 Enterprise Edition), so I had to Control Panel->System & Security->Windows Firewall->Allow Program Through Firewall, and browse to c:\Python27\python.exe.

Woo, hoo.  Up and running with the demo machine executing.  That was actually relatively painless.  (A couple more error checks could be used in the install script, but it does clearly state that the script assumes that no previous version of Python, PySerial and PyGame are installed.)

The thing in MPF that is used to support actual hardware is called a platform.  There isn’t currently any information on writing your own platform file, so you basically look at previous examples of platform files, and reverse engineer what they return to the rest of the framework.  There are already platform files for the FAST and the PROC and P3-ROC platforms.  They support some of the same functions that I support in the OPP hardware.  I based the OPP platform file off the FAST platform file.  I don’t think it would have changed things significantly to base the file on the P3, but I happen to choose the FAST file.  It is going well, but the new platform file isn’t done being written yet.

One thing that I do miss using C, C++, C#, etc is that it is very easy to define an interface.  Python does not really have any concept of what an interface is.  It also has the added benefit that if somebody calls your object, expecting a certain function and it doesn’t exist, it just crashes.  (Yeah, no type checking because that would restrict how things could be used)  Do you get a compiler error, oh no.  That wouldn’t be the Pythonic way to have to know what type of object you are talking to.  Instead it simply gives a back trace dump.  Hopefully all the functions are called frequently enough that I can easily find all the interface errors.

So, first thing I have to say about the MPF is that the documentation is really great, especially for a beginner.  Within a couple of hours, I was easily able to get a simple machine working that would do an attract light show, flip through my attract slides, and start a three ball game.  Most of that is built right into the framework which is really nice.  If you are following the tutorials, everything works really well.  In the tutorials, some of the background processing is explained which makes extending the example and modifying it to your liking easy.

When you get to the end of the tutorials, things become a little rougher around the edges.  I was not willing to dig into the core MPF code, but had some difficulties doing some very simple things.  There are currently no tutorials on playing sounds.  From programming my pinball framework, I knew this functionality should be very simple to get at using Pygame.  My main problem was that I didn’t know how to do it in MPF.  I immediately went to the forums but had difficulty finding information.  It was great that MPF has forums, but they aren’t very useful at this moment because they aren’t searchable.  After a day or two of mucking around, I finally figured out how to get it to work, so I could play a sound at the start of a mode.

I am planning on moving all of the SS3 rules over to MPF and posting the final files.  Hopefully this will give others a working example of running a full featured pinball machine using MPF.  This little exercise should force me to examine the differences between the two pinball platforms.

One major thing that needs to happen is that the MPF forums need to be made searchable.  I remember seeing a post that was related to something that I was putting off implementing, and even after going back and searching for a few hours, I could never find it.

Here are two quick pictures of comparisons between running the OPP framework and MPF.  I will describe more of the differences in a later post.

OPP Framework:


MPF Framework:


One quick thing to note is the jaggedness of the score font.  Both of the frameworks are using the exact same true type font file.  I might have to look into how MPF is generating its text.  This is one area that the OPP framework was optimized for printing text because it is assumed that it is going to be used for scoring.  The MPF framework puts much more emphasis on DMDs, and I think the code to display text is less mature.

When the OPP framework prints text, it is always right justified so it looks old style pinball displays.  I haven’t found an easy way to get this to happen in the MPF framework.  In MPF, the text anchor is always on the top left corner, so I will have to pre-process all scores to add extra spaces to get the text to not move as the score goes up.  MPF also post-processes numbers and adds the commas automatically.  That would be great, but in some cases, I don’t want to add commas to the numbers.

4 responses to “1/18/2016, Love that new code smell

  1. Hi Hugh & OPP readers! Brian from Mission Pinball here… This is awesome, congrats! I’m excited to be able to count OPP open source hardware among the platforms that MPF supports! Thanks for taking the lead on writing the platform interface!

    Good news that the next rev of MPF will include a completely rewritten media controller (powered by Kivy/SDL2) and will address a lot of what you mentioned here, including being much easier to install and support for alignment of text. We’re also building proper Python wheels for installation and will get everything added to PyPI, so installing should be as simple as “pip install mpf”.

    I’ll also completely update the documentation for the media controller, including adding more to the tutorial to include adding sounds and audio. (And I’ll make a note about the firewall on windows.)

    (BTW, you can add “number_grouping: false” to a text display element to remove the commas.)

    Now I’m off to figure out how to add better searching for the forums… 🙂

    Thanks again!

    • OPP readers…that’s funny. What you fail to understand is that the only person that reads the blog are my parents and this strange guy named Joe who I suckered (persuaded) into doing a whole bunch of free work for me. I had to offer him the VP of marketing position at the OPP just to keep him happy. (Quick strange fact, somebody from Jersey, the country, read a couple of pages from the website. That means that .001% of the population of Jersey is currently reading the blog. The previous leader was some guy from Luxembourg who I will assume was Andy Schleck as he is now retired and has some extra time on his hands. He was my favorite bike racer for quite a while, but alas, I digress.)

      I look forward to newer versions of MPF, and as I said, I know that I’m on the edge of certain things that are just being worked out. Your tutorials and documentation have been outstanding and I commend you on all the time that you spent putting that stuff together. I have some small corrections of errors that I saw in the documentation and will forward them to you when I have collected up enough to make it worth your time.

      The one thing that I’m really missing with MPF is a simulation environment. There’s that other project that is looking to hook into the BCP stream (Pinball labs maybe), but in my case that is sorely needed. I especially need to see the state of the incandescent bulbs in a simulator. Most of my coding and development are not done sitting beside a pinball machine, but through simulation to make sure rules work properly before I ever try it on a machine. A lot of the coding for SS3 was done using the simulator built into the OPP framework. That allowed me to code much of it while on business trips and such and really test things out. (If written properly, it can also be used to regression test pinball rules to make sure that changes to the rules don’t break old functionality.) The OPP framework throws up a graphic for each of the incandescent bulbs and turns them on/off or blinks them as appropriate. It also adds buttons so each switch can be pressed, or held on/off. (That is actually why the OPP framework needs TKinter to display the generic buttons.)

      Again, Mission Pinball has done a fantastic job so far. I look forward to future updates and added functionality. Rock on!

  2. And my on again off again pinball project that I might finish this decade

    • and…remember, we are already halfway through this decade. Ehhh, from when I started the first hardware design for OPP (Nov 2010) until SS3 was up and running in its first completed version took over four and a half years. Almost nothing happened for the first three and a half years when I was just tinkering. The last year was when everything came together. You’ll get there.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s