Board index FlightGear Development Canvas

Get objects to show up on Map/Radar

Canvas is FlightGear's new fully scriptable 2D drawing system that will allow you to easily create new instruments, HUDs and even GUI dialogs and custom GUI widgets, without having to write C++ code and without having to rebuild FlightGear.

Get objects to show up on Map/Radar

Postby RevHardt » Sat Jun 14, 2014 10:57 am

Can I get objects that I add to the scenery to show up on the map and/or the radar?
Take a look to the sky just before you die; it's the last time you will.
RevHardt
 
Posts: 31
Joined: Tue Jun 10, 2014 3:59 pm
Version: 3.4.0
OS: Win 7 Pro SP1 x64

Re: Get objects to show up on Map/Radar

Postby Hooray » Sat Jun 14, 2014 11:21 am

Hi & welcome !

RevHardt wrote in Sat Jun 14, 2014 10:57 am:Can I get objects that I add to the scenery to show up on the map and/or the radar?

The upcoming FlightGear version (3.2) will contain a canvas-based map dialog, including a modular "plugin" system for creating custom map layers and charts with roughly ~50 lines of code, most of it boilerplate.

This is entirely XML/Nasal based (scripted) - symbols can be pretty much anything, raster or vector images (png or svg), but even animated. Styling can be customized, too.

For more info, I suggest to check out:

http://wiki.flightgear.org/MapStructure ... map_dialog
Image

You can basically create arbitrary layers, even for custom objects/positions:
Image

The same method can be used for creating a "live" radar display:
http://wiki.flightgear.org/Canvas_Radar
Image

But maps and layers can be fairly sophisticated, too - all 100% scripted:
http://wiki.flightgear.org/FlightGear_N ... Map_dialog
Image

As long as you use the MapStructure framework, all layers can be easily used in dialogs AND instruments

Coding-wise, there isn't too much involved these days, all the details are covered in the MapStructure article.
Feel free to get in touch if you'd like to learn more, need a few pointers or examples.
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: Get objects to show up on Map/Radar

Postby RevHardt » Sat Jun 14, 2014 11:47 am

This is brilliant, and exactly what I require. I shall immediately start looking into this.

A few questions, though:
1. I understand this is still experimental, but if I wish to test the Canvas Radar framework with FlightGear 3.0, how should I go about it (dependencies, checking out repositories, or building from source, etc.)?
2. The Canvas Radar wiki mentions that it is being developed "with a focus on the Mirage 2000-5". What exactly does this entail? Will it not work out-of-the-box with other aircraft?
3. Finally, the obligatory: When is v3.2 expected realistically? :D

Thanks a lot - and great work, obviously.
Take a look to the sky just before you die; it's the last time you will.
RevHardt
 
Posts: 31
Joined: Tue Jun 10, 2014 3:59 pm
Version: 3.4.0
OS: Win 7 Pro SP1 x64

Re: Get objects to show up on Map/Radar

Postby Hooray » Sat Jun 14, 2014 11:55 am

1) it would probably be easier to wait for 3.2, otherwise, you'd really need to be familiar with FG stuff and do quite a bit of tinkering. Depending on your platform/OS, you could simply download a "nightly build", or just build from source directly, so that you can easily use the latest version - both of these options should be more future proof than tinkering with FG internals like "back-porting" stuff from 3.2 onto 3.0 (personally, I'd just build from source, to be independent from the release cycle)

2) that just means that it's the m2000-5 developer who's interested in this part of FG, but he's currently busy with other stuff, and we've made quite some progress in a related layer: the traffic/multiplayer layer, which would ideally serve as the foundation for a "radar" layer, see the radar article in the wiki for details. But basically it should be relatively straightforward now to adapt the "TFC" (=traffic) layer in order to come up with a radar layer that takes terrain, radio range etc into account to "clip" (exclude) certain targets, and add artificial ones (i.e. terrain/obstructions) - but all MapStructure layers are aircraft-agnostic

3) roughly 8 weeks, see: http://wiki.flightgear.org/Release_Plan

How you should proceed depends on if you have previously done any coding, or if you are familiar with coding concepts like OOP/MVC.

Even just knowing a bit of JavaScript would be helpful. Adding new layers is not exactly difficult.

Static layers, i.e. layers for statically-positioned objects, are rather simple actually now, and can be copied&pasted within a few minutes, even without any coding (SEARCH/REPLACE will do). Dynamic layers (RADAR/ATC/TRAFFIC) are a bit more involved. Either way, we can provide pointers, code snippets and help. So if you'd like to help with this, just get in touch. We would obviously be interested in helping, because any new MapStructure layer would benefit all of FG, i.e. not be specific to a single dialog or aircraft.

