Wednesday, January 31, 2018

Turntable (Pt 3) - Control



For the actual operation of the turntable I originally wanted to use an Arduino Uno with a motor control board driving a stepper motor (if you're not familiar with Arduino here's a quick explanation).  Three good sources for Arduino stuff are Arduino, Adafruit and Sparkfun.  This is probably the cheapest way to go but I'm new to the programming so there's a learning curve involved.  I waffled on just using manual control with a gear or belt and pulley driven by a hand crank.  Still pretty cheap but the operation of the turntable will be from 2.5' away and I'm concerned about getting the tracks lined up properly.  So now I'm back to the Arduino control because you can program it to do very accurate indexing and with a stepper motor it would be repeatable.

I ended up going to the Yahoo group "Arduino for Model Railroading" (click here) to ask for help.  Several folks there were very helpful and stuck with the project for a few weeks to develop a working sketch (program).  This required a lot of going back and forth because they had the programming knowledge but I had the gear to run it on.  Suggestions would be made and then I would modify the sketch and run the program.  In the end we came up with a very cool control system for the turntable.


The system consists of an Arduino microprocessor, the Mega 2560, running a 4x4 matrix keypad, a Nokia LCD display and an EasyDriver board running a NEMA 17 stepper motor.  This is a stand-alone system and won't need to be connected to a computer to run.  The Mega and the EasyDriver both run on 5VDC and the stepper motor runs on 12VDC through the EasyDriver.  The Mega provides power for the Keypad and the LCD.

If you're not familiar with some of this stuff I'll give a quick explanation.  The Arduino Mega ($17 - $25) is a larger version of the Uno, mentioned earlier.  It's a small microprocessor that can be programmed through a USB connection to your computer.  Once it's programmed it can run independently on power from a wall-wart style power supply or even a battery.  The board has numerous pins around its perimeter for input and output connections.  The EasyDriver ($8) is a stepper motor control board that uses a "library" of commands to provide custom control of the motor.  The 4x4 matrix keypad (5 for $7.50) has 16 keys set up in 4 rows and 4 columns.  The keys are 0 - 9 and A,B, C and D.  The keys can be programmed to be anything you want; symbols, numbers, letters, anything.  The LCD ($5) is actually a display from an older style cell phone.  It doesn't do color but can display low resolution images.  You can use Photoshop to make your display as a GIF file and then use an app to change it into code that the display understands.  The NEMA 17 stepper motor ($17) is a medium size (NEMA 17 is the size) motor that has a bunch of coils mounted around the output shaft that causes it to rotate in steps.  This one uses 400 steps to make a full rotation.  I'm mounting a 20 tooth pulley on the motor and a 60 tooth pulley on the turntable shaft to give me a 3:1 ratio so it takes 1200 steps to make one full rotation.  The EasyDriver can operate in 1/8 steps so I'll be running 9600 steps per revolution to give very smooth operation.  The total investment for this control system is about $75 and that includes everything mentioned above.


The program, called a sketch, is pretty cool.  When it's first initiated the stepper begins homing in full step mode.  I've mounted an Infra-Red Beam Break detector under the turntable platform.  As the turntable bridge rotates it also rotates a small metal flag attached to the shaft beneath the layout.  When the flag interrupts the IR beam it sends a signal to the Mega board which stops the stepper and sets that point as zero.  Everything the stepper does from that point on is referenced to that point.  There are 16 tracks around the turntable pit and each track is a certain number of steps from the zero point.  They're listed in the program and that's how the stepper knows where to find a specific track.  I can punch in a "2" on the keypad, hit the # key to enter it and the bridge/stepper knows to turn 90 steps to get to that point.  If I enter 15 it'll go 975 steps.  That's full steps though.  The program knows that after the zero point is established it needs to multiply everything by 8 so that 975 steps now becomes 7800.  That's how you get the smooth operation.  The EasyDriver also uses code that automatically starts and ends every motion by slowly ramping up speed at the beginning and then ramping down to a stop.  This creates a very realistic motion for the turntable bridge, especially since my turntable will be representing an Armstrong turntable, one that was totally positioned by man power.


Prototype turntables were used to position locomotives, to turn them so they'd be headed in the right direction for whatever job they had next.  Sometimes an engine would come onto the turntable so it could be swung around 180 degrees and head back out.  To simulate this I can enter the track number on the keypad and then enter "A" and the program knows to add 600 full steps or 4800 1/8 steps to the track value.  If an engine comes onto the turntable bridge at track # 15 I can enter 15A on the keypad and the engine will be turned 180 degrees and it can go back out track #15 in the opposite direction.  Using the * key you can erase an entry for a track number if you make a mistake.  There are still 3 other keys not used yet; B, C and D.  I'm planning to use a thumbstick (small joystick) to manually drive the turntable and one of those keys will be used to initiate that.

