Anyone mind checking how I am going with this code?

This is my latest attempt to get a block for train signals working.

This is a tab for now but will eventually be a sub-flow.

There is a lot of extra stuff on the tab. Input simulation and debug stuff.

The idea is that this is a block of code that receives signals (inputs) and depending on how things are set, may send signals to the outputs.

One of the outputs is then sent to the next block's input and the process is repeated.
I'm also not 100% on the workings of the signals, but I think I am close.

FOREIGN NODE:
Sorry but it is sometimes handy to have

The top part of the tab is the simulated input part.
Whole lot of inject nodes.
Lower part is the code.
There are debug parts which I tried to keep away from the main code.

The input and outputs are link-in and link-out nodes with names explaining their functions.

There is also a group which is used between the output of a node on a side track when it goes into a node which represents points/junction on the track.
Normally the blocks would just connect together - with a slight delay - and work.
But if/when there is/are a set of points (junction) the output of that block would go through the group before going to the next block's input.
(Clear?)

There is an option to HOLD a train at a section.
Then Release it to continue.

Between each section I'd suggest a delay of a few seconds to better show you how the train moves along.
But that is if you get really interested.
The other Signal outputs go to LED nodes and I define the colours to be displayed by their names.
(Keeps it easy)
And there is an output that indicates the position/condition of the points - if there is/are any on that block.

I've used the three main (ONLY?) colours: RED YELLOW and GREEN.
There are other things which can be seen, but for now, I want to make sure I've got the mechanics of the idea working, and those other conditions are rare - at best.
I've named some of the inject nodes with the colour code you should see on the panel (lights) when/if working.

Code:
(Ok, we have a problem. It's too big.)
json format file

I have a working model but the existing subflow fails to allow the train to enter the block if the block is set to hold.
As is, the train is stopped one block before the hold - which is wrong.
So I sat down and put this together. But I now fear/suspect I am blind to any problems with the workings.

Yes, it is a lot to ask. Only if you have a bit of free time.

I've tried to maintain some kind of constant structure. Maybe overkill at this stage, but I want to get the muscle memory so when I do more in the future, the process is there.

Thanks again.

Or use node-red v3.x junction node...

image

sorry

502 Bad Gateway

cant download

Ok, thanks for trying.

I just checked and it works here.
(I can get to the page and I click the "download" link....)

Yes, and I shall - one day - get NR 3.x. But that is more decorative than a functional difference.

decorative?
Hundreds of hours wasted fixing bugs and adding new features. Wasted :sob::sob::sob:

3 Likes

C'mon.... It was a bit of a dig. It wasn't meant to be serious.

I do like it.
But I posted the flow with what I have and was looking for help on the workings of it.
I can't post a flow in version 3.x if I only have 2.x

A classic case of "Bigger fish to fry and I cannot be bothered by these whales".

I sort of get it, but also sort of don't.

I was totally being sarcastic about your comment on version 3.x. Yeah, if you don't need 3, Decorative? Its editor improvements when your knee deep in getting results you want from your work, the editor is not really your focus. Maybe "Bass" would be a better compare than the "whale"? Plus it probably fries up better!

Yeah, and now I have just found an open can of worms with the button node not seeming to send the topic when I press it. (Other thread)

WOW!

I have made great headway with this.

(Sorry, gotta show off now and then)

This is a working example of the flow.
(and yes my favorite foreign node is in there too...)

Working example

Load the flow, import the foreign node (or do that before you load it)
Click the start button and watch the train go from monitor right to monitor left.
It is about 5 seconds between sections.

You can hold the train before it gets to a section and it will stop in there.
Release it and it will continue.

(update)

Sorry, you can only hold it where the switch button is also there.
My bad. That is a problem with what is mentioned below.

Wow!

Now I need to get it to understand points as well.
That is going to be tricky, but hey.... It's fun.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.