The basic steps for adding new layers are detailed at: http://wiki.flightgear.org/MapStructure ... new_Layers

For starters, I'd play with a very simple layers such as the NDB layer and customize that.
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: Get objects to show up on Map/Radar

Postby RevHardt » Sat Jun 14, 2014 12:14 pm

I'm a fairly proficient programmer, but am new to FG, and thus, its internals. I'm learning about it by tweaking all the XML and Nasal I can find in it :D

For an explicit clarification, would the current Win64 nightly build (v3.0.1) include a Canvas Radar framework capable of showing static objects in a custom layer?
Take a look to the sky just before you die; it's the last time you will.
RevHardt
 
Posts: 31
Joined: Tue Jun 10, 2014 3:59 pm
Version: 3.4.0
OS: Win 7 Pro SP1 x64

Re: Get objects to show up on Map/Radar

Postby Hooray » Sat Jun 14, 2014 12:32 pm

nope, the radar/ATC stuff was still being worked on by the m2000-5 developer and it hasn't been committed.
And in the meantime, we've made more progress with MapStructure.
Thus, personally, I'd start with customizing the new TFC layer to come up with a RADAR layer.
See the MapStructure article for the table with layers, which also has links to each layer/implementation file.

Given your background, I'd probably consider cloning all 3 repos and building from source, that way, you won't be tied to release schedules, and can also easily contribute your changes back to us, so that we can get them committed, to ensure that your work will be part of upcoming FG versions.

Regarding your question in particular: There's several sides to it: Showing a static position/object is trivial, should not take much more than 5-15 minutes, just by looking at existing layers (ANY navaid layer shows STATIC postions!)

But to show scenery objects on a radar AUTOMATICALLY, there's more involved, because the surrounding scenery needs to be explored/scanned and data structures need to be populated/filtered. So far, I've really been thinking in terms of using "meta information", as in position (lat,lon), object, attributes (height, diameter, radar profile, radar echo/signature).

Doing all this automatically is basically impossible unless you are willing to make a lot of simplifications, because we would be guessing all the time (kind of material, kind of echo, height etc).

So there's still some work involved here - the ATC/RADAR work was focused on just airborne targets, for which we have more information available.

Thus, some kind of helper function is needed to regularly build an image of the surroundings.
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: Get objects to show up on Map/Radar

Postby Hooray » Mon Jun 16, 2014 1:09 pm

RevHardt wrote in Fri Apr 10, 2009 6:31 pm:Sorry to chase you down like this. I'm the guy with the noob questions on Canvas Radar and MapStructure, and how to "Get objects to show up on Map/Radar", if you remember. So here's another:

Now that I'm finally done cloning fgdata.bundle, I realize I don't fully understand what you all you implied when you said "probably consider cloning all 3 repos and building from source". There's canvas-hackers/topics/canvas-map-dialog and there's canvas-hackers/topics/canvas-radar, but I can't find the third repo in question... unless you meant the latest fgdata itself?
it would be better to raise the same question in your original thread, my inbox is filling up like crazy due to inquiries like yours, and this one is obviously not just of private interest.

That being said, with all repos, we meant 1) simgear, 2) flightgear, 3) fgdata
I suggest to check out the wiki, the superbuild should be the most straightforward option: http://wiki.flightgear.org/Superbuild

You also need to understand that what you are referring to are BRANCHES not separate REPOSITORIES.

These ALL are FGDATA branches, i.e. based on the base package.
It would be better to spend some time going through the wiki to understand basic terminology, not just git, but also project specific stuff.

Like I said, you'll have to build from source or use a nightly snapshot in order to be able to actually use those fgdata branches.
And like I also said, I would suggest to ignore/disregard those branches anyway: they predate the current state of things, all important work has been merged back into fgdata. Thus, I would simply look at the TFC (=traffic) layer and copy/adapt that one.

The canvas radar article covers all the details that are involved here.
First of all, you'd start with a fresh copy of the TFC layer, i.e. renamed to "ATC" or "RADAR" or "TARGET".
That alone will take 2 minutes, and doesn't involve any programming.
Next, you could adapt this new layer to add some radar-based filtering, or to ensure that scenery objects show up.

It may be easier to directly use a map dialog to also place such models - that way, you can ensure that all the meta info is available for your placed objects.
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: Get objects to show up on Map/Radar

Postby Hooray » Sat Jun 21, 2014 6:35 pm

Hooray wrote in Mon Jun 16, 2014 1:09 pm:Next, you could adapt this new layer to add some radar-based filtering, or to ensure that scenery objects show up.


