Elvas Tower: Turntable Problems - Elvas Tower

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Turntable Problems Turntable won't turn clockwise in timetable mode Rate Topic: -----

#1 User is offline   roeter 

  • Vice President
  • Group: Status: Elite Member
  • Posts: 2,420
  • Joined: 25-October 11
  • Gender:Male
  • Country:

Posted 25 February 2021 - 04:07 PM

A few days ago, Mauricio (mbm_OR) approached me about a problem with turntables in timetable mode. In timetable mode, turntables won't turn clockwise, they do turn correct anti-clockwise.
I tested this, and found the problem was caused by this sequence in shapes.cs, method prepareframe (for turntable class) :

        public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
        {
            if (Turntable.GoToTarget || Turntable.GoToAutoTarget)
            {
                AnimationKey = (Turntable.TargetY / (float)Math.PI * 1800.0f + 3600) % 3600.0f;
            }

            else if (Turntable.Counterclockwise)
            {
                AnimationKey += SharedShape.Animations[0].FrameRate * elapsedTime.ClockSeconds;
            }
            else if (Turntable.Clockwise)
            {
                AnimationKey -= SharedShape.Animations[0].FrameRate * elapsedTime.ClockSeconds;
            }
            while (AnimationKey > SharedShape.Animations[0].FrameCount) AnimationKey -= SharedShape.Animations[0].FrameCount;
            while (AnimationKey < 0) AnimationKey += SharedShape.Animations[0].FrameCount;

            Turntable.YAngle = MathHelper.WrapAngle(AnimationKey / 1800.0f * (float)Math.PI);


So what happens here?
TargetY is the required angle. From this value, the AnimationKey is calculated. This calculation is such that the value of AnimationKey is the angle value in multiples of 0.1 degree, so, for instance, an angle of 2 degrees would give an AnimationKey value of 20.
Next, it is checked if this value is within the maximum frame count - and this is where things go wrong. For the maximum frame count as defined for the standard turntables is 3599 - not, as one might expect, 3600. So angle values between 359.9 and 360 degrees, which are perfectly valid, are now rejected as invalid because the calculated AnimationKey value would exceed 3599.

When turning clockwise, the angle goes down. So if the turntable starts at 0 degree, the first step would be down from 360 degrees. If this first step is < 0.1 degrees, it will result in an AnimationKey value between 3599 and 3600. But this value exceeds the framecount of 3599, and will therefor be 'corrected'.

Example: first step size is 0.05 degrees. So, TargetY will be 359.95 degrees, resulting AnimationKey value is 3599.5. This exceeds 3599, so is corrected to 3599.5 - 3599 = 0.5, resulting in an angle of +0.05 degrees - so the angle is set the wrong way! This way the turntable will indeed never start moving.

The basic error is, of course, that frame count is set to 3599 and not to 3600. But changing that would required changing all turntables in all routes and that seems to be bit beyond practical reality.

A possible correction would be not to test againt 3599, but against 3600, so framecount + 1.
As the problem only seems to occur in timetable mode (GoToAutoTarget mode), the test should only be adjusted in this mode.

Mauricio kindly provided a proper 'diff' file for this change and a test version based on the unstable version which includes this changed code:
Attached File  TT-AutoClockwise-20210224.diff.txt (1013bytes)
Number of downloads: 239
Attached File  U-TT-AutoClockwise-RunActivity.zip (1.2MB)
Number of downloads: 245

This has been tested and works correct.
Another option, perhaps, would be to explicitly test on AnimationKey values between 3599 and 3600, and clamp this to 3598.99, so avoiding the 'correction'.
I would very much like to hear the opinion of other developers on this issue and the proposed changes.

One thing bothered me, though. How could I have missed such a very clear error when I introduced this feature back in 2019?
The answer is quite surprising. At that time I was still using my 'old' laptop, which was getting a bit sluggish. So, frame rate was not that high, and the interval times were such that the delta angles based on the required turning speed and interval time were never less than 0.1 degree, so the TargetY value never was set to an angle between 359.9 and 360.
But last year I got myself a new laptop which is a bit faster, so now the interval rate is such that the required angle steps are less than 0.1 degree. But upto now, I had not yet run the Rio Grande Southern route (which is the route which served as testbed for this feature) on my new laptop.

Regards,
Rob Roeterdink

#2 User is offline   Csantucci 

  • Member, Board of Directors
  • Group: Status: Elite Member
  • Posts: 6,986
  • Joined: 31-December 11
  • Gender:Male
  • Country:

Posted 27 February 2021 - 02:29 AM

If this solves the problem on timetables, it's OK for me. I only wonder why in the patch AnimationKey is reduced by FrameCount and not FrameCount + 1, in the case the test with FrameCount + 1 is done.

A hypothesis could be to change the compare also for Activity and Explore mode, but due to the fact that up to now noone complained about malfunctions, I'd prefer to limit the change to timetable mode.

#3 User is offline   YoRyan 

  • Conductor
  • Group: Status: Active Member
  • Posts: 391
  • Joined: 19-February 20
  • Gender:Male
  • Location:California, United States
  • Simulator:Open Rails/unstable
  • Country:

Posted 15 March 2021 - 11:44 PM

After some additions, this fix has been merged into the testing release.

As it turns out, relaxing the 3600 frames assumption greatly simplifies the solution.

#4 User is offline   rickloader 

  • Conductor
  • Group: Status: First Class
  • Posts: 479
  • Joined: 05-February 13
  • Gender:Male
  • Location:Southampton uk
  • Simulator:Open Rails
  • Country:

Posted 15 March 2021 - 11:58 PM

Is it possible yet, to "turn " a loco please? Last time I looked it was only possible to turn to access a stabling track in a pool. By "turn" I mean rotate a loco through 180 and exit on the same approach track.
Thanks for continuing work in timetable mode. Rick

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users