Board index FlightGear Development Canvas

On board radar Canvas integration

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.

On board radar Canvas integration

Postby 5H1N0B1 » Mon Feb 03, 2014 10:29 pm

Hi,
Hooray, I followed your road :

Basically, this should get you going quickly:

copy an existing set of files (better TFC* instead of VOR*), but name it "TARGET" instead of TFC: TARGET.symbol, TARGET.lcontroller, TARGET.symbol (RADAR may be a more appropriate name)
you need to change the name to TARGET inside the 3 new TARGET* files (see the top of the new files, where 'TFC' can be seen)
start by opening TARGET.scontroller and replace TFC with TARGET
next, open TARGET.symbol - this contains the draw() and update() callbacks to draw/update a single symbol and animate it accordingly, also replace TFC with TARGET
next, open TARGET.lcontroller - this contains the layer management code, a layer manages a vector of symbols, replace TFC with TARGET
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", and so you will need to add "TARGET" there as well. This is to tell the framework about your newly created layer files.

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
this should give you a TCAS traffic (TFC) symbol using the TARGET handle when you run the dialog

(5H1N0B1 : I'm here)

once that is working, you can customize the symbol by opening the TARGET.symbol file which contains the draw routine - for example by changing the color or using some custom font/label, or just using a SVG file via parsesevg() - see the NDB.draw file for an example on how to display a custom SVG file
at this stage you should have a custom symbol rendered in all the places where MP/AI traffic is located, all driven via the TCAS function.
so the next step is to make the code a bit smarter, especially look at the TFC.lcontroller and TFC.scontroller files
it may even be a good idea to directly start with those, instead of the VOR files ...
once that is working, i.e. 1) you have a custom symbol shown and see all the surrounding MP/AI traffic, you have already successfully created a simple ATC/radar screen!
next, you would replace the data source (which is AI/MP traffic) with your own data source - for that, refer to the TARGET (TFC) files to see how the AI/MP traffic is added
once you have added your own data source, you can change the heuristics accordingly - to handle terrain, radar range etc.
your own objects should ideally be geo.nas Coord objects - that way, the system can directly support your traffic, you only need to derive from geo.Coord to make this happen:



but I got this :
Code: Select all
Nasal runtime error: No such member: searcher
  at /media/Data/FGFS-Git/fg-download-and-compile-fgmeta/install/fgfs/fgdata/Nasal/canvas/map/TARGET.lcontroller, line 40
  called from: /media/Data/FGFS-Git/fg-download-and-compile-fgmeta/install/fgfs/fgdata/Nasal/canvas/MapStructure.nas, line 320
  called from: /media/Data/FGFS-Git/fg-download-and-compile-fgmeta/install/fgfs/fgdata/Nasal/canvas/api.nas, line 477
  called from: __canvas:vor-map, line 329


I tried to look at the code of the "TARGET.lcontroller" but perhaps it's because it's late, but I cannot understand the code...
Any idea ?

Thanks in advance
5H1N0B1
"Each day, with every person you meet, there is something to learn"
5H1N0B1
 
Posts: 217
Joined: Thu Aug 30, 2012 9:36 am
Location: France
Callsign: 5H1N0B1
IRC name: _5H1N0B1
Version: GIT
OS: Ubuntu

Re: On board radar Canvas integration

Postby Hooray » Mon Feb 03, 2014 11:53 pm

first of all, everything must parse correctly during startup, without causing errors - if there are errors even without the dialog being open, there's some syntax issue that needs to be fixed first.

Did you also update MapStructure.nas ?

just some more troubleshooting: is the TFC layer itself working properly ?
Does the TFC (TCAS) layer show up properly once you replace "TARGET" with "TFC" in the vector ?

If not, there's some other problem - such as an outdated fgdata clone, so that you need to pull --rebase fgdata first.

If it it does show up correctly, you have some issues with your modified TFC layer (remember, TARGET is based on TFC).

Once you check out the original TFC.lcontroller file, you will see that the "searcher" member will be set by .new() constructor: https://gitorious.org/fg/fgdata/source/ ... roller#L42

