Page 1 of 1
Model Railroad Turntable Project Need Help!!
Posted: Mon Nov 07, 2011 12:27 am
by Werner
Hi Guys, I have been working on a fun project until I hit an area I just cant seem to figure out?

The area I am working on is in tab CodeGood were I have four if decisions in a row. What I am trying to do is: Imagine a Train Engine that pulls onto a turntable with the head of the engine we will say is at the index 00. The operator wants to move the engine to any of 1 through 40 positions around the turntable. But he wants to take the shortest way clockwise or counter clockwise to get to his new destination. I have been able to almost get it using four if decisions but always can find one situation that doesn’t work. You could see what my program is doing with the file below. Its best to simulate at 1000 in the panel options simulation speed and put a toggle brakepoint at the change = Digittotal - Index calculation so you can mouse click through this area. Run the program than toggle the initialize switch this is going to index the tuntable at 00. From there you can enter a position 0-39 and push the enter button. The variables I watch are Digittotal the number entered into the keypad to move to, Index the number of the current position, and Change the difference between Digittotal – Index. If anyone could give me a clue as to how I should be doing this I would be very grateful!!
Have a great day!
[img]

- CodeGood.jpg (92.78 KiB) Viewed 10175 times
[/img]
Re: Model Railroad Turntable Project Need Help!!
Posted: Mon Nov 07, 2011 11:26 am
by Benj
Hello Werner.
One way to find the quickest distance to travel would be to take the current position and then create a loop to count up from the current position to the desired position. Inside the loop increment a counter and this will end up being the total steps should you increment the position. Repeat the loop but this time decrement the position and increment a second counter. AT the end of the two loops compare the two counters and move in the direction that has the lowest counts. You will probably need a special case for when the counters are equal.
eg.
Decision: Count1 >= Count2
Move Clockwise Count 2 positions
Else
Move Anticlockwise Count 1 positions
Re: Model Railroad Turntable Project Need Help!!
Posted: Mon Nov 07, 2011 6:36 pm
by Werner
Hi Ben,
Thanks a lot for the for the suggestion. I knew you would have something clever for me to try! I will play with it and see if I can’t get it figured out!
Have a great day Buddy!
Re: Model Railroad Turntable Project Need Help!!
Posted: Tue Nov 08, 2011 1:31 am
by Werner
Hi Ben, I played around with my program for a few hours today but am not getting it? I always end up with one of the loops going off in a direction that won't end the loop. I have the decision part down ok, It just the loops that are giving me trouble. If I have the loop counting up until current position = desired position (Count1) the second loop just goes on forever (Count2)? Thanks for the help!
Re: Model Railroad Turntable Project Need Help!!
Posted: Tue Nov 08, 2011 6:48 am
by medelec35
Here is my thoughts.
You could have a calculation:
Required_Steps = 40-(Required_Position - Current_Position)
Then have a decision branch:
If: Required_Steps>40
Then: Required_Steps = Required_Steps - 40
Finally have the final decision branch
If: Required_Steps >20 Then: Required_Steps = 40 - Required_Steps: move counter clockwise // moves Required_Steps counter clockwise
Else move Required_Steps clockwise// So count = Required_Steps
Hope this makes sense as not long woke up and I'm half a sleep
So I can't guarantee it will work of course.
If I have not made much sense & I get a chance, then I will integrate this routine within your Flowchart to see if it works.
Martin
Re: Model Railroad Turntable Project Need Help!!
Posted: Tue Nov 08, 2011 8:45 am
by medelec35
I have integrated calculations into your flowchart.
Can you let me know if works OK or not.
Thanks
One comment I would make. You have got If change < 0
and
If Change < -20
Since Change is a byte and not a signed integer, it can never be less than 0 or greater than 255.
Martin
Re: Model Railroad Turntable Project Need Help!!
Posted: Tue Nov 08, 2011 2:48 pm
by Werner
Hi Martin,
I was so close to your solution so many times it makes me crazy!! What you came up with is a thing of beauty in its simplest form. I want to print my flow chart out and show it to everybody and let them know my friend Martin came up with this, isn’t it genius! I can’t thank you enough!! I thank you too Ben!!

Re: Model Railroad Turntable Project Need Help!!
Posted: Tue Nov 08, 2011 3:12 pm
by medelec35
Thanks Werner
You have made my day.
Yes you was very close to solving it!
Glad you happy with Flowchart.
Thank you for letting us know.
Kind Regards
Martin
Re: Model Railroad Turntable Project Need Help!!
Posted: Sat Nov 19, 2011 3:05 pm
by medelec35
Hi Werner,
I have altered your Turntable project so if you press the Enter before you key in any digits, you will be in jog mode.
If you do not press # then your in forward mode.
If you press # then you are in reverse mode.
now key in the the number of steps. Then turntable will move that number of steps but the AT: position will remain the same.
E.g if AT is showing 20, but 20 on your turntable is two steps in reverse, then just press Enter, then press #, 02 then Enter.
After steps ave been completed, the AT will still show 20 even though turntable has moved.
Once you have completed the jog function, then turntable should not be out again, since AT is stored in EEPROM, then retrieved when power is 1st applied.
Martin
Re: Model Railroad Turntable Project Need Help!!
Posted: Sat Nov 19, 2011 6:50 pm
by Werner
Hey thanks so much Martin! I am going to study this and see if I can figure out how you did that!
Thanks again!
Werner
Re: Model Railroad Turntable Project Need Help!!
Posted: Sat Nov 19, 2011 8:00 pm
by medelec35
Your welcome Werner.
Hope it works the way you want it too.
Martin
Re: Model Railroad Turntable Project Need Help!!
Posted: Mon Nov 21, 2011 6:37 am
by brandonb
Werner
EB-006, E-Blocks, Student of “Martin”
student of martin? awsome! where do i sign up!!!
Re: Model Railroad Turntable Project Need Help!!
Posted: Mon Nov 21, 2011 7:18 pm
by medelec35
brandonb wrote:student of martin? awsome! where do i sign up!!!
Oh me too please!

Re: Model Railroad Turntable Project Need Help!!
Posted: Mon Nov 21, 2011 7:23 pm
by Werner
From all the posts I’ve been reading Brandon it looks like you are too! We are all very fortunate and I for one very greatful!!
Have a great day!
Werner
Re: Model Railroad Turntable Project Need Help!!
Posted: Tue Nov 22, 2011 4:05 am
by brandonb
From all the posts I’ve been reading Brandon it looks like you are too! We are all very fortunate and I for one very greatful!!
your right, if it wasnt for martin and fotios i would still be scratching my head back at square one, im am definitly greatful, hey maybe matrix should give them both a free copy of v5 for their contributions
