Request Save State Vector to a txt file

LauncherLover

New member
Joined
Mar 19, 2024
Messages
18
Reaction score
1
Points
1
Location
Madrid
Hello there friends!

I need to save the state vector of my focus vessel from the scenario editor in a txt for a project I'm working on, could anyone tell me how should I update the source code of the scenario editor addon for this goal? I would also accept an already modified version of the addon dll hehe. I guess its truly basic, but my knowledge of c++ combined with my lack of understanding of compiling projects in Visual Studio have proven to be a big obstacle in my way.

PS: Would it be necessary to run orbiter for this task? Could it be possible the existence of an addon that, given the latitude, longitude and altitude of a point in orbiter and a date, it would return the X, Y and Z coordinates in cartesian and orbiters ecliptic frame? That would be AWESOME for me

Thanks in advance
 

N_Molson

Addon Developer
Addon Developer
Donator
Joined
Mar 5, 2010
Messages
9,287
Reaction score
3,255
Points
203
Location
Toulouse
PS: Would it be necessary to run orbiter for this task?

Yes. What might not be necessary is the graphic client.
 

Face

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 18, 2008
Messages
4,403
Reaction score
581
Points
153
Location
Vienna
Hello there friends!

I need to save the state vector of my focus vessel from the scenario editor in a txt for a project I'm working on, could anyone tell me how should I update the source code of the scenario editor addon for this goal? I would also accept an already modified version of the addon dll hehe. I guess its truly basic, but my knowledge of c++ combined with my lack of understanding of compiling projects in Visual Studio have proven to be a big obstacle in my way.

PS: Would it be necessary to run orbiter for this task? Could it be possible the existence of an addon that, given the latitude, longitude and altitude of a point in orbiter and a date, it would return the X, Y and Z coordinates in cartesian and orbiters ecliptic frame?
In principle you can do all the calculations on your own, especially in non-accelerated scenarios, no need for Orbiter. However, it is not trivial, so if you already have a program doing this math for you (Orbiter), why not use it?
You can run orbiter_ng.exe without a graphics client, it will then open up a simple terminal window with text input to control the session. Unfortunately, there is no easy way to fire up dialogs like the ScnEditor.
For the state vector serialization, I think the most important question is what exact format you have in mind. Maybe tell us for what project that is, or at least what you want to do with the exported data.
 

LauncherLover

New member
Joined
Mar 19, 2024
Messages
18
Reaction score
1
Points
1
Location
Madrid
In principle you can do all the calculations on your own, especially in non-accelerated scenarios, no need for Orbiter. However, it is not trivial, so if you already have a program doing this math for you (Orbiter), why not use it?
You can run orbiter_ng.exe without a graphics client, it will then open up a simple terminal window with text input to control the session. Unfortunately, there is no easy way to fire up dialogs like the ScnEditor.
For the state vector serialization, I think the most important question is what exact format you have in mind. Maybe tell us for what project that is, or at least what you want to do with the exported data.
Thank you for your response!

What I'm trying to do is visualize data from simulations outputted by Simulink in Orbiter. Once the simulation is run in Simulink, I save a .mat file. Then, with a MATLAB code I've created, I generate the necessary files for Orbiter to believe it's a recording and be able to replay it (files .att, .pos, and .atc). So far so good. The issue arises because there must be discrepancies between the Earth models in Orbiter and my simulator (especially how they rotate), and my launcher appears with an offset from where I want it to launch.

To solve this, what I've done is: since the launcher is placed at the exact starting point thanks to the longitude and latitude entered in the .scn, at that initial moment when the position is correct, I open the ScnEditor, copy the state vector, calculate the error between the first position outputted by my simulator and this "correct" position for Orbiter, and perform a translation. This corrects the entire trajectory of the launcher. However, it's tedious to have to copy this state vector and apply the correction every time I want to launch a simulation. So what I did was to record this error for the 1st of each month from 2022 to 2050 (it took me several hours) to perform interpolation given a specific date. The issue is that THERE ARE ALSO DISCREPANCIES WITH DAILY ROTATION, and I find it completely unfeasible to generate so much data manually to be able to interpolate afterward.

Therefore, if I could obtain this initial vector at the launch platform, I would save A LOT of problems, as I suspect that the error I can expect will also vary with latitude, so the number of data points I would have to generate manually (literally copying and pasting numbers from the scneditor window to an Excel sheet) is unfeasible.
 

Face

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 18, 2008
Messages
4,403
Reaction score
581
Points
153
Location
Vienna
So you need the translation from long/lat landed position to xyz coordinates on a given GBody at a given time?

