Jump to content

fps über Schnittstelle


EASY
 Share

Recommended Posts

Hallo Neo,

damit ich in VB nicht ganz einroste versuche ich mich gerade in einem (sanften) Kamerarschwenk auf ein Objekt zu. Wie bekannt ist die Schnittstelle an die fps geknüpft, so daß mein Schwenk (wie alle Bewegungen über die Schnittstelle) mal schneller und mal langsamer ist....
... und so dachte ich, daß es vielleicht am einfachsten wäre, wenn man die fps über die Schnittstelle (als Korrekturfaktor) auslesen könnte.

Gruß
EASY

Link to comment
Share on other sites

That's why I use a loco on a circular track as a timer in my controller Easy.

I use that instead since,

a) FPS depends on what you have in view. and whatever else is happening. It varies frame by frame.
b) With faster simulation rates you usually want to do your thing at the appropriate speed.

According to NEO I could use an MBS timer object instead... but I am not convinced that works quite as advertised and isn't controllable via the plug-in interface.

Obviously the timer track is a LOT slower than FPS... but with mine running at about 5 track entries per second it seems workable, though I could go faster.

(I figure NEO has already done the FPS - Distance travelled math so using the motion of a defined object makes sense.)

 

As an alternative you could watch the system time so see how long it has been since the last cycle..

something like

Have some globals...

Public WasTime as Date = Now()

Public Const Sperday As Double = 24 * 60 * 60
Public Const mSperday As Double = Sperday * 1000

Public Function Delta_MilliSeconds(T1 As Date, T2 As Date) As Double

     Dim DeltaT As Double = Math.Abs(T2.ToOADate - T1.ToOADate)

     Return mSperday * DeltaT

End Function

 

then in your routine use


Dim ThisTime as Date =  Now()
Dim ElapsedTime as double = Delta_Milliseconds(ThisTime, WasTime)
WasTime = ThisTime

Then use the Elapsed_Time figure as a scaling factor.

I hope that all helps..

Regards
T

Screenshot_138.jpg

Edited by trevor
Link to comment
Share on other sites

Hi trevor,

... this is what i figured out to get fps:

 Public Function Get_fps() As Double
        Dim sw As New Stopwatch
        C_Write.WriteLine("1")  'Write a command...
        C_Write.Flush()             '... send command...
        C_Read.ReadLine()      '... await respons -> end of frame -> (synchnonize -> command could be send anytime within frame)
        sw.Start()                       'Start stopwatch -> begin of next frame (!)...
        C_Write.WriteLine("1")  '... write a command...
        C_Write.Flush()             '... send command
        C_Read.ReadLine()      '... await respons -> end of frame (!)
        sw.Stop()                       '... get delta time
        Return Stopwatch.Frequency / sw.ElapsedTicks '... return fps
    End Function

... most time it works (but some times the result is (much) faster... but i don't understand why...

EASY

Link to comment
Share on other sites

17 hours ago, EASY said:

Hi trevor,

... this is what i figured out to get fps:

 Public Function Get_fps() As Double
        Dim sw As New Stopwatch
        C_Write.WriteLine("1")  'Write a command...
        C_Write.Flush()             '... send command...
        C_Read.ReadLine()      '... await respons -> end of frame -> (synchnonize -> command could be send anytime within frame)
        sw.Start()                       'Start stopwatch -> begin of next frame (!)...
        C_Write.WriteLine("1")  '... write a command...
        C_Write.Flush()             '... send command
        C_Read.ReadLine()      '... await respons -> end of frame (!)
        sw.Stop()                       '... get delta time
        Return Stopwatch.Frequency / sw.ElapsedTicks '... return fps
    End Function

... most time it works (but some times the result is (much) faster... but i don't understand why...

EASY

Yup that will work... however, the frame rate varies from frame to frame because of one, or all, of the following..

1. there are more events to handle in the frame gap, 
2. because the current view is more or less detailed, 
3. because more things may be moving at a particular moment of time, or
4. Because windows decided to steal some time..

 As such, if you are using the plug-in to simulate movement, you really need to either measure the time every frame, or use some other MBS generated, and presumably simulation synchronized, signal.

Edited by trevor
Link to comment
Share on other sites

Hi

Zitat
vor 9 Minuten schrieb trevor:

4. Because windows decided to steal some time..

:D:D:D... the big unknown...

Zitat
vor 15 Minuten schrieb trevor:

or use some other MBS generated, and presumably simulation synchronized, signal.

.... best would be if MBS "fire" a trigger signal... but as first step i would be happy if i could "ask" MBS with a command or a event for fps...

EASY

Link to comment
Share on other sites

1 minute ago, EASY said:

Hi

:D:D:D... the big unknown...

.... best would be if MBS "fire" a trigger signal... but as first step i would be happy if i could "ask" MBS with a command or a event for fps...

EASY

 

Yes, the interface is missing some handshake type commands and events for sure.

Remember though, Frame Rate is NOT REALLY a good clock to use. The MBS software attempts to refresh the display as fast as it can so it not only varies by frame but also by computer.

Today I switched my controller over from using a cycling locomotive to use an MBS timer which IS synchronized to the layout motion...(or seems to be close enough).

It works ok, but initially getting the timer started requires some event code which is a not exactly a "pure" solution.

I set the timer to 0.2S and use that event to time things. That's 5 interrupts per second which is a bit low really... but.. at four times simulation rate that goes up to 20/s which is starting to get too close to the slower frame rates, so I am reluctant to go any faster than that.

Link to comment
Share on other sites

Hi trevor,

Zitat
vor 3 Stunden schrieb trevor:

Remember though, Frame Rate is NOT REALLY a good clock to use

... i know not in any case...and there are other influences so the interface is not always synchronous to fps.
... i.e. if you move the mouse over the project window fps will slow down (a little bit) but the interface will be faster....
... or if you open a menue (i.e. "Extras") the fps will be significantly slower but the interface is significantly faster... (by the way... this was the beginning of command groups...) 

EASY

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...