Brewery Simulator

Debugging code that runs on the brewery takes time and is not simple. Software that heats and transfers physical quantities of liquid results in a slow, constrained debug environment.  To avoid these issues I decided to incorporate a brewery simulator into the code.

The physical nature of process control takes time and energy to run through the code. This makes debugging a difficult and time consuming process. Until recently this meant I had to run snippets of the code in isolation. For example the transfer of liquid, heating of kettle and chilling of the kettle were tested individually. This still took a long time to find and fix bugs.

To avoid a lot of this pain I decided to incorporate a simulation mode that would allow me to run and test the code on a windows PC instead of a Raspberry Pi. This required a a few simple modifications:

  1. MRAA is currently used to drive the I2C and GPIO pins on the Pi. I replaced this with a stub that mimics pin activity. This meant that all higher level code works as is without any changes.
  2. The publish-subscribe model facilitated a simple simulation model in which sensor events are subscribed to. For example, flow sensors subscribe to Pump events and publish simulated pulses. Also, the Kettle temperature sensor subscribes to Power settings and publishes fluid temperature changes

One of the major benefits was allowing the  simulation to run many times faster by modifying a few timing constants. The same monitoring web page could be used to watch the brew progress – which is fun.

In conclusion. Running the process faster than real time made debugging really fast and simple. This resulted in a significant number of problems being identified and fixed which otherwise would have taken many months of real-time testing and development. Not to mention the cost savings of not having to heat and pump water around.  The nature of the publish-subscribe model made it simple to adapt the behavior for simulation mode. Running on Windows also means that the post processing of results to draw graphs and publish data etc could also be tested with ease.