Model Railway Laboratory

Lately I've been beavering away on a project to add wireless remote control to some of my trains. It is a fairly complex project, the hope though is that by having wireless controllers in each loco, with a battery on board, I can alleviate a few pet modelling peeves of mine:

So nothing too complex!! We'll see how far I get.

As part of this, I need a way of testing my code. My day job involves writing a lot of code, and writing a lot of code to test my code. Luckily for that we have automated testing. Every change I make, I run the automatic tests, and if any of the tests fail, I know I broke something.

It's one thing to test some code, that is just a bunch of numbers in a computer somewhere. But testing a real, physical loco? That is a bit more complex!

The Lab

One of my favourite blogs is the Model Railroad Tools Lab. Even translated into English, I fail to understand most of it. However, I do admire his "tools lab", where he measures every possible performance metric he can about his trains.

So that gave me an idea...

What I've done is build up a micro testing rig. It has two motors, each with an optical encoder. One half of the system emulates my decoders. The other half is set up as a dynamometer, a fancy tool that uses its motor as a variable load, and measures the effect it is having on the other half using its rotary encoder.

The mechanical and optical parts come from various old inkjet printers, and the mounts are, naturally, laser cut. The encoder wheel is also laser cut, something I am quite proud of. The encoder mount I made on my lathe, and a length of clear tubing connects the two motors.

Electrically, there are a couple of Arduinos, the ubiquitous L9110S motor driver, and a NRF24L01+ wireless module. Working out the pinouts of the encoders took a bit of head scratching, but I got there in the end.

Software side, I have lots of C++, with a smattering of Coffeescript to glue together wireless, serial, and network communications, and lots of Ruby for the unit tests. Now I can code away in bed, testing my changes as I go, knowing that my code will work just as well in my trains.

Newer Older