Sign in to follow this  
Jim Robinson

Problem with radio gauge

Recommended Posts

Hi all,I'm working on my first panel for FSX and have run into some quirky behaviour with a radio stack gauge I'm making which I'd really appreciate some help with. I'm using the following gauge string:%( (A:COM STANDBY FREQUENCY:1, MHz) 100 * 1 div 100 /)%!3.2f!...which works fine except when the frequency on the default radio stack reads XXX.20 mine reads XXX.19. Similarly for these values:Default MineXXX.45 XXX.44XXX.70 XXX.69XXX.95 XXX.94For all other values my readout is correct. Can anyone tell me what I'm doing wrong?Many thanks,DD

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

On closer inspection, the 3 digits to the left of the decimal point always display correctly, but the 2 to the right are sometimes off by 0.01. The weird thing is that the digits on the right which don't work vary depending on the value of the digits on the left. For example, "127.67" works fine, but "128.67" displays as "128.68". I'm even more baffled than I was before :/.DD

Share this post


Link to post
Share on other sites

Hi DD I use ((A:COM1 STANDBY FREQUENCY, MHz))%!6.2f! for all simple frequency number displays.

Share this post


Link to post
Share on other sites

Hi, here is an example that explains the oddity:-Default freq = 118.67894 - the value is rounded to 2 decimals so it shows 118.68-Using your formula :118.67894 100 * = 11867.894 1 div = 11867100 / = 118.67 Solution = use Paul's approach or (A:COM STANDBY FREQUENCY:1, MHz) 100 * near 100 /Tom

Share this post


Link to post
Share on other sites

Thanks very much for the help guys - I'm away for the weekend, but will give your suggestions a go as soon as I get back.Cheers,DDP.S. A bit of a daft question, but is it "reverse Polish notation" (as in 303 squadron) or "reverse polish notation" (as in "wax on, wax off")? I've seen it written both ways in the docs and was just wondering which is correct.

Share this post


Link to post
Share on other sites

Polish, pronounced as pO-lish...not as pAH-lish... ;)

Share this post


Link to post
Share on other sites

Hi BillDon't you mean Polish as in Poland and not Polish as in Kiwi? :)(I'm really sorry - that was an awful joke and I'm not sure it travelled outside the UK. Kiwi is a brand of shoe cleaner, as well as a native of New Zealand).-Dai

Share this post


Link to post
Share on other sites

>Hi Bill>>Don't you mean Polish as in Poland and not Polish as in Kiwi?>:)>>(I'm really sorry - that was an awful joke and I'm not sure it>travelled outside the UK. Kiwi is a brand of shoe cleaner, as>well as a native of New Zealand).I polish my Polish shoes with Kiwi, before chasing kiwi's in the outback... :)

Share this post


Link to post
Share on other sites

I thought I understood what was going on after reading Tom's explanation, but when I had the sim display the frequency to several decimal places, I found that the variable only contains values up to the third digit after the decimal so presumably the zeroes beyond that can't be having any effect.I've tried both Paul and Tom's suggestions, but neither seems to exactly replicate the behaviour of the default radio stack (which ignores the third number after the decimal point so that XXX.625 is displayed as XXX.62 and not as XXX.63). I then tried breaking my original formula down into its components and found the following (with a frequency of 127.700 as displayed by the tooltip):((A:COM1 STANDBY FREQUENCY, MHz) 100 *) gives 12770.00((A:COM1 STANDBY FREQUENCY, MHz) 100 * 1 div) gives 12769.00 (!)((A:COM1 STANDBY FREQUENCY, MHz) 100 * 1 div 100 /) gives 127.69...so it would seem to be the DIV operation which is calculated incorrectly thereby throwing off the final result. In the end I got tired of banging my head against the monitor and just drew the frequencies to 3 decimal places and used a mask image to hide the final digit, which has done the trick but I'd still love to know why the DIV didn't work.Onto another couple of questions: 1. I'm using (A:COM STATUS:X,enum) to control the visibility of the comm radio digits, so they don't display if they have no electricity or have failed, but I couldn't find equivalent variables for the other radios (specifically ones which are also triggered by a failure). I'm assuming there must be some -what do you guys use?2. When you press C or T, for example, part of the comm or transponder frequency changes colour and can be adjusted with the + and - keys. Is there a variable somewhere which stores the identity of the variable which is currently controllable with these keys?Cheers,DD

Share this post


Link to post
Share on other sites

