Ammeter code help

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Post Reply
Message
Author
Irimi-Ai
Posts: 12
Joined: Sun Sep 13, 2020 12:28 pm

Ammeter code help

#1 Post by Irimi-Ai »

Hi there,

I'm trying to create a simple ammeter gauge for GA aircraft that will work in MSFS2020. I'm using Hannes Schulten's Bombardier Ammeter gauge from the online store as a template since it's the same style (center-zero) as the one in the C172 I fly. The gauge should operate like the one in this instructional video (https://www.youtube.com/watch?v=Eg5o7MKCeTs).

However, I'm running into a couple of issues.

1) The default gauge behavior is odd in that it only seems to produce values of -32, 32, or 28 depending on different combinations of master battery and alternator states. The gauge should produce a floating integer on the full continuum between -30 and 30, and not just 3 static, pre-determined values. My basic understanding is that the gauge should indicate the numerical result of the following equation: amps produced by the alternator - amps discharged by the battery (e.g., an alternator producing 30 amps - the battery discharging at 28 amps = 2 amps; a slight charge to the battery as in normal flight).

Questions:
A) Am I thinking about this totally wrong?
B) If not, how would the formula be coded?

2) I also have a hardware LED light on the panel that should light up whenever the ammeter indicates a discharge state of 5 or more amps (i.e., when the result of the equation is less than or equal to -5 amps). It's not really a "low volt" light in this case. It indicates when the aircraft's electrical supply is primarily being supplied by the battery (i.e., alternator failure).

Question:
A) How would this "If" statement be coded within the function?


Here's the code I'm running:

Code: Select all

img_add_fullscreen("background.png")
pointer = img_add("pointer.png", 48, 140, 400, 400)
rotate(pointer, 90)
rotate(pointer, 122)
rotate(pointer, 57)

function new_amp (pamp)
    amp = pamp
    amp = 122 - (65 * ((amp + 30)/60))
    amp = var_cap(amp, 55, 110)
    rotate(pointer, amp)
end

fs2020_variable_subscribe("ELECTRICAL GENALT BUS AMPS:1","Amperes", new_amp)
fs2020_variable_subscribe("ELECTRICAL BATTERY BUS AMPS", "Amperes", new_amp)

---------------------------------------------
--   Controls Add                          --
---------------------------------------------
hw_led_id = hw_led_add("Ammeter Light", 0.25)
Appreciate the help!

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Ammeter code help

#2 Post by Sling »

Hi,

You have a few things wrong so let’s work through them.

A floating integer is not a thing. It’s either a float or an integer. If your not sure which is which you can Google that.

In a real aircraft the sum will be alt amps - bus amps = battery amps or just battery amps. Alt produces 30A bus is taking 28A meaning the battery is taking the other 2A (charging). When the alternator is offline for whatever reason the result is -28A, meaning the battery is supplying the bus loads and therefore discharging.

When you use the subscribe functions they should either have their own unique callback or probably what’s best in this case is return both subscribes to a single callback but correctly. You have this wrong. It should be like this.

Code: Select all


function new_amp (pamp, bamp)
    
    — needle code goes here
    
end

fs2020_variable_subscribe("ELECTRICAL GENALT BUS AMPS:1","Amperes",
                                        “ELECTRICAL BATTERY BUS AMPS", "Amperes", new_amp)

I hope this helps

Tony

Post Reply