In that case it would be good if we could take a look at your changes/files - preferably, via gitorious - but you can also use some pastebin.

Indeed, you can also just edit the "Canvas Radar" page and post your code there - we're using this as a "sandbox" now, and turning this into a tutorial.
So feel free to move your code there, so that we can have a look and change it.
This may seem weird at first, but Philosopher has a track record of writing 100s of lines of code like that (via the wiki) without ever testing anything :lol:
(which is also why it's helpful to post some screen shots)

Just post your files here: http://wiki.flightgear.org/Canvas_Radar#Design

EDIT: The .searcher member is already added in MapStructure.nas, see: https://gitorious.org/fg/fgdata/source/ ... e.nas#L330
Check your own MapStructure.nas file if it's up-to-date
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: 11968
Joined: Tue Mar 25, 2008 8:40 am

Re: On board radar Canvas integration

Postby Philosopher » Tue Feb 04, 2014 2:39 am

Yeah, I did fix that a few days ago (around when I added TFC.*) - the problem was that the .lcontroller was initialized before the .seacher, but that's been swapped. Now you should see "m.searcher = ...;" right after "var m = { ...};". If you don't, then the file is not latest.
Thanks,
Philosopher
(inactive but lurking occasionally...)
Philosopher
 
Posts: 1590
Joined: Sun Aug 12, 2012 6:29 pm
Location: Stuck in my head...
Callsign: AFTI
Version: Git
OS: Mac OS X 10.7.5

Re: On board radar Canvas integration

Postby Hooray » Tue Feb 04, 2014 3:06 am

note to self: we need to add some API versioning layer at some point, probably in conjuction with TheTom...
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: 11968
Joined: Tue Mar 25, 2008 8:40 am

Re: On board radar Canvas integration

Postby Hooray » Tue Feb 04, 2014 5:13 am

I just tried to do this using the instructions I posted, and we missed a few minor things apparently, but overall the steps were correct - just not exactly complete :D
Image

But this is to be expected, the TFC layer is our newest layer and still needs some work.

Specifically:
  • you also need to provide 2 callbacks needed by the TFC layer, otherwise they will be missing
  • see query_range() and get_position() in navdisplay.mfd - or just provide them in TARGET.lcontroller
  • traffic handling is a bit inconsistent ATM - while both, AI & MP, are supported, it seems that Philosopher tested things only with MP ?
  • for example, the tcas properties are not available for AI traffic, so result in Nasal errors currently (referring to the TFC layer, not the new one based on it)
  • currently, the layer is listener-based to pick up new traffic - which makes sense for the common use-case, because the aircraft will be up and running after booting
  • but this fails if the controller is used in a dialog, i.e. it won't pick up existing traffic apparently, only new traffic - because the added signal will not be fired again
  • tcas_arrows seem to be causing issues when testing with AI - could be related to the other issue, i.e. tcas properties being n/a
  • symbols are not always properly positioned using setGeoPosition() apparently, but this seems to be specific to AI traffic only

Obviously, this also still needs scaling (LOD) - and testing is a bit tedious, because the AI traffic system may take between 3-5 minutes at KSFO until there's sufficient traffic showing up.

Overall, the steps were correct - and this can be made to work, but it still needs some TLC obviously - I only tested this very briefly, the results are encouraging, but it may take a while to develop this fully.

I wouldn't focus too much on the TCAS stuff, because a Radar layer will not necessarily need those.
Otherwise, most issues will go away automatically, once the TFC layer become a bit more mature - i.e. once it supports multiple aircraft and once it can run in multiple dialogs independently.

The XML dialog is based on the snippet I added to the wiki - it contains the mentioned "reload" button for reloading the dialog/code - but that won't help you with changes in MapStructure.nas or any of its layers currently...
If you want me to, I can push this to a branch, so that the two of you can have a look and see if I missed anything obvious, or commit changes directly.

I won't have a lot of time to play with this unfortunately - but you should be able to fix most issues quickly (say, a weekend) - and to animate things, you can look at Gijs' 747-400 altitude-arc and customize it for your radar.

EDIT: ok, just uploaded things to the wiki, so that we can easily provide feedback and change things directly: http://wiki.flightgear.org/Canvas_Radar
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: 11968
Joined: Tue Mar 25, 2008 8:40 am

Re: On board radar Canvas integration

Postby Philosopher » Tue Feb 04, 2014 2:41 pm

traffic handling is a bit inconsistent ATM - while both, AI & MP, are supported, it seems that Philosopher tested things only with MP ?

Actually, kinda the opposite. Anyhow, it's just copy/paste from the original file (by Gijs), so I don't really know much. However, Hyde has also been reporting problems with it, but I don't really have any... :P

Try it with the controller thrown in there, maybe it'll work better.

see query_range() and get_position() in navdisplay.mfd - or just provide them in TARGET.lcontroller

yeah, as I've mentioned before, we really need map controllers that handle this, and just provide access to the "upper-level" controller(s) - so TARGET.lcontroller will end up calling "me.map.controller.query_range()" instead of "me.query_range()", etc. etc. This is not something I want to do ATM, so yeah... If anyone else wants to look into it, it should be fairly easy - it just requires touching a lot of places, but I can provide guidance. The ND will also need a map controller, but it essentially has one. The aircraftpos.controller will need to be updated to use query_range(). And once that's done, we might as well start using query_range() as an actual query_range() for the positioned layers. Oh, and we can remove these big hacks as well.

Or maybe I'll just do it...
Thanks,
Philosopher
(inactive but lurking occasionally...)
Philosopher
 
Posts: 1590
Joined: Sun Aug 12, 2012 6:29 pm
Location: Stuck in my head...
Callsign: AFTI
Version: Git
OS: Mac OS X 10.7.5

Re: On board radar Canvas integration

Postby Hooray » Tue Feb 04, 2014 4:01 pm

Hyde confirmed that he is not seeing any other traffic, I suppose that all the groups are correctly added but have identical positions. This is in line with his report at: http://code.google.com/p/flightgear-bug ... id=1334#c8
And I also saw that when using just the TFC layer in a dialog.
Maybe everybody involved here should specify exactly what traffic they're referring to, i.e. AI or MP - or both being active at the same time ?
None of this would seem really difficult to solve, we just need to fix the TFC layer to work properly in the ND mode, but also in standalone/dialog mode.
Afterwards, the "TARGET" stuff should also work pretty much automatically.
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: 11968
Joined: Tue Mar 25, 2008 8:40 am

Re: On board radar Canvas integration

Postby Gijs » Tue Feb 04, 2014 4:17 pm

With both AI and MP enabled, the TFC layer is completely empty here. It's not displaying anything and the group is completely empty in the property tree...
Airports: EHAM, EHLE, KSFO
Aircraft: 747-400
User avatar
Gijs
Moderator
 
Posts: 9456
Joined: Tue Jul 03, 2007 2:55 pm
Location: Delft, the Netherlands
Callsign: PH-GYS
Version: Git
OS: Windows 10

Re: On board radar Canvas integration

Postby Hooray » Tue Feb 04, 2014 4:37 pm

thanks for clarifying, that matches Hyde's comments - so then we are having a TFC-layer specific problem here, which is not primarily about the TARGET layer which is based on it.
Could you also check how this behaves once you only use AI OR only MP ?
Also, I'd suggest to re-enable some of Philosopher's logging to see if there are any targets added to the vector.
First of all, you should probably use the built-in Map dialog to ensure that there ACTUALLY IS traffic in your vicinity - When I used only AI yesterday, I had to wait ~3-5 minutes.
Obviously, this should be better on MP when going to a crowded place like KSFO.

I'd suggest to add some more logging/print statements to see where things are failing...
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: 11968
Joined: Tue Mar 25, 2008 8:40 am

Re: On board radar Canvas integration

Postby 5H1N0B1 » Tue Feb 04, 2014 5:42 pm

So... Just for mortal guys like me who try to understand :

The TFC controller have a bug/don't work very well and so that's why it's a bit difficult to have something displayed. And one the the origin of this problem is with the range.
Am I right ?

So the TFC controller (who will/have become TARGET controler) is there to have a kind of control on what is displayed.
(Range, aircraft posistion/rotation etc....)
I'm asking, because, the target[] that come from the radar code have already be filtered (Range, azimuth...)

Or perhaps tried to follow you guys but I didn't make it :mrgreen:
5H1N0B1
"Each day, with every person you meet, there is something to learn"
5H1N0B1
 
Posts: 217
Joined: Thu Aug 30, 2012 9:36 am
Location: France
Callsign: 5H1N0B1
IRC name: _5H1N0B1
Version: GIT
OS: Ubuntu

Re: On board radar Canvas integration

Postby Hooray » Tue Feb 04, 2014 5:57 pm

Yeah, the TFC layer is totally new and not very mature - the first time I tested it was yesterday, and apparently our ND early-adopters (the 747 and 777 guys) also didn't spend much time testing. :D
The only problem is my previous suggestion to base your new TARGET layer on the TFC layer - which is normally 100% correct, but I just didn't know that there were still some issues ...
Which is why the TARGET layer now also contains the same "bugs". But these should not be very difficult to fix (hopefully).
Once the TFC layer is fixed, we can start with a fresh set of TARGET layer files, based on the updated TFC files.
Once the TFC layer also works outside the ND (and reliably there!), we can also use it in dialogs like your radar prototyping testbed.

Overall, I would not focus too much on your existing "Target" class/code for now - once the TFC layer is working, you only need to follow the steps I outlined previously, i.e. customizing searchCmd and adding your own in_range* variations - in general, you will want your classes/functions not to have more than ~20-30 lines, about ~15 would ensure that others can more easily help with your code - so once TFC is working properly, we can copy those files and customize them for your needs.

None of this is difficult stuff - most of the code is already there, and it will save you a ton of time and work, regardless of some minor issues we're currently facing.

You are probably confused because the TFC layer is our most sophisticated layer - and because it isn't yet working quite as advertized ...
When I looked at it, I also didn't understand everything there immediately, keep in mind this is not "just" about Nasal or just about Canvas - it's a completely custom-developed framework: MapStructure.
But don't worry: Philosopher is around and can provide a helping lend :D

In the meantime, you could spend some time looking at the simpler layers, such as NDB, DME, VOR etc - to understand how they work, make sure to read the MapStructure article in the wiki 3-5 times and actually look at the code for a simple layer - most things will then become self-explanatory over time.
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: 11968
Joined: Tue Mar 25, 2008 8:40 am

Re: On board radar Canvas integration

Postby Hooray » Tue Feb 04, 2014 6:09 pm

Okay, for starters: I am getting the following errors when using the 777-200 @KSFO with MP being enabled and AI traffic disabled:
Code: Select all
Nasal runtime error: non-objects have no members
  at /home/hooray/sources/fgroot/Nasal/canvas/map/TFC.scontroller, line 9
  called from: /home/hooray/sources/fgroot/Nasal/canvas/map/TFC.symbol, line 23
  called from: /home/hooray/sources/fgroot/Nasal/canvas/MapStructure.nas, line 282
  called from: /home/hooray/sources/fgroot/Nasal/canvas/MapStructure.nas, line 268
  called from: /home/hooray/sources/fgroot/Nasal/canvas/MapStructure.nas, line 135
  called from: /home/hooray/sources/fgroot/Nasal/canvas/MapStructure.nas, line 381
  called from: /home/hooray/sources/fgroot/Nasal/canvas/map/TFC.lcontroller, line 29
  called from: /home/hooray/sources/fgroot/Nasal/globals.nas, line 110



I added the unmodified TFC layer and a VOR layer to the dialog, and it's showing the same problems as reported previously - I suggest that we commit something like this as a test case to a topic branch and then all of us can play with it a little to see what's going on.
Image

To get rid of the AI/MP errors, I just wrapped your helpers in TFC.scontroller:

Code: Select all
# XXX: this is more model-ish than controller-ish

var get_if_valid = func(model,node,default) {
 if (!isa(model, props.Node)) return default;
 return model.getNode(node).getValue();
}

var get_threat_lvl = func(model)  get_if_valid(model: model, node:"tcas/threat-level", default:0);
# FIXME: add units
var get_vspd       = func(model)  get_if_valid(model: model, node:"velocities/vertical-speed-fps", default:0) *60;
# FIXME: this needs to be encapsulated - i.e. to work for other aircraft, not just main aircraft
var get_alt_diff   = func(model)  get_if_valid(model: model, node:"position/altitude-ft", default:0) - (getprop("/position/altitude-ft") or 0);


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: 11968
Joined: Tue Mar 25, 2008 8:40 am

Re: On board radar Canvas integration

Postby 5H1N0B1 » Tue Feb 04, 2014 10:42 pm

Ok.
In the code you updated in the wiki, there is this :
Code: Select all
var dependencies = [];


So this is the way to feed the canvas. What is the object on this array ? Is it a geo.Coord object ?

If yes, what is the best way of doing the stuff :
1) Transform each TARGET object into a geo.Coord
2) Add a geo.Coord variable into the TARGET object itself ?