Well, it is what you wrote initially, it is only now that I really understand what you mean.

After studying the sources a bit, I think it boils down to getting the rotation matrix of the GBody at the given time, as well as the terrain elevation at the landed position. The former should be doable, but the later is a bit tricky without Orbiter. I guess the best would really be to rig up a module that - if started in headless mode - just serializes the oapiGetRelativePos coordinates on sim start, then closes the simulation again. That way you could maybe even build an automation tool-chain.
 
Last edited:

LauncherLover

New member
Joined
Mar 19, 2024
Messages
18
Reaction score
1
Points
1
Location
Madrid
So you need the translation from long/lat landed position to xyz coordinates on a given GBody at a given time?

Well, it is what you wrote initially, it is only now that I really understand what you mean.
Yup, that's what I need, do you find it feasible? It must be few lines with the oapiGetGlobalPos, but can't manage to compile anything :(
 

Face

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 18, 2008
Messages
4,403
Reaction score
581
Points
153
Location
Vienna
Yup, that's what I need, do you find it feasible? It must be few lines with the oapiGetGlobalPos, but can't manage to compile anything :(
I think oapiGetGlobalPos has the origin in the barycenter. I'm not sure if you get that via ScnEditor, because its display uses oapiGetRelativePos from the selected GBody. What did you select in your manual procedure?
 

LauncherLover

New member
Joined
Mar 19, 2024
Messages
18
Reaction score
1
Points
1
Location
Madrid
I think oapiGetGlobalPos has the origin in the barycenter. I'm not sure if you get that via ScnEditor, because its display uses oapiGetRelativePos from the selected GBody. What did you select in your manual procedure?
X, Y and Z from the state vect with Orbit Reference: Earth, Frame: Ecliptic and Coordinates: Cartesian
 

LauncherLover

New member
Joined
Mar 19, 2024
Messages
18
Reaction score
1
Points
1
Location
Madrid
Okay I've done it, I have an addon that registers the statevector into a .txt. Indeed it was with the oapiGetRelPos.
Now the next step would be to kinda automatize this, the problem is that this data is registered only if the scenario is started. So with this, the steps that one has to follow are
Run Code -> Open Orbiter -> Activate Addon -> Launch Scenario (this generates the .txt) -> From here I can do the correction. What I would like is to run this two steps [Open Orbiter -> Launch Scenario (this generates the .txt)] from a command window or, preferable, an .exe so I can run it directly from my code. Can anyone think a way around this?
 

Face

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 18, 2008
Messages
4,403
Reaction score
581
Points
153
Location
Vienna
What I would like is to run this two steps [Open Orbiter -> Launch Scenario (this generates the .txt)] from a command window or, preferable, an .exe so I can run it directly from my code. Can anyone think a way around this?
Like I outlined before: put the serialization code into a simstart event handler, then immediately close the simulation again (if closing is not possible yet via API, send a WM_CLOSE window message to the render window). This way you can launch orbiter_ng.exe without a graphics client, it is even possible via CLI to open a specific scenario immediately without a launchpad showing up. It might take around 10 secs for a run, though, depending on your installation.
 

LauncherLover

New member
Joined
Mar 19, 2024
Messages
18
Reaction score
1
Points
1
Location
Madrid
Like I outlined before: put the serialization code into a simstart event handler, then immediately close the simulation again (if closing is not possible yet via API, send a WM_CLOSE window message to the render window). This way you can launch orbiter_ng.exe without a graphics client, it is even possible via CLI to open a specific scenario immediately without a launchpad showing up. It might take around 10 secs for a run, though, depending on your installation.
I have no idea what the serialization code and the simstart event handler are. Is there any kind of guide I can follow for this?
 

Face

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 18, 2008
Messages
4,403
Reaction score
581
Points
153
Location
Vienna
Serialization is essentially when you write structured data into a byte-stream, or in other words: whatever you did to write those xyz values into a file (most probably fprintf). All Orbiter modules have a callback for the simulation start event. You'd simply move your code there, so it is the first action done after simulation starts, without the need to open a dialog or click a button.
I can try to come up with a small addon on the weekend to demonstrate the idea.
 

LauncherLover

New member
Joined
Mar 19, 2024
Messages
18
Reaction score
1
Points
1
Location
Madrid
Serialization is essentially when you write structured data into a byte-stream, or in other words: whatever you did to write those xyz values into a file (most probably fprintf). All Orbiter modules have a callback for the simulation start event. You'd simply move your code there, so it is the first action done after simulation starts, without the need to open a dialog or click a button.
I can try to come up with a small addon on the weekend to demonstrate the idea.
Would it Be possible to run orbiter and a specific scenario from command window (or other kind of ejecutable file) to automate the process? What would these commnads be?
 

Face

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 18, 2008
Messages
4,403
Reaction score
581
Points
153
Location
Vienna
Would it Be possible to run orbiter and a specific scenario from command window (or other kind of ejecutable file) to automate the process? What would these commnads be?
Yes. Open a command window, navigate to the root folder, then either use "orbiter.exe -s <scenario\path>" for the regular Orbiter, or "Modules\Server\orbiter.exe -s <scenario\path>" for the OVP Orbiter. The <scenario/path> can be relative, e.g. "Scenarios\(Current state).scn". This should immediately start into the simulation window, skipping the launchpad.
 

LauncherLover

New member
Joined
Mar 19, 2024
Messages
18
Reaction score
1
Points
1
Location
Madrid
Yes. Open a command window, navigate to the root folder, then either use "orbiter.exe -s <scenario\path>" for the regular Orbiter, or "Modules\Server\orbiter.exe -s <scenario\path>" for the OVP Orbiter. The <scenario/path> can be relative, e.g. "Scenarios\(Current state).scn". This should immediately start into the simulation window, skipping the launchpad.
bro this is awesome. Surely you can algo activate a Module from the command window, right? Where do you take all this information from? Ive been searching for it but hacen been lucky
 

LauncherLover

New member
Joined
Mar 19, 2024
Messages
18
Reaction score
1
Points
1
Location
Madrid
Yes. Open a command window, navigate to the root folder, then either use "orbiter.exe -s <scenario\path>" for the regular Orbiter, or "Modules\Server\orbiter.exe -s <scenario\path>" for the OVP Orbiter. The <scenario/path> can be relative, e.g. "Scenarios\(Current state).scn". This should immediately start into the simulation window, skipping the launchpad.
Tried this and a fatal error pops up bc it cant find the scenario. Tried with all variations of syntax, should I add the forlder to any kind of path?
 

Face

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 18, 2008
Messages
4,403
Reaction score
581
Points
153
Location
Vienna
bro this is awesome. Surely you can algo activate a Module from the command window, right? Where do you take all this information from? Ive been searching for it but hacen been lucky
Unfortunately you can't activate a Module from the command line. You will have to create a temp config file and exchange it with the "real" one, then do the call, then change the old back again. That's how I do it in my multiplayer launcher. Most of the information I take directly from Orbiter's source code or old project's code.
Tried this and a fatal error pops up bc it cant find the scenario. Tried with all variations of syntax, should I add the forlder to any kind of path?
Don't miss the "navigate to the root folder" part. This means you have to use the standard shell commands to get your working directory to the Orbiter installation root folder. If you open a command shell, you usually start out in your user folder (C:\Users\<user>). If your Orbiter installation is e.g. at "C:\Program Files (x86)\Orbiter", you need to do a 'cd "C:\Program Files (x86)\Orbiter"' call before calling the executable. Also mind quotation marks around paths with space in it.

EDIT: forget what I said about relative path support! I just double-checked my code and realized that I always used absolute paths when invoking that "-s" option. So you need to put 'orbiter.exe -s "'C:\absolute\path\to\scenario\file.scn"' into it. The navigating to the proper root folder is still necessary, lest Orbiter won't find its files anymore.
 
Last edited:

LauncherLover

New member
Joined
Mar 19, 2024
Messages
18
Reaction score
1
Points
1
Location
Madrid
Unfortunately you can't activate a Module from the command line. You will have to create a temp config file and exchange it with the "real" one, then do the call, then change the old back again. That's how I do it in my multiplayer launcher. Most of the information I take directly from Orbiter's source code or old project's code.

Don't miss the "navigate to the root folder" part. This means you have to use the standard shell commands to get your working directory to the Orbiter installation root folder. If you open a command shell, you usually start out in your user folder (C:\Users\<user>). If your Orbiter installation is e.g. at "C:\Program Files (x86)\Orbiter", you need to do a 'cd "C:\Program Files (x86)\Orbiter"' call before calling the executable. Also mind quotation marks around paths with space in it.

EDIT: forget what I said about relative path support! I just double-checked my code and realized that I always used absolute paths when invoking that "-s" option. So you need to put 'orbiter.exe -s "'C:\absolute\path\to\scenario\file.scn"' into it. The navigating to the proper root folder is still necessary, lest Orbiter won't find its files anymore.
Bro, I love you. I finally achieved what I needed to do, thank you so much!
 
Top