The LCD screen is set up to display current track #, next track # and it also displays "mvng" (moving) when the bridge is in motion.

Anyone interested in using the turntable sketch for their own project can find it at the Yahoo group mentioned before, "Arduino for Model Railroading".  It's located in the "Files" section in a folder called "Turntable Indexing".  Here's a link to the folder (click here).

Update (2-23-18):

Over the last three weeks I made some changes to the Arduino software.  The biggest one was adding the use of a joystick for manual control.  It's set up so you hit "C" on the keypad to run the turntable manually and "D" to return to keypad control.  The joystick is only connected for operation on the X axis so pushing it to the right drives the turntable CW and to the left CCW.  There are four speeds for the stepper motor in this mode so the further you push the control the faster it will go.  The speeds are 1, 2, 7 and 38 steps per second.  This is using full steps so the motion is course but the main purpose is for setting up track locations around the turntable pit.  You would drive the bridge at a faster speed and slow down as you approach the spot you want.  The display shows the actual full step distance from zero, which speed setting you're in (1 - 4) and says "stick" to indicate joystick control.

There is quite a bit of math involved in setting up a turntable using a stepper motor.  To start, you have to find equivalents for metric and fractional parts.  The stepper motor shaft is 5mm and we need a 20 tooth pulley for that.  The pulleys turn a metric GT2 belt that has teeth spaced 2mm apart.  The stepper motor uses 400 steps to make one full turn.  The turntable shaft is 5/16", or 0.315" in diameter.  This is equivalent to 8mm which is also a common size for GT2 pulleys.  I chose one with 60 teeth which gives me a ratio of 3:1, or three turns of the stepper to rotate the turntable one full turn.  That means it takes 1200 full steps for one rotation.  It's important to make calculations for track locations in full steps because if the motor stops on a partial step it will relax to a full step position when the power is turned off and this will cause a track misalignment.  So, we have 1200 steps per revolution.  We need to calculate the circumference of the turntable pit so we can figure out where to put the tracks in full step locations.  My pit is 13.75" in diameter.  To get circumference you multiply diameter times pi or 13.75 x 3.14 = 43.175".  Now we divide that by 1200 to get 0.036" per step.  Since I'm using On30 track my rails are 11/16" apart so I can safely separate the tracks by just over 1" center-to-center which works out to 30 full steps.  Perfect.  With a circumference of 43" I have 42 possible track locations around the pit.


My track plan only calls for 16 tracks and most of those are storage or dummy tracks, too short for cars or locomotives.  If you view the picture above as a clock then the 12 o'clock position is the return lead coming in across the ashpit.  This is track #0 and is the zero location for the stepper motor.  The tracks are listed below and follow a CW rotation around the pit.

Track #         Name             Degrees    Full Steps      Micro Steps
___________________________________________________

   0           Return Lead           0                 0                     0 
   1           Storage #1            20               60                  480
   2           Storage #2            30               90                  720
   3           Ready Track         40             120                  960
   4           Shop Track           55             180                1440
   5           Stall #1                 70             240                1920
   6           Stall #2                 80             270                2160
   7           Stall #3                 90             300                2400
   8           Stall #4               120             330                2640
   9           Plow Storage      135             375                3000
  10          Crane Storage     165             405                3240
  11          Storage #3           195             435                3440
  12          Storage #4           205             465                3720
  13          Storage #5           220             600                4800
  14          Outbound N.       295             765                6120
  15          Outbound S.        325             975                7800

When I start laying track I'll use these numbers to manually drive the turntable bridge to the right location, mark center-of-track and position the ties and rail for best alignment.

On the underside of the pit floor I've mounted an IR beam-break detector and attached a flag to the turntable shaft.  I found that the best material for my flag was a short section of an old hack saw blade.  I tried several other materials but they didn't interrupt the beam.  Not sure why.  Anyway, the flag gets positioned so that the detector sends an interrupt when the bridge is aligned to the zero track.  This gives the stepper motor a way to keep track of it's location and it references everything to this zero position.

I also added easy disconnect plugs to the stepper motor and detector wires.  Being able to separate the control panel from the turntable makes installation and removal easier.

No comments:

Post a Comment

Painting Plaster Castings

 Today I painted the remaining walls of the roundhouse and thought I'd add a blurb here to share my technique for painting plaster stone...