Model Railroad Turntable Project Need Help!!

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
Werner
Posts: 95
Joined: Sat Jun 11, 2011 4:12 am
Has thanked: 87 times
Been thanked: 31 times

Model Railroad Turntable Project Need Help!!

Post 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! :D

[img]
CodeGood.jpg
CodeGood.jpg (92.78 KiB) Viewed 10152 times
[/img]
Attachments
NewWork12.fcf
(29.95 KiB) Downloaded 335 times
Werner
STUDENT OF: Martin - Professor of Flowcode, John, Jan, Fotios and Nicolas "Spanish Dude"

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Model Railroad Turntable Project Need Help!!

Post 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

Werner
Posts: 95
Joined: Sat Jun 11, 2011 4:12 am
Has thanked: 87 times
Been thanked: 31 times

Re: Model Railroad Turntable Project Need Help!!

Post 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!
Werner
STUDENT OF: Martin - Professor of Flowcode, John, Jan, Fotios and Nicolas "Spanish Dude"

Werner
Posts: 95
Joined: Sat Jun 11, 2011 4:12 am
Has thanked: 87 times
Been thanked: 31 times

Re: Model Railroad Turntable Project Need Help!!

Post 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!
Werner
STUDENT OF: Martin - Professor of Flowcode, John, Jan, Fotios and Nicolas "Spanish Dude"

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: Model Railroad Turntable Project Need Help!!

Post 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 :lol:
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
Martin

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: Model Railroad Turntable Project Need Help!!

Post 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
Attachments
NewWork12_modifed.fcf
(29.15 KiB) Downloaded 314 times
Martin

Werner
Posts: 95
Joined: Sat Jun 11, 2011 4:12 am
Has thanked: 87 times
Been thanked: 31 times

Re: Model Railroad Turntable Project Need Help!!

Post 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!! :D
Werner
STUDENT OF: Martin - Professor of Flowcode, John, Jan, Fotios and Nicolas "Spanish Dude"

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: Model Railroad Turntable Project Need Help!!

Post 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
Martin

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: Model Railroad Turntable Project Need Help!!

Post 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
Attachments
NewWork12_modifed4.fcf
(33.95 KiB) Downloaded 285 times
Martin

Werner
Posts: 95
Joined: Sat Jun 11, 2011 4:12 am
Has thanked: 87 times
Been thanked: 31 times

Re: Model Railroad Turntable Project Need Help!!

Post 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
Werner
STUDENT OF: Martin - Professor of Flowcode, John, Jan, Fotios and Nicolas "Spanish Dude"

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: Model Railroad Turntable Project Need Help!!

Post by medelec35 »

Your welcome Werner.

Hope it works the way you want it too.


Martin
Martin

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times

Re: Model Railroad Turntable Project Need Help!!

Post by brandonb »

Werner
EB-006, E-Blocks, Student of “Martin”
student of martin? awsome! where do i sign up!!!

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: Model Railroad Turntable Project Need Help!!

Post by medelec35 »

brandonb wrote:student of martin? awsome! where do i sign up!!!
Oh me too please! :lol:
Martin

Werner
Posts: 95
Joined: Sat Jun 11, 2011 4:12 am
Has thanked: 87 times
Been thanked: 31 times

Re: Model Railroad Turntable Project Need Help!!

Post 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!! :D

Have a great day!

Werner
Werner
STUDENT OF: Martin - Professor of Flowcode, John, Jan, Fotios and Nicolas "Spanish Dude"

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times

Re: Model Railroad Turntable Project Need Help!!

Post 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 :lol:

Post Reply