Jump to content
The simFlight Network Forums

Oil Temp Sensor


Recommended Posts

Pete,

I am trying to make a Lua script that will act as a sensor for when the Oil Temp in each Engine of a Twin Engine gets above 80 degrees Celsius. I am using a GoFlight module as my LED test light.

Below is my most recent attempt for Engine1 which I assembled from insights gained from Lua documents and numerous Lua script examples. If you could steer me in the right direction as to what it is I am missing, I would sure appreciate it.

Dan

OilTemp1 = ipc.readSW(08B8) -- OilTemp1 Offset

Limit1 = 80 * 140 / 16384 -- to 80 Celsius

while 1 do

if OilTemp1 > Limit1 then -- OilTemp1 Trigger LED

gfd.SetLight(GFP8, 0, 2)

ipc.sleep(500)

gfd.ClearLight(GFP8, 0, 2)

ipc.sleep(500)

gfd.SetLight(GFP8, 0, 2)

ipc.sleep(1000)

else

if OilTemp1 < Limit1 then -- OilTemp1 Clear LED

gfd.ClearLight(GFP8, 0, 2)

end

ipc.sleep(20)

end

Link to comment
Share on other sites

Below is my most recent attempt for Engine1 which I assembled from insights gained from Lua documents and numerous Lua script examples. If you could steer me in the right direction as to what it is I am missing, I would sure appreciate it.

Well, the glaring error seems to be here:

Limit1 = 80 * 140 / 16384 -- to 80 Celsius

where you want to compare "Limit1" with the FS value where 16384 represents 140. This makes Limit1 equal to 0.68, a value which is between 0 and 1 for the offset out of its range of 0-16384 for 0 - 140 degrees!

To make "Limit1" equal to the value equivalent to 80, you would need

Limit1 = 80 * 16384 / 140

of course. You are scaling the other way. You can do that too, like

if (OilTemp1 * 140 / 16384) > 80 then ...

but of course that is far less efficient because you are repeating the computations 50 times per second.

Which brings me to this:

ipc.sleep(20)

Isn't 50 times per second a bit over the top? Especially considering that you are flashing a LED over a 2 second period too. Why not just check it every half or even one second?

Regards

Pete

Link to comment
Share on other sites

Well, the glaring error seems to be here:

Limit1 = 80 * 140 / 16384 -- to 80 Celsius

where you want to compare "Limit1" with the FS value where 16384 represents 140. This makes Limit1 equal to 0.68, a value which is between 0 and 1 for the offset out of its range of 0-16384 for 0 - 140 degrees!

To make "Limit1" equal to the value equivalent to 80, you would need

Limit1 = 80 * 16384 / 140

of course. You are scaling the other way. You can do that too, like

if (OilTemp1 * 140 / 16384) > 80 then ...

but of course that is far less efficient because you are repeating the computations 50 times per second.

Which brings me to this:

ipc.sleep(20)

Isn't 50 times per second a bit over the top? Especially considering that you are flashing a LED over a 2 second period too. Why not just check it every half or even one second?

Regards

Pete

Link to comment
Share on other sites

Pete,

Thanks for the direction. But still, no joy!

I had used the very equation you provided (Limit1 = 80 * 16384 / 140) in a previous attempt. However, when I did not get the desired results, I went on to trying other approaches.

I did change ipc.sleep to (1000) as you suggested, but still, I am not getting the LED to light when the Oil Temp exceeds 80 degrees Celsius.

In other attempts at solving this, I have tried using Limit1 = 9362.28 (the result of 80 * 16384 / 140).

I have also tried using the Rankine Offset (see below) in my script, as well as using Limit1 = 635.67 (the result of 80 * 1.8 + 491.67).

OilTemp1 = ipc.readDBL(3B58) -- Rankine OilTemp1 Offset

Limit1 = 80 x 1.8 + 491.67 -- Rankine Conversion

Below is the current script with the changes you provided. Please advise on what it is that I am not yet taking into account.

-- LED-3 - Oil Temperature Sensor

OilTemp1 = ipc.readSW(08B8) -- Celsius OilTemp1 Offset

Limit1 = 80 * 16384 / 140 -- Celsius Conversion

while 1 do

if OilTemp1 > Limit1 then -- OilTemp1 Trigger LED

gfd.SetLight(GFP8, 0, 2)

ipc.sleep(500)

gfd.ClearLight(GFP8, 0, 2)

ipc.sleep(500)

gfd.SetLight(GFP8, 0, 2)

ipc.sleep(1000)

else

