# [Solved] Train-dependent level crossing

## [Solved] Train-dependent level crossing

Hi folks,

I have played with the formulas from Graham and after a few modifications, I can finally say it is working as i wanted. Watch the below video and comment, please. Note: the animations are running smoothly in real life, the recording software is quite demanding and therefore it appears choppy in some part of the vid.

This video shows conditional use of animations on the level crossing - based upon train approach. Timing of the animations is subject to adjustments, this is only a demonstrative video.:-)

I have played with the formulas from Graham and after a few modifications, I can finally say it is working as i wanted. Watch the below video and comment, please. Note: the animations are running smoothly in real life, the recording software is quite demanding and therefore it appears choppy in some part of the vid.

This video shows conditional use of animations on the level crossing - based upon train approach. Timing of the animations is subject to adjustments, this is only a demonstrative video.:-)

Last edited by Derryck on Sun Oct 09, 2011 8:18 pm; edited 1 time in total

## Re: [Solved] Train-dependent level crossing

I get an error message: this video contains music from UMG ...

**velaro**- Posts : 23

Join date : 2011-08-02

Age : 41

Location : Reutlingen, Germany

## Re: [Solved] Train-dependent level crossing

Looks good! So now there is the flexibility of being able to set two distance values, one to drop the barriers well before the train arrives , and a shorter one after the train has passed, which lifts the barriers again for the road traffic. Well done Derryck.

## Re: [Solved] Train-dependent level crossing

velaro wrote:I get an error message: this video contains music from UMG ...

Ah yes, German resident, right? I just got a lovely email from youtube that my video won't be available in Germany due to music copyright. I will upload the vid here, no worries.

## Re: [Solved] Train-dependent level crossing

What's up with German residents that YouTube won't allow? :S

## Re: [Solved] Train-dependent level crossing

It's not an YouTube issue, it has to do with Universal Music Group. Iam uploading the video on my website - I shall put a link here shortly.

## Re: [Solved] Train-dependent level crossing

Actually, truth be told I rather have a silent video than one with music I don't appreciate.

## Re: [Solved] Train-dependent level crossing

Joey, is there something you don't like about that music? By the way, it is a matter of a second to click the speaker button. Back to the topic please, any suggestions?

## Re: [Solved] Train-dependent level crossing

OK, I promised to make the formula public, so here it is + I will also try to explain.

ANY QUESTION, GRAY?

**First goes the gate:**

states = [whatever_your_object_name_is]

RotateXFunction = if[trackDistance <=400 & trackdistance[-1]>(-25), 0, (abs[trackdistance] > 50) * (-1.5)]

RotateXDamping = 1, 1.1

__Explanation:__**IF**-> a conditional, expresses that something will happen in case the set criteria (conditions) are met, the formula inside has to be surrounded by brackets [] and consists of condition, what to do if condition is met and what to do if not

**trackDistance <= 400**-> sets the first condition, in this case the nominal distance of the train from the object is less or equal to 400 metres

**&**-> logical operator, which stands for "AND". In this case it means more criteria need to be fulfilled within the same time period before the action will be taken

**trackdistance[-1]>(-25)**-> the second condition, which needs to be fulfilled together with the first one in order for the action to take place. In our case the distance (in meters) of the geometrical centre of coupler indexed with "-1" (which is a default value of the very last wagon regardless on their total amount) has to be higher than -25, which means the condition is broken after the last wagon passes the crossing (because -25 is in fact 25 meters BEHIND the crossing) and the gate goes up.

**0**-> Means when the conditions ARE fulfilled, the rotation will be ZERO radians (this in fact requires the gate to be defined in thefile as closed, otherwise the displayed result will be incorrect)**"states.csv"**

**(abs[trackdistance] > 50) * (-1.5)**-> defines that the rotation will be performed when at least one of the criteria is NOT fulfilled. The formula will open the gate to an approximate angle of 87 angular degrees.

**RotateXDamping = 1, 1.1**-> Tells us the rotation will be performed gradually, not as a jump from an unrotated state to the other one

**And the blinking lights, this is something I particularly like:**

states = CrossingLightL.csv, CrossingLightR.csv, Null.csv

StateFunction = if[trackDistance<=600 & trackdistance[-1]>(-25), mod[value + 1, 2], 2]

RefreshRate = 0.5

__Explanation:__**states = CrossingLightL.csv, CrossingLightR.csv, Null.csv**-> Defines the list of states of the light. In the first one, the left is turned on, in the second, the right one is turned on and the third object is just an invisible fake.