I'm wondering why you're doing all that math to begin with.(A:COM1 STANDBY FREQUENCY, MHz) returns the value as 127.700 and thus should be at the actual value you seek to begin with. I believe if you want the value as 127700 you should be asking for (A:COM1 STANDBY FREQUENCY, KHz).

Share this post


Link to post
Share on other sites

Hi Ed,The reason I was using the formula is because (A:COM1 STANDBY FREQUENCY, MHz) doesn't produce the same results as the default radio stack.For example, when the frequency is 128.525 (as displayed by the tooltip), the default radio stack will display 128.52 but (A:COM1 STANDBY FREQUENCY, MHz) displayed in "3.2f" format will give you 128.53.The weird thing is, it's not consistent - if you decrement the whole part of the frequency to 127 so the tooltip now reads 127.525, the default stack will display 127.52 and this time so will (A:COM1 STANDBY FREQUENCY, MHz) displayed in "3.2f" format.It's this effect of a change in the whole part of the frequency causing a change in the displayed fractional part which I'm trying to avoid. The formula was intended to multiply the frequency by 100 (12852.5), truncate that using DIV 1 (12852), then divide by 100 to give the same result as the default radio stack (128.52).Cheers,DD

Share this post


Link to post
Share on other sites

>Hi Ed,>The reason I was using the formula is because (A:COM1 STANDBY>FREQUENCY, MHz) doesn't produce the same results as the>default radio stack.>>For example, when the frequency is 128.525 (as displayed by>the tooltip), the default radio stack will display 128.52 but>(A:COM1 STANDBY FREQUENCY, MHz) displayed in "3.2f" format>will give you 128.53.>The default radio stack is a C++ gauge, thus uses different code to produce it's results.>The weird thing is, it's not consistent - if you decrement the>whole part of the frequency to 127 so the tooltip now reads>127.525, the default stack will display 127.52 and this time>so will (A:COM1 STANDBY FREQUENCY, MHz) displayed in "3.2f">format.>It's the DIV function in the XML that's causing part of the problem. The other culprit is the format command. The "best" method for this is to extract the remainder from the 12.5xx value so that you have it separate... then based on that value add either .02/.05/.07 or nothing. While I know diddly squat about XML... if it has a mod function, that's what you need.>It's this effect of a change in the whole part of the>frequency causing a change in the displayed fractional part>which I'm trying to avoid. The formula was intended to>multiply the frequency by 100 (12852.5), truncate that using>DIV 1 (12852), then divide by 100 to give the same result as>the default radio stack (128.52).>Cheers,>DDYep... you can't truncate with a division or the format command.

Share this post


Link to post
Share on other sites

>Yep... you can't truncate with a division or the format>command.My understanding of the DIV command (as opposed to division) was that "A B DIV" (in reverse Polish) meant "the number of times B can be divided completely into A" so "12852.5 1 DIV" should truncate it to "12852". Have I misunderstood the function, or are you just saying that that operator is unreliable in FSX?The list of operators in the docs gives % as the symbol for taking the modulo, but I've tried both that and "mod" with no success. I did wonder if maybe a different symbol has to be used in the xml (in the same way that "<" is replaced by "<". I couldn't find any mention of this in the docs, though.Cheers,DD

Share this post


Link to post
Share on other sites

No... if you're taking 12852.5 and wanting to eliminate the fractional part... it will, by default, round up if the fractional part is 0.5 or higher.As for the modulo operator... as I've stated, I don't do anything XML so am very little help there. Sorry. :(

Share this post


Link to post
Share on other sites

Hi, formatting uses C# formatting styles for floating point numbers (and int/string as well) , so:!nnnn.2f! will round a number to the nearest centesimal fraction.In your example 127.6999999 shows 127.70127.6999999 100 * gives 12769.99999 !5.2f! then shows 12770.00Now, 'div' operator doesn't care about formatting, therefore it just removes the decimals making an integer: 12769 ; !nn.2f! then adds the decimal places in 0, because it is an integer - shows 12769.00Rest of the operations apply to an integer number, so if you divide by 100 127.69 is obtained, AND if you 'div' this value the result is 127 !nn.2f! = 127.00Hope this clarifies the whole thing. And regarding the default radio stack, it is a C gauge as Ed stated, and is probably using a truncation to two decimals:127.6999999 100 * = 12769.99999 near = 12770.00 100 / = 127.70 You might try this last approach and see what happens :-)Tom

Share this post


Link to post
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
Sign in to follow this