if OilTemp1 < Limit1 then -- OilTemp1 Clear LED

gfd.ClearLight(GFP8, 0, 2)

end

ipc.sleep(1000)

end

Link to comment
Share on other sites

I had used the very equation you provided (Limit1 = 80 * 16384 / 140) in a previous attempt. However, when I did not get the desired results, I went on to trying other approaches.

Why not use logging to see what values you are getting? Maybe the aircraft you are using doesn't update this value. Add the offset to the Monitor in FSUIPC's logging, and do

ipc.log(OilTemp1)

or something more sophisticated if you like, in your program.

Logging is really the only way to see what is going on.

[LATER]

Oh, one thing wrong, at least in that latest version you showed:

You only read the offset once, then go around a loop forever checking the same initial value. If the Oiltemp is over 80 when you START the program, it will work, but then it'll never change again.

was your original program like that too? I didn't notice.

Pete

Link to comment
Share on other sites

Why not use logging to see what values you are getting? Maybe the aircraft you are using doesn't update this value.

For 0x08B8, I get a constant 6868. So because this value does not change, even though the OilTemp does, am I to assume that this aircraft does not update this value?

Link to comment
Share on other sites

For 0x08B8, I get a constant 6868. So because this value does not change, even though the OilTemp does, am I to assume that this aircraft does not update this value?

Where did you log that? If in your program, not in FSUIPC, then did you correct your program and read the Oil Temp INSIDE the loop? Remember, I said:

You only read the offset once, then go around a loop forever checking the same initial value. If the Oiltemp is over 80 when you START the program, it will work, but then it'll never change again.

If you haven't fixed this it will of course never change in your program.

Pete

Link to comment
Share on other sites

Where did you log that? If in your program, not in FSUIPC, then did you correct your program and read the Oil Temp INSIDE the loop? Remember, I said:

If you haven't fixed this it will of course never change in your program.

Pete

I did put OilTemp1 inside while 1 do (see below). But prior to previous post, I forgot to refresh ipcready.lua. Sorry about that!

Limit1 = 80 * 16384 / 140 -- Celsius Conversion

while 1 do

OilTemp1 = ipc.readSW(0x08B8) -- Celsius OilTemp1 Offset

if OilTemp1 > Limit1 then -- OilTemp1 Trigger LED

In FSUIPC, I am logging 08B8 SW to FS window with IPC Reads and Lua Program Logging selected.

In flight, as the Oil Temp gauge climbs to 80C, the value also rises. Right around 80C on the gauge, the value for 08B8 is 6923.

With that number in hand, I tried using Limit1 = 6923. But still, no LED.

Link to comment
Share on other sites

In flight, as the Oil Temp gauge climbs to 80C, the value also rises. Right around 80C on the gauge, the value for 08B8 is 6923.

Hmm. strange. That would suggest 59 degrees. Maybe the chap who supplied the information for FS9 got it wrong, or maybe it's being modified for the gauge for some reason. Have you checked that it is the same for all aircraft?

With that number in hand, I tried using Limit1 = 6923. But still, no LED.

Well your test is for > not >= so the value read would need to be 6924 or more, wouldn't it.

Haven't you tried logging in your program at all? I can't really debug your program from here. Logging is a very valuable debugging tool.

[LATER]

I've just been monitoring, on screen, the value of 08B8, with the default FS9 737. comparing the crude analogue gauge with the offset value isn't accurate, but as I left the thing running and watched the oil temperature rise, when the needle passed the 50 C marker on the gauge the offset correctly read about 5800. So at least for default jets it seems good.

So i loaded the default Cessna. Its oil temp gauge reads Fahrenheit. At the 150 F mark the readout in the offset was around 7800, which is 65 C or 151 F, so that seems good too.

If you aren't getting matching results with an add-on aircraft it maybe that their gauge isn't showing the actual FS value, but some 2fiddled" value to approximate more to realistic values according to the way the aircraft has been written. If I were you I'd always test things first with default aircraft.

Regards

Pete

Link to comment
Share on other sites

If you aren't getting matching results with an add-on aircraft it maybe that their gauge isn't showing the actual FS value, but some 2fiddled" value to approximate more to realistic values according to the way the aircraft has been written. If I were you I'd always test things first with default aircraft.

Pete, I have a feeling you are right on concerning add-on aircraft, as this is one that is known to operate outside the FSX standards in various ways. In the meantime, I think I need to let my frustration level simmer down a little, as well as do so more reading and testing. I really appreciate your time and insight. You have been most kind!

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
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.