**IF**-> a conditional, expresses that something will happen in case the set criteria (conditions) are met, the formula inside has to be surrounded by brackets [] and consists of condition, what to do if condition is met and what to do if not

**trackDistance <= 600**-> sets the first condition, in this case the nominal distance of the train from the object is less or equal to 600 metres

**&**-> logical operator, which stands for "AND". In this case it means more criteria need to be fulfilled within the same time period before the action will be taken

**trackdistance[-1]>(-25)**-> the second condition, which needs to be fulfilled together with the first one in order for the action to take place. In our case the distance (in meters) of the geometrical centre of coupler indexed with "-1" (which is a default value of the very last wagon regardless on their total amount) has to be higher than -25, which means the condition is broken after the last wagon passes the crossing (because -25 is in fact 25 meters BEHIND the crossing) and the lights should stop blinking.

**mod[value + 1, 2]**-> determines the state to be used by dividing VALUE+1 (the starting content of this variable is 0) by TWO. With each cycle (will be explained when I get to REFRESH) 1 is added to the VALUE and therefore, the remainder (basically this is what MOD function is all about) of VALUE being divided by two is either 0, or 1. Here comes the state change, either state 0, or 1 is used and flashes over the static crossing object

**2**-> when the conditions are NOT fulfilled, the state 2 is used. Therefore, we only see the switched off lights defined within the static crossing object.

**RefreshRate = 0.5**-> Represents the time interval for the state change in seconds. In other words this means that the cycle repeats every second.

ANY QUESTION, GRAY?

Last edited by Derryck on Mon Oct 17, 2011 10:14 pm; edited 3 times in total

## Re: [Solved] Train-dependent level crossing

Thanks for that Derryck. I shall enjoy experimenting with the distances. It looks as if it could also be adapted to operate a .freeobj semaphore distant signal to work with a crossing. Should be very useful.

## Re: [Solved] Train-dependent level crossing

graymac wrote:Thanks for that Derryck. I shall enjoy experimenting with the distances. It looks as if it could also be adapted to operate a .freeobj semaphore distant signal to work with a crossing. Should be very useful.

Yes, it is constructed to be universal. For the semaphore, I would rather use the second part. I like the way I am avoiding the state indexed as "2" when I need the lights to be switched off.

## Re: [Solved] Train-dependent level crossing

In the expression:

So far I have tried the expression with a 600metre distance and it looks very good. The -25 should be suitable for nearly every situation, I would think.

you chose a value of 50. Am I right in thinking that this is an "else" condition? And is the number important? I haven't tried changing it to see what happens.RotateXFunction = if[trackDistance <=400 & trackdistance[-1]>(-25), 0, (abs[trackdistance] > 50) * (-1.5)]

So far I have tried the expression with a 600metre distance and it looks very good. The -25 should be suitable for nearly every situation, I would think.

## Re: [Solved] Train-dependent level crossing

Yes, the regular ELSE condition, you are right.

Basically, the more important of the numbers is the one in brackets (-1.5 in this case) Currently, I am performing test whether and under what conditions the calculation can be replaced by a simple value of (-) 1.53, which is approximately equal to 87 angular degrees. It should also work by simply setting this amount of radians. You might want to try it out and let me know afterwards.

Basically, the more important of the numbers is the one in brackets (-1.5 in this case) Currently, I am performing test whether and under what conditions the calculation can be replaced by a simple value of (-) 1.53, which is approximately equal to 87 angular degrees. It should also work by simply setting this amount of radians. You might want to try it out and let me know afterwards.

## Re: [Solved] Train-dependent level crossing

Yes, you can change the 1.5 radians value which you have in your example to any other value to suit the situation.

It does not make any difference to the first part of the expression as the first part is a conditional formula which simply returns a value of 'true' or 'false'. As this is a 'Rotate' funtion then the amount of rotation is the figure, given in radians rather than degrees. For more information about the relationship between radians and degrees, and to understand how to make the calculations necessary, see here:

http://en.wikipedia.org/wiki/Radians

It does not make any difference to the first part of the expression as the first part is a conditional formula which simply returns a value of 'true' or 'false'. As this is a 'Rotate' funtion then the amount of rotation is the figure, given in radians rather than degrees. For more information about the relationship between radians and degrees, and to understand how to make the calculations necessary, see here:

http://en.wikipedia.org/wiki/Radians

Page

**1**of**1****Permissions in this forum:**

**cannot**reply to topics in this forum