What about the update of this array ?
The RADAR object will have a loop which UPDATE the targets[], and will update coordonates.

So if I put the target array into -> dependencies , is there a kind of pointer ?

So which one :
1) RADAR ->TARGET ->targets[] -> geo.Coords[]->dependencies[] ?

2) RADAR -> TARGET(with geo.Coords)->targets[]->dependencies[] ?

3) RADAR -> TARGET ->target[] -> intrumentation/radar/targets[] -> geo.Coords -> dependencies[] ?

OR

Do I need another loop in the canvas to update dependencies[] ?

As the objects are moving this is a bit twisty ... or perhaps, I got one train late... :?:
Sorry for all the questions.
5H1N0B1
"Each day, with every person you meet, there is something to learn"
5H1N0B1
 
Posts: 217
Joined: Thu Aug 30, 2012 9:36 am
Location: France
Callsign: 5H1N0B1
IRC name: _5H1N0B1
Version: GIT
OS: Ubuntu

Re: On board radar Canvas integration

Postby Hooray » Tue Feb 04, 2014 10:50 pm

the dependencies vector is just a placeholder for Nasal files that you want to INCLUDE - such as "target.nas" for example, i.e. aircraft-specific things etc - so that you don't need to use copy & paste.

I would just use the "TrafficModel" class for now. But you can prepare your target class to be DERIVED from geo.Coord, you could also add the variable there (doesn't matter) - but that would be more work on the MapStructure side of things than just changing your target.new() constructor to ensure that it's derived from geo.Coord.

It REALLY is MUCH simpler than you think:

You only need to change the parents vector in your target class: http://pastebin.com/QRcgejVZ
Code: Select all
# Target class
        var Target = {
                new : func (c) {
                        var obj = { parents : [Target, geo.Coord.new() ]};


And then use the lat/lon/alt instead of the old fields (remove/comment obj.Alt)

If you prefer adding a Geo.Coord instead to each Target, you would need to teach MapStructure how to deal with such objects, to extract lat/lon/alt - you can refer to the implementation for geo.Cooord objects to see how its done in MapStructure.nas

Actually, I answered most questions already - I suggest to re-read either the thread or the wiki article, it has all the answers that you need, maybe too much info at once ? :D
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: 11968
Joined: Tue Mar 25, 2008 8:40 am

Re: On board radar Canvas integration

Postby 5H1N0B1 » Tue Feb 04, 2014 11:02 pm

Yeeeeep...
It's a lot of info...I surely miss some threw the reading...

-
Code: Select all
var obj = { parents : [Target, geo.Coord.new() ]};

This help a lot. This is how Inheritance is managed here. I understand this.

- "dependencies" is a kind of "include" I get it to now

I'll re read all the things find the others infos...Thanks Dude
5H1N0B1
"Each day, with every person you meet, there is something to learn"
5H1N0B1
 
Posts: 217
Joined: Thu Aug 30, 2012 9:36 am
Location: France
Callsign: 5H1N0B1
IRC name: _5H1N0B1
Version: GIT
OS: Ubuntu

Next

Return to Canvas

Who is online

Users browsing this forum: Applebot [Bot] and 1 guest