API Question How can I get atmospheric pressure at an altitude where I ain't?

Wishbone

Clueless developer
Addon Developer
Joined
Sep 12, 2010
Messages
2,421
Reaction score
1
Points
0
Location
Moscow
Probing the idea of a lunch ^H^H^H^H^H launch trajectory optimizer (at least, integrator), I come back to the basics. To get forces in the integrator, I need Cl and Cd. To get Cl and Cd I need Mach number, to get Mach number I need speed of sound. There is no speed of sound function in the API, so I calculate it from the ground up (I have ratio of specific heats, all I need is pressure and density). The question is: how do I get ATMPARAM on Earth and Venus, since the functions that use CELBODY interface all return false.

And yes, I know about oapiGetAtm, but it uses vessel state and I don't want it - I want to know the pressure/density where I ain't.
 

Hielor

Defender of Truth
Donator
Beta Tester
Joined
May 30, 2008
Messages
5,580
Reaction score
2
Points
0
Why don't you want the pressure at the vessel's current location? The speed of sound changes with altitude/air pressure, so if you don't use the pressure at the vessel's location, you won't be calculating the correct Mach number.

---------- Post added at 14:55 ---------- Previous post was at 14:52 ----------

On that note, why don't you just use the GetMachNumber function for the vessel?
 

Wishbone

