MERG Article - Controlling a Crane
A small change to this month's 'My Workbench' article, rather than talking about my control play ground project, I'll be talking about a small project which has recently taken a sizable chunk of my model railway time (not that I care). And no I don't feel guilty about it - my regular feature was pitched to the editor ( a few issues ago now) as a what's on my workbench series rather than a my control playground series.
At a recent local MERG meeting we had a new member pop along to say hi and ask for some suggestions on controlling some container cranes on his club's layout. Several suggestions were thrown about and I ended up offering my services to help implement the chosen solution.
The problem the club were having was the unsightliness of the 9 way ribbon cable and the awkwardness of the controller, both of which are being fixed. The ribbon cable is now redundant thanks to DCC, the crane runs along two rails (which will be powered) and the moveable top part also runs along two rails (which will also be powered) and 3 DCC chips will be hidden inside the frame in order to allow the 3 movement directions (forward/back, left/right and up/down) and 4 functions (cab light, flood light, warning lights and grabber release) to be controlled.
The controller will be a much simpler affair with 2 joysticks to control the movement. They'll be a button to control the grabbing and three switches to control the lights.
The controller is plugged into a computer which sits between it and an ecos command station, issuing commands over the network connection as needed.
The controller will be made using a useful item from www.u-hid.com which plugs into the USB port and the computer sees as a number of HID (Human Interface Device) devices allowing each of its pins to be configured as a number of things. Usefully for the project this includes a joystick axis and a joystick button, needing just 3 axis and 4 buttons means we can get away with the smaller version (with no pins to spare). Potentially also of interest to MERG members is a thumb joystick I found at www.sparkfun.com.
The software I'm writing has a fairly simple job to do:
- Take the inputs from the joysticks
- If a speed has changed then scale it (from 0 -> 65535 to -28 -> 28) and tell the ecos
- If a button/switch has changed then tell the ecos
The software can support any number of cranes but only 16 joysticks (a limitation of the windows API I'm using). It does however allow for a function to be assigned to any of the 32 buttons allowed on a joystick and a movement axis to be controlled by any of the 6 allowable joystick axes, so in theory 32 cranes could be controlled from the same PC.
The first of the screen shots shows the program containing both a crane form (any number of these can be open) and an output form. Currently the output form just displays a message for each thing which would be sent to the ecos, it will in future be responsible for sending the instructions to the ecos. You can see the crane is in setup mode, this is where the axis of the joystick are assigned to DCC addresses and buttons are assigned to both addresses and function numbers. The crane state section gives a graphical representation of what the crane would do.
The second screen shot shows a close up of the crane form and output form except this time the crane is in run mode. By having this setting at the form level it is possible to tweak the settings for one crane whilst allowing the others to continue to be operated. A future revision may allow for all cranes to be entered into either setup mode or run mode in a single operation.
I've left the writing of an article on the process of converting the crane (if he decides to) to my partner in crime with respect to this project. Next issue I'll be back to normal, probably writing about some of my RFID experiments (as I write this they are planned but not yet done).
The above is the article as written for the Summer journal, however it got bumped owing to the journal editor having the good problem of too much content. Since writing the above I would have aimed to turn this article into a one discussing a finished rather than current project, especially given our deadline of the local exhibition after Summer. However various annoying issues on my main PC have prevented this from being the case. In order to get something working the plan for version 0.2 is to have the software speak to a SPROG (which I already have the code for) and have the SPROG connected to the sniffer port on the ecos. This will mean that something is working by the deadline, thus relieving the pressure to understand a machine translated technical manual in order to talk to the scos in version 0.3.
The pictures in this article show the crane in the local MRC's new home, it is in O scale and straddles three tracks plus a road. I hope to have Part two reporting on the issues of actually getting it to work written in time for the Winter journal, strange as it seams to be writing that during a hot Summer's day in a building with broken air-con, I'm just glad I'm up here in the cooler North.