September 25, 200916 yr Hi all FS9 XMLI noticed that on some RW HSI that the NAV & ADF bearing needles when tuned and active sway intermittently between up to + - 10 degrees of the bearing. Is it possible to simulate this and how? Paul EGLD
September 26, 200916 yr Commercial Member Hi PaulYes, it is, but you have to do it at the programming stage. I do something similar with pressure gauges because all pumps don't produce the same pressure at the same time (wear, cavitation etc). What I do is to create the gauge and ensure that it is working as expected, then finally make a call to a randomiser function ensuring that the random return is within reasonable limits for the type of display, add the randomiser to the FS output and feed the result to the needle. Another use of this method that I make is that in heavy iron, if you then check time of day you can increase the spread in the randomiser to increase peak load on the generators at mealtimes. If you then get a generator failure at peak times, you really do have to start load-shedding before you start losing the rest of them to overload conditions. //**************************************************************************//Randomiser - where iMax is the upper limit and iActual is what you get//This version only gives a positive output; to get negative as well it will need modifying//**************************************************************************int GetRand(int iMax, int iActual){ long ltime=-1; int stime=-1; ltime=(long)time(NULL); stime=(unsigned)ltime/2; srand(stime); iActual=(int)rand()%iMax; return iActual;} (Yes, I know you said XML and this is C, but you get the picture!).-Dai
September 27, 200916 yr Author Hi PaulYes, it is, but you have to do it at the programming stage. I do something similar with pressure gauges because all pumps don't produce the same pressure at the same time (wear, cavitation etc). What I do is to create the gauge and ensure that it is working as expected, then finally make a call to a randomiser function ensuring that the random return is within reasonable limits for the type of display, add the randomiser to the FS output and feed the result to the needle. Another use of this method that I make is that in heavy iron, if you then check time of day you can increase the spread in the randomiser to increase peak load on the generators at mealtimes. If you then get a generator failure at peak times, you really do have to start load-shedding before you start losing the rest of them to overload conditions.//**************************************************************************//Randomiser - where iMax is the upper limit and iActual is what you get//This version only gives a positive output; to get negative as well it will need modifying//**************************************************************************int GetRand(int iMax, int iActual){ long ltime=-1; int stime=-1; ltime=(long)time(NULL); stime=(unsigned)ltime/2; srand(stime); iActual=(int)rand()%iMax; return iActual;} (Yes, I know you said XML and this is C, but you get the picture!).-Dai Hi DaiYes that will work, I got the needle sway done but the radomiser code in C is way over my head. I need code to generate random numbers between -10 + 10 if possible or I can make it work with 0 to 20 with more code.Thanks Paul EGLD
September 27, 200916 yr Commercial Member I'm unclear as to why you pass iActual as a variable to this function. It makes no sense... especially since you return the value on the stack with the function itself.The call to srand() repeatedly shouldn't be necessary. It should be done once when the gauge loads.I use the PANEL_SERVICE_CONNECT_TO_WINDOW service call in the gauge's main callback:srand( (unsigned)time( NULL ) );To get a min value that's negative... simply subtract half of the max value from the result. //**************************************************************************//Randomiser - where iMax is the upper limit and iActual is what you get//This version only gives a positive output; to get negative as well it will need modifying//**************************************************************************int GetRand(int iMax, bool go_negative = false){ int ret_val; ret_val = (((double) rand() / (double) iMax) * iMax); if (go_negative) { ret_val = ret_val - (iMax/2); } return ret_val;} Ed Wilson Mindstar AviationMy Playland - I69
September 27, 200916 yr Commercial Member Do you know Ed, I've forgotten why I pass in iActual too! I wrote that function so long ago I've never questioned it as it did what I wanted it to do at the time and also since.-Dai
September 28, 200916 yr Moderator Hi DaiYes that will work, I got the needle sway done but the radomiser code in C is way over my head. I need code to generate random numbers between -10 + 10 if possible or I can make it work with 0 to 20 with more code.ThanksHere is one example of an XML pseudo-random number generator:<Macro Name="XMLRandom"> (L:RandomSeed1,number) 0 == (L:RandomSeed2,number) 0 == || if{ (P:Absolute Time,seconds) abs d 2147483563 % (>L:RandomSeed1,number) sqrt d d * * abs 2147483599 % (>L:RandomSeed2,number) } (L:RandomSeed1,number) 40014 * 2147483563 % (>L:RandomSeed1,number) (L:RandomSeed2,number) 40692 * 2147483399 % (>L:RandomSeed2,number) (L:RandomSeed1,number) (L:RandomSeed2,number) - 2147483563 / s1 l1 0 < if{ l1 ++ s1 } l1</Macro><Update> @XMLRandom (>L:RandomNumber,number)</Update> from: http://forums1.avsim.net/index.php?showtop...;hl=random++xml Fr. Bill AOPA Member: 07141481 AARP Member: 3209010556 Avsim Board of Directors | Avsim Forums Moderator
September 28, 200916 yr rand() returns a uniformly distributed random integer between 0 and RAND_MAX. On my 32-bit system RAND_MAX is defined in stdlib.h as ox7fff.To get a double between 0.0 and 1.0 use: (double)(rand()) / RAND_MAX To get a double between 0.0 and iMax use: iMax * (double)(rand()) / RAND_MAX Gerry Howard
September 28, 200916 yr Author Here is one example of an XML pseudo-random number generator:<Macro Name="XMLRandom"> (L:RandomSeed1,number) 0 == (L:RandomSeed2,number) 0 == || if{ (P:Absolute Time,seconds) abs d 2147483563 % (>L:RandomSeed1,number) sqrt d d * * abs 2147483599 % (>L:RandomSeed2,number) } (L:RandomSeed1,number) 40014 * 2147483563 % (>L:RandomSeed1,number) (L:RandomSeed2,number) 40692 * 2147483399 % (>L:RandomSeed2,number) (L:RandomSeed1,number) (L:RandomSeed2,number) - 2147483563 / s1 l1 0 < if{ l1 ++ s1 } l1</Macro><Update> @XMLRandom (>L:RandomNumber,number)</Update> from: http://forums1.avsim.net/index.php?showtop...;hl=random++xml Thanks BillI can work with this code Paul EGLD
Create an account or sign in to comment