This basically means to adjust the searchCmd() such that it excludes certain stuff, and only includes objects that match certain heuristics/criteria.
For instance, you could simply change the logic such that only models/traffic objects are added that have a certain altitude (aircraft) and/or elevation/height (objects).
We've covered this in the MapStructure article (look for "searchCmd"), but also discussed this in the original forum thread, and copied the whole thing to the radar article: http://wiki.flightgear.org/Canvas_Radar ... _Filtering

It's mainly a matter of modifying and extending an existing layer, and playing a bit with different ideas. Once you are satisfied, you can also change the appearance of your symbols based on the same heuristics, i.e. to take some kind of "radar profile" into account.
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: Get objects to show up on Map/Radar

Postby RevHardt » Sun Jun 22, 2014 8:01 pm

I wish to create a layer to show the various anti-aircraft models in a previously exported ufo-model-export.xml loaded via command line each time.
I copied NDB.symbol and NDB.lcontroller, and renamed both files and all corresponding strings within to "AA".

The wiki says:
now, add the new files to MapStructure.nas: near the end of MapStructure.nas, in the loading code, there's a vector that contains the names to load, e.g. "VOR", "DME", and "TFC"

The only place I found such a vector was near the top in MapStructure_selfTest, where I added r('AA') to the foreach loop inside the unnamed vector to be iterated.
Printlining after load() in the last foreach in load_MapStructure confirms that AA.lcontroller and AA.symbol are indeed loaded at startup.

once that is done, use the new "TARGET" identifier in the foreach vector in the Nasal section of the dialog seen above and its embedded canvas/nasal/load block

  1. I am not sure I have populated the right vector in MapStructure.nas as it clearly states that it is "to be used for prototyping, performance & stress testing..."
  2. I do not understand what is implied by "the dialog seen above".
  3. How do I pass the lat/long/alt data of the objects in ufo-model-export.xml for use in searchCmd() this layer?
Last edited by RevHardt on Sun Jun 22, 2014 8:10 pm, edited 1 time in total.
Take a look to the sky just before you die; it's the last time you will.
RevHardt
 
Posts: 31
Joined: Tue Jun 10, 2014 3:59 pm
Version: 3.4.0
OS: Win 7 Pro SP1 x64

Re: Get objects to show up on Map/Radar

Postby Hooray » Sun Jun 22, 2014 8:09 pm

sorry, that step is no longer needed - files are now automatically loaded. The function you changed is just a "self-test", but it demonstrates how to actually "use" a new layer. You can also refer to $FG_ROOT/gui/dialogs/map-canvas.xml for another example. I'd suggest to modify that file to use/test your new layer there. You will probably want to default it to visible:1 or add a corresponding checkbox (refer to the other layers/checkboxes as example)

You would then open the Map (Canvas) dialog via the EQUIPMENT menu to see your layer at work.
Using that method, will also allow you to easily reload the dialog via the DEBUG menu.
However, the layer itself cannot currently be reloaded (yet).

Regarding #3: You would probably want to create a new helper/wrapper (data structure like a vector/hash) to which you add your positions (lat/lon) using geo.Coord objects - and then simply use that data structure from your searchCmd method.

In other words, modify the ufo editor to copy such info to a global data structure, i.e. initialized while booting (any Nasal submodule will do), and then traverse this data structure when running your searchCmd. There are other/better options, but this should be simple enough and get you going quickly.

For testing purposes, just make searchCmd() return a vector like [geo.aircraft_position()], which willl return a single position (your current position).

To make this a little more interesting use the .apply_course_distance() to apply offsets to the current position, e.g. to return 12 positions within 10 miles, all offset by a few degrees (in a circle):

http://wiki.flightgear.org/Canvas_Radar ... ry_Objects
Image

Once this works, you can basically refine your searchCmd() method, i.e. by using actual data from the "ufo editor"

PS: It would be great if you could help update/maintain the corresponding wiki article - feel free to add your own feedback/questions, updates and screen shots there - including the advice and code snippets provided here!
Last edited by Hooray on Sun Jun 22, 2014 10:04 pm, edited 4 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: Get objects to show up on Map/Radar

Postby Johan G » Sun Jun 22, 2014 8:21 pm

@RevHardt: You might find this post interesting. ;)
Low-level flying — It's all fun and games till someone looses an engine. (Paraphrased from a YouTube video)
Improving the Dassault Mirage F1 (Wiki, Forum, GitLab. Work in slow progress)
Some YouTube videos
Johan G
Moderator
 
