Board index FlightGear Development Nasal

787 MFD Vertical Profile Nasal (prev. Calculating Elevation)

Nasal is the scripting language of FlightGear.

Re: 787 MFD Vertical Profile Nasal (prev. Calculating Elevat

Postby Hooray » Fri Feb 03, 2012 2:23 pm

That's a floating point issue. Hard to tell without looking at your code.

Where and how exactly does this matter? Where do you depend on incrementing exactly by 0.5 (XML or Nasal)?
You should probably change your logic slightly.
For floating point values, never do equality checks in the form of (x==0.5) - rather, just check if the value is within a certain range: (x<=0.5 and x >=0.49)
Last edited by Hooray on Fri Feb 03, 2012 2:30 pm, edited 2 times in total.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: 787 MFD Vertical Profile Nasal (prev. Calculating Elevat

Postby Thorsten » Fri Feb 03, 2012 2:29 pm

Btw, why did the function return -1 from 25 to 50 nm? When I turn the plane around, those work fine...


It returns (-1) if no terrain is loaded at the position you're probing. I use that as a flag to disregard the point then - returning NIL isn't really a good idea.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: 787 MFD Vertical Profile Nasal (prev. Calculating Elevat

Postby omega95 » Fri Feb 03, 2012 2:38 pm

Image

Code: Select all
setprop("/controls/navigation/vert-profile/nm" ~ me.loopnum, get_elevation((y + yoffset) / 60, (x + xoffset) / 60));


Code: Select all
me.loopnum = me.loopnum + 0.5;


That's how it matters. :|

Is there a code to round the number to the nearest 1 decimal place and then set it as me.loopnum?
Merlion Virtual Airlines - the experience of a flight time...
Get high quality aircraft, airports, video tutorials or development tools from my hangar.
omega95
 
Posts: 1222
Joined: Sat Jul 30, 2011 1:59 am
Location: -unknown-
Callsign: MIA0001, OM-EGA
IRC name: omega95
Version: 2.12 git
OS: Ubuntu 13.04

Re: 787 MFD Vertical Profile Nasal (prev. Calculating Elevat

Postby Hooray » Fri Feb 03, 2012 2:50 pm

umm, are you using "me.loopnum" as an actual counter/index variable in a for loop??
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: 787 MFD Vertical Profile Nasal (prev. Calculating Elevat

Postby omega95 » Fri Feb 03, 2012 2:59 pm

Hooray wrote in Fri Feb 03, 2012 2:50 pm:umm, are you using "me.loopnum" as an actual counter/index variable in a for loop??


Sort of like that, but not a for loop. It's a continuous loop that doesn't stop (sorta like the loops in aircraft systems)

The me.loopnum = me.loopnum + 0.5; is the only line that increments the value.
Merlion Virtual Airlines - the experience of a flight time...
Get high quality aircraft, airports, video tutorials or development tools from my hangar.
omega95
 
Posts: 1222
Joined: Sat Jul 30, 2011 1:59 am
Location: -unknown-
Callsign: MIA0001, OM-EGA
IRC name: omega95
Version: 2.12 git
OS: Ubuntu 13.04

Re: 787 MFD Vertical Profile Nasal (prev. Calculating Elevat

Postby omega95 » Fri Feb 03, 2012 3:14 pm

Can someone tell me why this emission animation doesn't work? And the solution too. :shock:

Code: Select all
   <animation>
      <type>material</type>
      <object-name>elevation49</object-name>

      <emission>
         <red>1</red>
         <green><property>/controls/navigation/vert-profile-rGb/nm49</property></green>
         <blue><property>/controls/navigation/vert-profile-rgB/nm49</property></blue>
      </emission>
   </animation>
Merlion Virtual Airlines - the experience of a flight time...
Get high quality aircraft, airports, video tutorials or development tools from my hangar.
omega95
 
Posts: 1222
Joined: Sat Jul 30, 2011 1:59 am
Location: -unknown-
Callsign: MIA0001, OM-EGA
IRC name: omega95
Version: 2.12 git
OS: Ubuntu 13.04

Re: 787 MFD Vertical Profile Nasal (prev. Calculating Elevat

Postby Hooray » Fri Feb 03, 2012 3:21 pm

Well, it's hard to make a suitable suggestion without looking at all of the code, because I don't know if, how and where loopnum is getting used.

Previously, you were just using "1" here, right? That's the interval between terrain samples, right?

I would suggest not to use a floating point value as the index. Even without changing much of your code, there are simple workarounds - such as simply multiplying loopnum by a factor of 10 and then changing your code to undo this:

Code: Select all
var xoffset = (me.loopnum/10) * math.sin(heading);
var yoffset = (me.loopnum/10) * math.cos(heading);


But the truth is, it would be better to uncouple the indexing and the sampling interval by using an additional variable instead.

So, you could still name your samples 0..99 but do them in 0.5 nm increments instead, without the interval affecting the index.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: 787 MFD Vertical Profile Nasal (prev. Calculating Elevat

Postby omega95 » Fri Feb 03, 2012 3:31 pm

Hooray wrote in Fri Feb 03, 2012 3:21 pm:But the truth is, it would be better to uncouple the indexing and the sampling interval by using an additional variable instead.

So, you could still name your samples 0..99 but do them in 0.5 nm increments instead, without the interval affecting the index.


I didn't understand... Anyway, here' the code :

Code: Select all
var nav = {
   init : func {
        me.UPDATE_INTERVAL = 0.01;
        me.loopid = 0;

   setprop("/controls/navigation/init", 1);
   me.loopnum = 1;

        me.reset();
},
   update : func {

var heading = getprop("orientation/heading-magnetic-deg");
var nav1heading = getprop("/instrumentation/nav/heading-deg");
var nav2heading = getprop("/instrumentation/nav[1]/heading-deg");

var poslat = getprop("/position/latitude-deg");
var poslon = getprop("/position/longitude-deg");

# Current WP Deflection and Distance Calculation

if (getprop("/autopilot/route-manager/route/num") != 0) {

var currentwpbrg = getprop("/instrumentation/gps/wp/leg-mag-course-deg");

var currentwpdefl = Deflection(currentwpbrg, 55);
setprop("/controls/navigation/wp1-defl", currentwpdefl);

var currentwpdistnm = getprop("/instrumentation/gps/wp/leg-distance-nm");
setprop("/controls/navigation/wp1-dist", currentwpdistnm * 1852);

if ((currentwpdistnm * 1852) < 55600) {

if (getprop("/autopilot/route-manager/active") == 1) {
setprop("/controls/navigation/show-active-wp", 1);
setprop("/controls/navigation/show-inactive-wp", 0);
} else {
setprop("/controls/navigation/show-active-wp", 0);
setprop("/controls/navigation/show-inactive-wp", 1);
}

setprop("/controls/navigation/show-wp-pointer", 0);

} else {
setprop("/controls/navigation/show-active-wp", 0);
setprop("/controls/navigation/show-inactive-wp", 0);
setprop("/controls/navigation/show-wp-pointer", 1);
}

} else {
setprop("/controls/navigation/show-active-wp", 0);
setprop("/controls/navigation/show-inactive-wp", 0);
}

# Set Heading Deflections

setprop("/controls/navigation/nav1-defl", Deflection(nav1heading,55));
setprop("/controls/navigation/nav2-defl", Deflection(nav2heading,55));

setprop("/controls/navigation/heading-bug", Deflection(getprop("/autopilot/settings/heading-bug-deg"), 55));

# Calculate Descent glideslope

var verticalspeedfps = getprop("/velocities/vertical-speed-fps");
var groundspeedfps = getprop("/velocities/groundspeed-kt") * 1.68780986;

var indaltitude = getprop("instrumentation/altimeter/indicated-altitude-ft");

var slope = (57.2957795 * math.atan2(groundspeedfps, 0 - verticalspeedfps)) - 90;
setprop("/controls/navigation/descent-slope", slope);

var linelength = 0;

var convfactor = 1500; # Testing this value

var xavail = 50; # The box shows elevations upto 50 nm

# I'll have to do some weird calculations to keep the descent slope inside the vertical profile box

# Climbing

if (slope > 0)
{

var yavail = 40000 - indaltitude; # yavail is in feet

} else { # Descending

var yavail = indaltitude;

}

if (yavail < math.abs(convfactor * 50 * (math.sin(slope / 57.2957795) / math.cos(slope / 57.2957795)))) { # The end of the line does not go on till the end of teh space given.

linelength = (yavail / convfactor) / math.sin(slope / 57.2957795);

} else { # Here, it does

linelength = 50 / math.cos(slope / 57.2957795);

}

setprop("/controls/navigation/descent-line-length", math.abs(linelength));

# Calculate vertical Profile

var currentwp = getprop("/autpilot/route-manager/current-wp");
var numberofwps = getprop("/autopilot/route-manager/route/num");



# Calculate Latitude and Longitude for 50 points in front of you.

var x = poslon * 60;
var y = poslat * 60;

var xoffset = me.loopnum * math.sin(heading);
var yoffset = me.loopnum * math.cos(heading);

# Calculate elevations for the next 50 nautical miles (only 1 mile every frame)

setprop("/controls/navigation/vert-profile/nm" ~ me.loopnum, get_elevation((y + yoffset) / 60, (x + xoffset) / 60));

var altdiff = indaltitude - get_elevation((y + yoffset) / 60, (x + xoffset) / 60);

if (altdiff < 1000) {
var dangerg = 0;
var dangerb = 0;
} elsif (altdiff < 2000) {
var dangerg = 0.5;
var dangerb = 0;
} elsif (altdiff < 3000) {
var dangerg = 1;
var dangerb = 0;
} else {
var dangerg = 1;
var dangerb = 1;
}

if (getprop("/autopilot/route-manager/airborne") == 0) {
var dangerg = 1;
var dangerb = 1;
}

setprop("/controls/navigation/vert-profile-rGb/nm" ~ me.loopnum, dangerg);
setprop("/controls/navigation/vert-profile-rgB/nm" ~ me.loopnum, dangerb);

# Loop Number Add and Reset

me.loopnum = me.loopnum + 0.5;

if (me.loopnum == 50.5) {
me.loopnum = 1; }

},
    reset : func {
        me.loopid += 1;
        me._loop_(me.loopid);
    },
    _loop_ : func(id) {
        id == me.loopid or return;
        me.update();
        settimer(func { me._loop_(id); }, me.UPDATE_INTERVAL);
    }

};

var DegToRad = func(deg) {
var rad = deg * 0.0174532925;
return rad;
}

var RadToDeg = func(rad) {
var deg = rad * 57.2957795;
return deg;
}

var Deflection = func(bug, limit) {
  var heading = getprop("orientation/heading-magnetic-deg");
  var bugDeg = 0;

  while (bug < 0)
   {
   bug += 360;
   }
  while (bug > 360)
   {
   bug -= 360;
   }
  if (bug < limit)
   {
   bug += 360;
   }
  if (heading < limit)
   {
   heading += 360;
   }
  # bug is adjusted normally
  if (math.abs(heading - bug) < limit)
   {
   bugDeg = heading - bug;
   }
  elsif (heading - bug < 0)
   {
   # bug is on the far right
   if (math.abs(heading - bug + 360 >= 180))
    {
    bugDeg = -limit;
    }
   # bug is on the far left
   elsif (math.abs(heading - bug + 360 < 180))
    {
    bugDeg = limit;
    }
   }
  else
   {
   # bug is on the far right
   if (math.abs(heading - bug >= 180))
    {
    bugDeg = -limit;
    }
   # bug is on the far left
   elsif (math.abs(heading - bug < 180))
    {
    bugDeg = limit;
    }
   }

  return bugDeg;
}

# Function to get Elevation at latitude and longitude

var get_elevation = func (lat, lon) {

var info = geodinfo(lat, lon);
   if (info != nil) {var elevation = info[0] * 3.2808399;}
   else {var elevation = -1.0; }

return elevation;
}


It's incomplete but should still be functional for what I have so far.

And what about changing the color according to a property?
Merlion Virtual Airlines - the experience of a flight time...
Get high quality aircraft, airports, video tutorials or development tools from my hangar.
omega95
 
Posts: 1222
Joined: Sat Jul 30, 2011 1:59 am
Location: -unknown-
Callsign: MIA0001, OM-EGA
IRC name: omega95
Version: 2.12 git
OS: Ubuntu 13.04

Re: 787 MFD Vertical Profile Nasal (prev. Calculating Elevat

Postby omega95 » Fri Feb 03, 2012 5:35 pm

I completed the VNAV Markers :D

Image

Image
Merlion Virtual Airlines - the experience of a flight time...
Get high quality aircraft, airports, video tutorials or development tools from my hangar.
omega95
 
Posts: 1222
Joined: Sat Jul 30, 2011 1:59 am
Location: -unknown-
Callsign: MIA0001, OM-EGA
IRC name: omega95
Version: 2.12 git
OS: Ubuntu 13.04

Re: 787 MFD Vertical Profile Nasal (prev. Calculating Elevat

Postby Gijs » Fri Feb 03, 2012 5:37 pm

You're developing this thing at an amazing speed! :shock:
Airports: EHAM, EHLE, KSFO
Aircraft: 747-400
User avatar
Gijs
Moderator
 
Posts: 9544
Joined: Tue Jul 03, 2007 3:55 pm
Location: Delft, the Netherlands
Callsign: PH-GYS
Version: Git
OS: Windows 10

Re: 787 MFD Vertical Profile Nasal (prev. Calculating Elevat

Postby omega95 » Fri Feb 03, 2012 5:55 pm

NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO! Hooray just sent me a modified version on the file (older) and I accidentally replaced mine (the one with VNAV markers) with thaT!!! Now, I have to write the code for VNAVs all over again. :cry:
Merlion Virtual Airlines - the experience of a flight time...
Get high quality aircraft, airports, video tutorials or development tools from my hangar.
omega95
 
Posts: 1222
Joined: Sat Jul 30, 2011 1:59 am
Location: -unknown-
Callsign: MIA0001, OM-EGA
IRC name: omega95
Version: 2.12 git
OS: Ubuntu 13.04

Re: 787 MFD Vertical Profile Nasal (prev. Calculating Elevat

Postby Hooray » Fri Feb 03, 2012 6:10 pm

I am sorry, like I said already via PM: You should be using git to prevent such things from happening. You may want to check if your text editor has created any backups automatically, or maybe just using your editors UNDO function (CTRL + Z usually). But that will only work if you didn't close the editor already.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: 787 MFD Vertical Profile Nasal (prev. Calculating Elevat

Postby Thorsten » Fri Feb 03, 2012 6:28 pm

The problem is a bit that it doesn' really work so well under IFR conditions when you need it most, because if you have 3 km visibility, there's almost no terrain loaded to be probed... except when you use the terrain haze shader - that'd allow you to have large aloft visibility (and load enough terrain) and yet have low ground visibility 8)

Thinking about wxradar, it occurred to me that it doesn't seem too smart to assemble the info from the add-cloud calls. At this point, it's cumbersome and you have no information about the radar echo of the clouds. Rather, the mid-level cloud adding calls (create_8_8_stratus() and company) could write coordinates, extension and reflectivity of the created clouds into the tree, from which any wxradar code could generate a suitably fuzzy image to display. At that point, you'd deal with less than 100 distinct objects, and you can easily fit in the reflectivity because you know what cloud in what circumstances you are currently creating. If anyone wants to work on this, let me know and we can specify an interface. It's comparatively easily done from my end.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: 787 MFD Vertical Profile Nasal (prev. Calculating Elevat

Postby Hooray » Fri Feb 03, 2012 6:36 pm

Yes, I also thought about that, it would definitely be the more appropriate place (more high level, more info available)- but on the other hand, that would get us back to LW writing lots of stuff into the property tree, even though the idea was to reduce excessive use of the property tree.
I don't know how "Global Weather" is dealing with this. While it is technically possible to come up with an interface in scripting space that is used by core code, that would probably feel "hackish" to any sane C++ developer. So using the property tree might be the best compromise actually.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: 787 MFD Vertical Profile Nasal (prev. Calculating Elevat

Postby Thorsten » Fri Feb 03, 2012 7:03 pm

The problem doesn't really exist in global weather since global weather always fills cloud layers with homogeneous density of clouds - there are no local structures which would show on a wxradar in a meaningful way. In global weather, you can't ever see a layer edge - either visually or in wxradar.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

PreviousNext

Return to Nasal

Who is online

Users browsing this forum: No registered users and 4 guests