SDK Question creating a function that runs every frame

thepenguin

Flying Penguin
Addon Developer
Joined
Jul 27, 2013
Messages
220
Reaction score
1
Points
16
Location
Earth-Moon Lagrange Point (L4)
What I am trying to do is to create a function that is executed by the simulator every frame. The function will be dynamically adjusting parameters of the spacecraft (such as adjusting engine power every frame). how do I do this?
 

Izack

Non sequitur
Addon Developer
Joined
Feb 4, 2010
Messages
6,665
Reaction score
13
Points
113
Location
The Wilderness, N.B.
These two are called once for every time step (ideally 60/second with VSync):
Code:
clbkPreStep()
clbkPostStep()
 

BruceJohnJennerLawso

Dread Lord of the Idiots
Addon Developer
Joined
Apr 14, 2012
Messages
2,585
Reaction score
0
Points
36
These two are called once for every time step (ideally 60/second with VSync):
Code:
clbkPreStep()
clbkPostStep()

You may also see something like clbkstep in older projects. I think its outdated, so I wouldnt reccomend using it. Izacks post above is the best option by far.

Just out of silly curiosity, what is the point of having a pre and post callback each frame? It seems to me that its just a case of glass half full/empty...
 

Enjo

Mostly harmless
Addon Developer
Tutorial Publisher
Donator
Joined
Nov 25, 2007
Messages
1,665
Reaction score
13
Points
38
Location
Germany
Website
www.enderspace.de
Preferred Pronouns
Can't you smell my T levels?
I don't know but PreStep was giving me more stable results in my PID autopilot.
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,632
Reaction score
2,350
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
I don't know but PreStep was giving me more stable results in my PID autopilot.

Thats because the data that you calculated desired to be applied in the same time step, while in Post-Step you would apply it in the following iteration.
 

martins

Orbiter Founder
Orbiter Founder
Joined
Mar 31, 2008
Messages
2,448
Reaction score
462
Points
83
Website
orbit.medphys.ucl.ac.uk
clbkPreStep is called after the step size has been computed, but before the simulation state has been propagated. clbkPostStep is called after the state propagation.
attachment.php
 

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
clbkPreStep:
This method is useful when the step length Dt is required in
* advance of the time integration, for example to apply a force that
* produces a given Dv, since the AddForce request will be applied in
* the next update. Using clbkPostStep for this purpose would be
* wrong, because its Dt parameter refers to the previous step length.
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,632
Reaction score
2,350
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
clbkPreStep is called after the step size has been computed, but before the simulation state has been propagated. clbkPostStep is called after the state propagation.
attachment.php

Thats a really great diagram, will it be in the new API docs? And can it be uploaded to Orbiter-Wiki?
 

Enjo

Mostly harmless
Addon Developer
Tutorial Publisher
Donator
Joined
Nov 25, 2007
Messages
1,665
Reaction score
13
Points
38
Location
Germany
Website
www.enderspace.de
Preferred Pronouns
Can't you smell my T levels?
Hehe, guys, I realize that :)
The real question is: why do we need the PostStep?
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,632
Reaction score
2,350
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Hehe, guys, I realize that :)
The real question is: why do we need the PostStep?

For finishing the iteration. For example, you might have state variables to reset again at the end of the time step. Or you might need to log parameters.

One design example from my Frankensteins Lab: You have a radio communication library, that works by letting vessels send messages and receive them via message buffers. In the time step, all spacecraft should receive all messages for them by other spacecraft via message queues.

As you can see, this isn't done with pre-step alone, you design the library that the messages in the communication object are sent in prestep and received and handled in Post-Step. Now all spacecraft can send their messages in one phase and receive them in the other, but still all happens in the same timestep and not for example, that the first spacecraft in Orbiters vessel list receives the messages of the last spacecraft in the next timestep, while the last spacecraft receives the messages from the first spacecraft already in the same timestep. Sounds harmless when you only have two spacecraft, but once you have three or more, the situation becomes much more annoying, without using post-step.
 

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
Thats a really great diagram, will it be in the new API docs?
It's already there (in the API_Reference.chm) since December last year:
From SVN r.15, you'll find under "Related pages | Orbiter program flow and module callback order" a flowchart for the orbiter frame update loop and vessel callback functions.
 
Top