You're reading ...
Arduino, Hardware, Software, Traincontroller

Traincontroller 53 – Speed profiling an engine using an external device.

This is part 3 of 3 on a € 6,- DIY model train speed measurement device.

Part 1: The hardware
Part 2: The Arduino software
Part 3: Speed profiling an engine in Traincontroller 9 with an external device

Traincontroller 9 has a semi-automated speed profiling option for use with a ‘third party device’. Well … that ‘third party’ … that’s us! With our brand new built Arduino speed measurement device described in part 1 and 2.

The TC measurements are done one by one. When we press START the engine starts to run with a speed and direction set by TC. Our device performs the speed measurement while the train passes by. When done, we press STOP and TC shows a field where we can enter the measured value. We now press START again to start the next measurement. And so on.

Despite the operator interaction, measuring a complete speed profile this way takes far less time than it would otherwise, because the device performs the measurements with high accuracy over just a very short distance.

The steps to take to profile an engine with an external speed measurement device are:

  1. If your Command Station has the option to select the DCC output voltage, set it to the desired value and from there on never change it again.
  2. Set your loc decoder’s CV3 (acceleration) and CV4 (deceleration) to 0 (or to 1, if 0 gives problems) and ensure that ‘traction control’ is enabled (refer to your decoder’s user manual how to do this).
  3. Tune CV2 (minimum speed at step 1), CV5 (maximum speed at step 28) and CV6 (medium speed at step 15) such that you derive speed values that you like, using the measurement device. Example: 4, 80, 40 km/h. Also measure the backward max speed … this may differ some.
  4. In TC9, go into Edit Mode and double click the engine to profile in the ‘Engines+Trains’ window to open its properties window.
  5. Click the ‘Speed’ tab and enter the maximum speeds you just measured in the ‘Forward’ and ‘Backward’ fields.
  6. Now click the ‘Automatic Speed & Brake’ button and in the new window click ‘Advanced Fine Tuning’. We’re in the speed calibration window now.
  7. First click the ‘Threshold Speed’ tab. Move the green slider to forward speed step 1. The engine now runs at the minimum speed we just tuned with CV2. Click ‘Store’. Do the same backward.
  8. Now click the ‘Speed Profile’ tab and from the ‘Measurement’ drop down select the one with the tools icon, where the tooltip says ‘Measurement of the complete profile with a third party device’.
  9. TAKE CARE: Set both the ‘Run Out’ and ‘Pause’ fields to zero. If there is a non-zero value in the ‘Run Out’ field, your engine will keep running after you pressed ‘Stop’ … we don’t want that.
  10. We’re ready to start measuring. Place the engine such that the forward direction is towards the measurement device. Just a few cm away is fine at low speeds; this will give nice short measurement times. Now press ‘Start’.
  11. The engine now runs through our measurement device. Once it is fully out, press ‘Stop’, read out the km/h value, enter it into the field presented by TC and click ‘OK’.
  12. Click ‘Start’ again to start the next measurement (this will be backward). And so on … until 14 forward and 14 backward measurements are done. Take care to let the engine run a bit further away as the speed increases … we need to give it some room to accelerate.
  13. When the speed calibrations are finished, select brake compensation measurement from the drop down.
  14. Enter the brake ramp distance you use in the majority of blocks and set the slider to the speed with which you usually enter blocks where you want the train to stop.
  15. With a few iterations, tune the ‘Brake Compensation’ forward and backward values such that the engine stops accurately at the distance specified.

The video shows the whole process.

 

 

About RudyB

Hobbyist

Discussion

