Troubles with AMBIENT_PRES_MBAR

#1
Hello everybody!
I've got a problem.
I wonna get altitude from barometric pressure, but when I tray to get value of AMBIENT_PRES_MBAR or BAROMETRIC_PRESSURE tokens I get it only once per second (not 18 times per second).
I used different macros (STRING and NEEDLE), but the result is the same. If I use another token for this macros (AIRSPEED for example) I get fast updating (18 times per second).
Could you tell me - whats problem?
p.s. Sorry for my English.
p.p.s. I use C gauges.
 
#2
I have a such problem!

FS change variable AMBIENT_PRES_MBAR \ BAROMETRIC_PRESSURE very slow (discrete).

My solution was based on own calculating barometric pressure depending absolute altitude (PLANE_ALTITUDE).

Just..
double dCurrentPressureMRS = 760.0 / pow( M_E, (mvAltitude.var_value.n / 7991) );
...and get bar.press (in mm merc pole)

Then, using this calculated baro, I calculate altitude in gauge (depending on setting baro).

Extra code, but nothing to find better :\.
 
#3
For us to help you, you will need to post your code. How do you know you are only getting an update 1 time per second?

I have no trouble at all with my altimeter.
 
#4
Lavrik
Thanx!
I was thinking of this way, but was not sure.

Waugh
Some code for example:
============================================================
......
UINT32 PressSet=0;
FLOAT64 LastVal=0;


FLOAT64 FSAPI temperature_string_cb( PELEMENT_STRING pelement )
{
FLOAT64 val = pelement->source_var[0].var_value.n;

if (val==LastVal)
{
PressSet=PressSet+1;
}
else
{
wsprintf(pelement->string, "%d", (UINT32)PressSet);
PressSet=0;
LastVal=val;
}

return val;
}

MAKE_STRING
(
temperature_string,
NULL,
NULL,
IMAGE_USE_ERASE | IMAGE_USE_BRIGHT | IMAGE_USE_TRANSPARENCY,
0,
28, 9,
60, 29,
4,

AMBIENT_PRES_MBAR,
MODULE_VAR_NONE,
MODULE_VAR_NONE,
RGB(255,0,0),
RGB(0,0,0),
RGB(92,92,92),
GAUGE_FONT_DEFAULT,
GAUGE_WEIGHT_DEFAULT,
GAUGE_CHARSET,
0,
DT_CENTER | DT_VCENTER | DT_SINGLELINE,
NULL,
temperature_string_cb
)
=============================================================
I just count cycles for not change value.
As a result - 17,18.
Not less.
With maximum VERTICAL SPEED.
 

n4gix

Resource contributor
#5
Don't depend on the MAKE_STRING macro to read the variable for you.

Instead, perform a lookup in the PREUPDATE case:
Code:
FLOAT64 AmbientPressMB = 0 ;
MODULE_VAR AMBIENT_PRES_MBARvar= {AMBIENT_PRES_MBAR};

		case PANEL_SERVICE_PRE_UPDATE:
			lookup_var(&AMBIENT_PRES_MBARvar);
                        AmbientPressMB = AMBIENT_PRES_MBARvar.var_value.n ;
		break;
You can then use AmbientPressMB in the rest of your code as you like. This will execute at 18 Hz without fail...
 
#6
Well first, it is my understanding that MACRO callbacks (such as yours) are not guaranteed to be called at a certain rate.

Instead, you should be using the GAUGE callback.

Second, although I understand your code, I still have no idea what you are trying to do. Why are you not using:

ALT_FROM_BAROMETRIC_PRESSURE

which gives you the altitude? That is what you said you want, altitude, so just get it directly.

Patrick
 
#7
This will execute at 18 Hz without fail...
Yes, but, this sim variable changes very slow! I don't know why, but if try fast descend\climb, this will is well seen. FS version - X (in 2004 don't look). May be this depend's on many other factors (sim settings, proccessor loads, etc - i not sure).

Why are you not using: ALT_FROM_BAROMETRIC_PRESSURE which gives you the altitude?
Because, for example, I have four (4) altimeter with independent baro setting. How i can realize their with one sim variable(ALT_FROM_BAROMETRIC_PRESSURE)? I know only described below method (through manually calculated baro, and then alt).....
 
Last edited:
#8
Yes, but, this sim variable changes very slow! I don't know why, but if try fast descend\climb, this will is well seen. FS version - X (in 2004 don't look). May be this depend's on many other factors (sim settings, proccessor loads, etc - i not sure).
Pressure chnages slowly relative to altitude change, and has pretty low resolution in FS.


Because, for example, I have four (4) altimeter with independent baro setting. How i can realize their with one sim variable(ALT_FROM_BAROMETRIC_PRESSURE)? I know only described below method (through manually calculated baro, and then alt).....
If I were going to do this, then I would setup my own INC/DEC vars for the other altimeters, and then just calculate the "indicated" altitude from the pressure setting difference between altimeters and the altitude returned based on the setting of the primary altimeter. In other words, determine the altitude to display on a second altimeter by adjusting the indicated altitude up/down from the indicated altitude of the primary altitude based on the difference in INC/DEC setting.

Patrick
 
#9
If I were going to do this, then I would setup my own INC/DEC vars for the other altimeters, and then just calculate the "indicated" altitude from the pressure setting difference between altimeters and the altitude returned based on the setting of the primary altimeter. In other words, determine the altitude to display on a second altimeter by adjusting the indicated altitude up/down from the indicated altitude of the primary altitude based on the difference in INC/DEC setting.
Hmm, interesting variant, I dont think in that way, thanks.
 
#11
but ALT_FROM_BAROMETRIC_PRESSURE based on BAROMETRIC_PRESSURE.
How source value (pressure) can changes slowly than result (altitude)?
Because unlike in the real world where one depends on the other, they are both simulated variables and pressure might actually be derived (in part) from altitude! Also, it seems to me (and I could be wrong) that the resolution (number of decimals) of the pressure is much lower than altitude. This would make sense because it takes only a small pressure change to make a larger altitude change. =)

But, anyway, if you are trying to make 2 backup altimeters that can have their kohlsman adjusted separately that's how I would do it. To be honest, I'm not sure it is worth the trouble since they should always be both set to the same altitude.

Patrick
 
Top