Posts: 6625
Joined: Fri Aug 06, 2010 6:33 pm
Location: Sweden
Callsign: SE-JG
IRC name: Johan_G
Version: 2020.3.4
OS: Windows 10, 64 bit

Re: Get objects to show up on Map/Radar

Postby RevHardt » Sun Jun 22, 2014 8:22 pm

modify the ufo to copy such info to a global data structure


But that won't work if I want to use another aircraft to fly a sortie. The UFO was used only to export the XML file to be loaded every time via command line.

Not sure if it's the right forum, but is there a standard way/idiom for XML parsing in Nasal, so I can just parse ufo-model-export.xml?
Take a look to the sky just before you die; it's the last time you will.
RevHardt
 
Posts: 31
Joined: Tue Jun 10, 2014 3:59 pm
Version: 3.4.0
OS: Win 7 Pro SP1 x64

Re: Get objects to show up on Map/Radar

Postby Hooray » Sun Jun 22, 2014 8:25 pm

Right, but a Nasal submodule will be loaded either way - many ways to accomplish this.
PropertyList XML parsing is accomplished via io.nas: read_properties() - for other XML dialects, there are more low-level methods available too
I'd just focus on making the layer functional for starters, then add a custom SVG/symbol, and then you can change the heuristics according to your needs.
In fact, with a few more changes, you could even use a conventional GUI dialog to place such objects interactively.

BTW: If the export.xml file is already loaded (like you said above), it will already be loaded into the property tree - so there should be no XML parsing involved AFAIK
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: Get objects to show up on Map/Radar

Postby Hooray » Sun Jun 22, 2014 10:50 pm

RevHardt wrote in Sun Jun 22, 2014 8:22 pm:But that won't work if I want to use another aircraft to fly a sortie. The UFO was used only to export the XML file to be loaded every time via command line.


Assuming that you're using this method: http://wiki.flightgear.org/Howto:Place_ ... ar_scenery
... then, you only need to open the XML file to see where those objects end up when loaded into the property tree.
Next, open the property tree browser - and you'll find that you won't have to parse any XML, it will be all there already - probably somewhere under /models
You'll just need to use the props.nas APIs/helpers to get out the relevant lat/lon/altitude etc to populate your searchCmd() vector with geo.Coord objects via geo.Coord.new() accordingly.

Instead of creating/modifying a PUI/XML dialog, you can also use a native Canvas Window by adapting the snippet at: http://wiki.flightgear.org/Canvas_MapSt ... onstration
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: Get objects to show up on Map/Radar

Postby RevHardt » Tue Jun 24, 2014 4:57 pm

For the benefit of anybody who seeks answers to similar questions:

I used the following implementation of searchCmd() in AA.lcontroller to make things work:
Code: Select all
var searchCmd = func
                {
                    var results = [];
                    var loadedModels = props.globals.getNode("models").getChildren();
                   
                    foreach (var model; loadedModels)
                        if (cmp(substr(model.getValue("path"), 0, 10), "Models/AA/") == 0)  # only process models loaded from $FG_ROOT/Models/AA/
                            append(results, geo.Coord.new().set_latlon(model.getValue("latitude-deg"), model.getValue("longitude-deg")));

                    return results;
                };

Learnt the hard way that SVG parsing (for svg_path in AA.symbol) in FG doesn't recognize <circle>, <ellipse>, etc., so I opened my hand-coded SVG in Inkscape and used Path->Simplify (which ostensibly converts shapes to paths) to convert it to a code compatible with FG.

Quoted from http://wiki.flightgear.org/Canvas_Radar#Displaying_Scenery_Objects:
If you are adapting an existing navaid layer (e.g. NDB), you may still want to change your lcontroller file to provide a custom layer.searcher._equals function, and make it inherit from MultiSymbolLayer instead of NavaidSymbolLayer.

  1. Having blindly followed both the suggestions, how does query_type in the .lcontroller new() function work? I see it is also used in NavaidSymbolLayer.make(query) to be supplied to a positioned member function of choice, but commenting out query_type: name; in the .lcontroller new() function (while inheriting from MultiSymbolLayer) shows no ill effects either.
  2. What does this do when added to the .lcontroller new() function?
    Code: Select all
    layer.searcher._equals = func(l, r) 0;
    What if this custom definition is not provided?
  3. Noob question time: Are new() and del() the Nasal equivalent of a mandatory constructor/destructor pair?
Take a look to the sky just before you die; it's the last time you will.
RevHardt
 
Posts: 31
Joined: Tue Jun 10, 2014 3:59 pm
Version: 3.4.0
OS: Win 7 Pro SP1 x64

Next

Return to Canvas

Who is online

Users browsing this forum: No registered users and 2 guests