21 thoughts on “Traincontroller 53 – Speed profiling an engine using an external device.

  1. Willing to help anyone get this working. You need PyCharm as the IDE

    Like

    Posted by Eddie Jones | January 24, 2022, 00:20
  2. Python code for anyone who is brave enough:
    import serial
    import pyperclip as pc
    import PySimpleGUI as sg

    global port_number
    sg.theme(‘DarkAmber’) # Add a touch of color
    # All the stuff inside your window.
    layout = [ [sg.Text(‘Get Train Controller ready to speed test’)],
    [sg.Text(‘Enter Serial Port Number COM’), sg.InputText(size=(6, 1))],
    [sg.Button(‘Ok’), sg.Button(‘Cancel’)] ]

    # Create the Window
    window = sg.Window(‘Serial speed reader to clipboard’, layout)
    # Event Loop to process “events” and get the “values” of the inputs
    while True:
    event, values = window.read()
    if event == sg.WIN_CLOSED or event == ‘Cancel’: # if user closes window or clicks cancel
    break
    else:
    port_number = ‘COM’+values[0]
    break

    print(port_number)

    serialPort = serial.Serial(port=port_number, baudrate=9600, bytesize=8, timeout=2, stopbits=serial.STOPBITS_ONE)
    serialPort.close()
    print(‘Serial Port Closed’)
    serialPort.open()
    print(‘Serial Port Open’)

    # Close Opening Window for Com port number
    window.close()

    # All the stuff inside your window.
    layout = [[sg.Text(‘Reading Serial Data’)],
    [sg.Text(”), sg.Text(size=(40,1), key=’-OUTPUT-‘)],
    [sg.Button(‘Cancel’)]]

    # Create the Window
    window = sg.Window(‘Serial speed reader to clipboard’, layout)

    serialString = “” # Used to hold data coming over UART

    while True:

    event, values = window.read(timeout=100)
    if event == sg.WIN_CLOSED or event == ‘Cancel’: # if user closes window or clicks cancel
    break
    elif serialPort.in_waiting > 0:

    # Wait until there is data waiting in the serial buffer
    var: bool = serialPort.in_waiting <= 0

    # Read data out of the buffer until a carriage return / new line is found
    serialString = serialPort.readline()

    # Print the contents of the serial data
    print(serialString.decode('Ascii'))

    # Copy the contents of the serial data to the Clipboard
    pc.copy(serialString.decode('Ascii'))

    # Put Serial data into Window
    window['-OUTPUT-'].update(serialString.decode('Ascii'))

    serialPort.close()
    print('Serial Port Closed')

    Like

    Posted by Eddie Jones | January 24, 2022, 00:17
  3. I have been planning of making one of these ever since you posted this and finally did it. I modified your code a little to only send over the speed, and only the number. Then made a small Python App to read the serial data and post to the clipboard. Traincontroller then reds this and controls the whole speed operation. The first pass till need to be monitored as Traincontroller doesn’t know the speed and reverses too early(possible bug in TC) but every other run after is flawless. It saves so much time setting up engines. Thans for the help and inspiration Rudy (Yet again) 🙂 If anyone wants the Serial read and copy App its here https://1drv.ms/u/s!AowqasI1coAD8fZYvZFnAKRnds7rXA?e=1NZOf6

    Like

    Posted by Eddie Jones | January 24, 2022, 00:16
    • Hi Eddie. That’s great work! I once did something similar using Autohotkey to copy & paste the speed value from Notepad to TC. It worked too, but we have a lot of trains to handle at the railway club and more often than not something went wrong halfway the process, like a train not reversing, or a hang … in the end it turned out to be faster if we just manually typed in the numbers. 😉 Unfortunately the TC speed profiling process is the worst of the worst designs, if something goes wrong you have to start all over again. With any other train control program you can also measure one specific speed step and fill in that number in a table. I have talked with Freiwald about improvements but he is reluctant to improve the software.

      Like

      Posted by RudyB | January 24, 2022, 09:49
  4. Hi Rudy,

    I am already successfully using the Arduino to measure the speed for the Traincontroller. However, I still have to manually transfer the measured values to the traincontroller.

    So far, I have searched the internet unsuccessfully for a solution/source that helps me with automation.

    I have now found a hint here in the comments that there are already private scripts (e.g. via autoit) that would solve my problem.

    Would you be so kind and could you give me a contact or even a source ?

    Thanks a lot for sharing this Information

    Like

    Posted by Carsten Müller | December 14, 2021, 10:52
    • Hi Carsten. I have been working on a method that uses Autohotkey to automatically mousr click the righ spots and copy & paste the value that was written to a text file. It worked some times but also some times it did not work perfect until the end of the cycle and I could not figure out why and then I was too busy with more important stiff and I left it for what it was … and experiment. Can’t share it because it’s completely undocumented and it’ll take too much time to figure it all out again.

      Like

      Posted by RudyB | December 18, 2021, 16:31
  5. Thanks so much for this Rudy! I built a similar speed measurement device using an Arduino nano and some diodes from cheap TCRT5000 sensors. I modified your Arduino code so that only the raw speed is sent to the serial monitor. and then used a little 10 line python script in Windows to monitor the serial port and copy any data onto the windows clipboard. That gives me fully automated speed profiling in Traincontroller! I noticed the Arduino code that wrote to the display had quite a bit of overhead so that the slowest timing I could get was about 700ms (~160km/h in N scale at 200mm sensor separation ) – by commenting out the zeroing of the display at the start of a run would get that down to about 300ms. This is going to save a lot of time profiling my locomotives!

    Like

    Posted by Chris C | June 16, 2019, 00:48
  6. Hi Rudy, I got interested in your ”speedometer” for the modeltrains. I’m a user of the ESU ECoS and Traincontroller And decided to build me a similar using most of your code. What’s missing is the interface to Traincontroller which can be easily be fixed with ”AutoIt” scripting language for Windows. I have written a little Windows program using AutoIt which will read the serial from the Arduino and place the value on the clipboard for Traincontroller speed profiling. Works great! Please contact me if you find this interesting. Best regards /Peder

    Like

    Posted by Peder Berggreen-Clausen | April 26, 2019, 14:41
    • Peder, that sounds absolutely great. I am a user of AutoHotkey, which is somewhat similar to AutoIt. I’d be very intersted to see what you have made. At the museum we need to profile many trains, automating it will gretly reduce the effort. I will send you an email.

      Like

      Posted by RudyB | April 27, 2019, 08:03
  7. Guten Tag Rudy.
    Ich habe arduino-1.8.8 installiert aber der Speed-Measurement-Device folder und sketch ist nicht auffindbar.
    Kannst Du mir weiterhelfen?
    Liebe Grüße
    HDGSandkrug

    Like

    Posted by HDGSandkrug | January 23, 2019, 11:12
  8. hello Ruud,im ital247, i first contacted you in relation to getting a walthers 130″ turntable to work using train controller gold software via video traincontroller 53 on youtube. i am still unable to get these working together, can you help me please?

    Like

    Posted by ital | September 9, 2018, 20:35
  9. hallo Rud! What about the use of a ‘roller test bench’ as indicated at pg.128 of TC9Gold manual? In this case we do have a train rolling on ‘its own’ only…than how to perform the speed measurements?
    …thks for all your cute exercises about TC

    Like

    Posted by vieri | April 11, 2018, 15:38
  10. Hi Rudy. Isn’t the speed measurement using a distance of 200mm inherently less accurate than say, using the distance of a Block on the layout of perhaps 1M or more when using TC to make the measurements using indicators?

    My thinking is that in such a short distance speed variations of the locomotive due to gear wear, inaccurate decoder, motor speed ripple, temperature, etc. have a greater impact on the measurement accuracy than over a greater distance where momentum aberrations are more likely to average out.

    Like

    Posted by Geoff | April 9, 2018, 15:40
    • Sure, the longer the track, the higher the overall accuracy (given an accurate time measurement) and the more all kinds of aberrations average out. But the device is more than accurate enough and it gives a substantial gain in the time needed for a complete profile. Plus … it is just fun to build and to have one.

      Like

      Posted by RudyB | April 9, 2018, 15:50
      • Absolutely! Actually, I had been looking for an Arduino project to learn on as well as incorporate into my MRR activities and this looks perfect. Indeed, I have spent a lot of time over the years profiling new locos as well as re-profiling others from time to time as they loose accuracy due to aging. Thanks.

        Like

        Posted by Geoff | April 9, 2018, 17:12
  11. Hi Ruddy. I am folllowing your TC tutorials since you started. The tutorials are super, better than the original handbook !! I had built DDC decoders with Arduino, but I never tought to build a speed measurement device. Thanks a lot for sharing !

    Like

    Posted by E4lok | March 31, 2018, 17:55

Trackbacks/Pingbacks

  1. Pingback: A € 6,- model train speed measurement device. Part 2: the Arduino software. | rudysmodelrailway - March 29, 2018

  2. Pingback: A € 6,- model train speed measurement device. Part 1: the hardware. | rudysmodelrailway - March 29, 2018

Leave a comment

Archive of all posts