Clueless developer
Addon Developer
Joined
Sep 12, 2010
Messages
2,421
Reaction score
1
Points
0
Location
Moscow
The idea is to forecast the trajectory. The vessel is here (180 meters something AMSL, with airspeed zero - sitting at a table), but I want to know the speed of sound at 40 km altitude (assuming no lat/lon/f10.7 dependence for now), at least the T/rho/P at this altitude, so that the integrator could forecast the trajectory up to MECO. There will be dozens of little integration steps, and at each one the program will need speed of sound (I may choose to memoize it to save CPU time, but that's irrelevant).

I already have a couple of speed of sound engineering formulas (spliced polynomials), and five to six atmospheric models. However, Precession MFD should work on other planets as well, where neat engineering shortcuts aren't available, and on Earth with other player-chosen atmosphere. Hence the question.
 

Hielor

Defender of Truth
Donator
Beta Tester
Joined
May 30, 2008
Messages
5,580
Reaction score
2
Points
0
I don't have access to the SDK docs at the moment, but one thing that would work would be to make a vessel, put it where you want to measure the pressure, then delete it when you're done with it :p
 

Notebook

Addon Developer
Addon Developer
News Reporter
Donator
Joined
Nov 20, 2007
Messages
11,822
Reaction score
644
Points
188
Not sure I get what you want, but could you do a dry run with a vehicle and collect that data? Then use tha as a template for forecasting.

N.
 

Wishbone

Clueless developer
Addon Developer
Joined
Sep 12, 2010
Messages
2,421
Reaction score
1
Points
0
Location
Moscow
Hurrm, no offense here, but it looks like suggestions from Vasily Mishin (let's launch the N1 once more and collect all the data for ... future reference). Launching imaginary or real vehicles is just too expensive (in terms of time, coding effort, money etc.)

The point is the atmospheric model is already coded in Orbiter, just not accessible to addon developers. I can follow the lucid description by Martin in the technote and implement it myself, or go on and port the atmospheric models I already have in other languages (say, Fortran), but when Martin revises the model next time or, more likely, the user changes from legacy 2006 model to Jacchia-Gill or whatever, do we have to rewrite the code?

This is a race that can never be won by addon writers - there are other planets with atmosphere, and entirely fictional systems with any kind of atmosphere imaginable and unimaginable, do we have to track all the cases? To be of help to Orbiter players, addons must be accurate, and the best way to ensure it is to use the same code as the simulator.
 

N_Molson

Addon Developer
Addon Developer
Donator
Joined
Mar 5, 2010
Messages
9,296
Reaction score
3,270
Points
203
Location
Toulouse
I would try to create a "virtual" vessel (no mesh or extremely small "size" parameter") at a given altitude, then retrieve the pressure data via a handle... (v->GetAtmPressure...)

Or maybe the "virtual" vessel could be created at a given distance of the player's ship, and stay at the same position (relative to the vessel, maybe with a "sub-autopilot" and hyper-powerful invisible thrusters)...

Just my two cents...
 

tblaxland

O-F Administrator
Administrator
Addon Developer
Webmaster
Joined
Jan 1, 2008
Messages
7,320
Reaction score
25
Points
113
Location
Sydney, Australia
I'm curious why you are getting no results through the CELBODY interface. That is the interface that Orbiter uses to get the atmospheric parameters for bodies that have a plugin module. Can you paste a code segment for how you are using it?
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,910
Reaction score
2,169
Points
203
Location
between the planets
If the atmosphere is defined in a dll, I have no idea. If the atmosphere doesn't have a dll, the best way for getting the presure at altitude x is to use the standard formula Orbiter uses, which is listed in the API guide under atmosphere.
 

Wishbone

Clueless developer
Addon Developer
Joined
Sep 12, 2010
Messages
2,421
Reaction score
1
Points
0
Location
Moscow
Code:
	double GetMaxMainForce(CELBODY* planet, double Altitude)// alt in meters
	{
		if (planet==NULL) 
		{
			return GetMaxMainForce(0.0);
		};
		ATMPARAM atm;
		if (planet->clbkAtmParam(Altitude, &atm)==true)
		{
			return GetMaxMainForce(atm.p);
		}
		else
		{
			// vacuum
			// it always gets here - on Venus and on Earth at least
			return GetMaxMainForce(0.0);
		};
	}
 

tblaxland

O-F Administrator
Administrator
Addon Developer
Webmaster
Joined
Jan 1, 2008
Messages
7,320
Reaction score
25
Points
113
Location
Sydney, Australia
CELBODY objects seem to have CELBODY::clbkAtmParam return false when CELBODY::Version != 1. Have you tried CELBODY2::GetAtmosphere and ATMOSPHERE::clbkParams? I have not yet myself.

BTW:
Code:
			return GetMaxMainForce(0.0);
Won't that try to evaluate GetMaxMainForce again? I've not seen that syntax in C++ before and I'm surprised you are not getting a "function does not take 1 arguments" error.
 

Wishbone

Clueless developer
Addon Developer
Joined
Sep 12, 2010
Messages
2,421
Reaction score
1
Points
0
Location
Moscow
I use several versions of GetMainForce :)

Right now this code yields the same pressure (ground level 1013.etc Pa) for any altitude on Earth:
Code:
inline double GetStaticPressure(CELBODY* planet, double Altitude)// alt in meters
{
	if (planet==NULL) 
	{
		//oapiWriteLog("no planet");
		return 0.0;
	};
	ATMPARAM atm;
	ATMOSPHERE* atm2;
	ATMOSPHERE::PRM_IN inparam;
	ATMOSPHERE::PRM_OUT outparam;
	CELBODY2 * pl2;
	switch (planet->Version())
	{
	case 1:
		if (planet->clbkAtmParam(Altitude, &atm)==true)
		{
			return atm.p;
		}
		else
		{
			// vacuum
			return 0.0;
		};
		break;
	case 2:
		pl2 = (CELBODY2 *) planet;
		atm2 = pl2->GetAtmosphere();
		inparam.alt = Altitude;
		inparam.lat = 0.0;
		inparam.lng = 0.0;
		inparam.ap = 3.0;
		inparam.f107bar = 140;
		inparam.f107 = inparam.f107bar;
		if (atm2->clbkParams(&inparam, &outparam)==true)
		{
			return outparam.p;
		}
		else
		{
			return 0.0;
		};
		break;
	default:
		oapiWriteLog("unsupported CELBODY version");
		throw "unsupported CELBODY version";
	};
}
Sigh...
 

martins

Orbiter Founder
Orbiter Founder
Joined
Mar 31, 2008
Messages
2,448
Reaction score
462
Points
83
Website
orbit.medphys.ucl.ac.uk
You need to set the inparam.flag entry to PRM_ALT (in addition to any other valid input parameters you are supplying, such as PRM_LNG, PRM_LAT, PRM_FBR and PRM_AP). Otherwise the inparam.alt parameter is ignored.
 
Top