Board index FlightGear Development

[closed] Flightgear plotter updated.

FlightGear is opensource, so you can be the developer. In the need for help on anything? We are here to help you.
Forum rules
Core development is discussed on the official FlightGear-Devel development mailing list.

Bugs can be reported in the bug tracker.

[closed] Flightgear plotter updated.

Postby kuifje09 » Fri May 17, 2013 5:26 pm

There is a project started ( little one ) creating a plotter program for use with creating or tuning the autopilot in flightgear.

I just made a setup an build one already useable. It can be found at sourceforge
https://sourceforge.net/projects/fgplot/?source=navbar

Maby some of you will like it. But, currently only for linux, using Xlib and Motif.

Have a look at the Readme and the provided picture.
Last edited by kuifje09 on Sat Jun 15, 2013 8:42 pm, edited 2 times in total.
kuifje09
 
Posts: 579
Joined: Tue May 17, 2011 8:51 pm

Re: Flightgear plotter

Postby Hooray » Fri May 17, 2013 6:44 pm

That's definitely interesting, but I would suggest to really consider using FlightGear itself - so that your work is not limited to a particular platform (Xlib/Motif), and all users can directly use it, you can accomplish that by using Nasal scripting and the Canvas 2D drawing system in FlightGear, people with programming experience can get started really quickly using a number of Nasal/Canvas tutorials.

Subject: static piston engine test
Hooray wrote: That said, the new canvas system does provide an option to create graphs at runtime
And it would also be possible to load another graph image as an overlay.

Obviously, gnuplot offers much more flexibility than this - but it may still be interesting to come up with a compromise that's using FG as the "GUI".
The other option would be invoking gnuplot via FG and using JSBSim in standalone mode.
FlightGear's I/O protocol is already able to write to special files (called pipes), these could be used to connect FG->JSBSIM->GNUPLOT.
This would be mostly about creating/customizing a bunch of XML files (and obviously doing a fair amount of reading)

Subject: Using a canvas map in the GUI
Hooray wrote in Wed Sep 19, 2012 12:56 pm:
zakalawe wrote in Wed Sep 19, 2012 12:34 pm:There's also a long-requested feature to use the replay-code to extract the historical aircraft position, which would be another kind of data to show.


That's definitely a good idea, accessing the replay/flight recorder buffers via a dedicated Nasal/property tree interface would be pretty cool, not just for showing historical path data, but also for computing a flight profile, or even for doing a full flight evaluation - which could also be done via Nasal/Canvas then, we just need Nasal hooks (i.e. ghosts) to access the replay/flight recorder subsystem and get data from it.

I've been talking to ThorstenB about exposing the system to Nasal a while ago, and when Tom and I played around with graph plotting, we also figured that it would be kinda cool to access such info from Nasal.

The combination of these features (replay/flight recorder access + Nasal + Canvas), would also make it possible to create a full flight instructor console. The original graph-plotting experiments were pretty encouraging:
Image
And 2D plotting is another long-standing feature request, originally brought up by Curt: http://www.mail-archive.com/flightgear- ... 03651.html

curt wrote:But, I was just thinking today that it might be cool to have a built
in grapher for simple / quick graphing needs.

With the property system it would be trivial to pick an arbitrary
property from the property tree and graph it over time -- superimposed
on top of everything else.


With the Canvas, it has now become trivial to create such graphs, but we still need to have Nasal-space access to the corresponding subsystems and data, i.e. the replay/flight recorder system.


Update: Zakalawe has just committed to implement the required hooks for this as part of issue 763: https://gitorious.org/fg/flightgear/com ... dfc1e1cb43
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: 11376
Joined: Tue Mar 25, 2008 8:40 am

Re: Flightgear plotter

Postby kuifje09 » Sun May 19, 2013 2:42 pm

Hi Hooray, thanks for the response.
I know what you mean, but nasal is again a new language for me. I used it in the autopilot "files" which I tried to modify.
Would indeed be nice to have such plotter inside flightgear. But would it be fast enough to not slowdown flightgear?
At the other hand, I always be very surprised about the speed of flightgear. It does a lot of calculation and creating graphs on the screen.
Then I see my fgplot does such little work and consumes the half of the time like flightgear.

But, I already did some updates and posted it into sourceforge.
Removed some bug and added some features.
kuifje09
 
Posts: 579
Joined: Tue May 17, 2011 8:51 pm

Re: Flightgear plotter updated.

Postby Hooray » Sun May 19, 2013 4:24 pm

I know what you mean, but nasal is again a new language for me.

If you already know another language, it is really easy to pick up Nasal quickly.

kuifje09 wrote in Sun May 19, 2013 2:42 pm:Would indeed be nice to have such plotter inside flightgear. But would it be fast enough to not slowdown flightgear?

Definitely, the Canvas is going to be used in various parts in FlightGear: instruments, MFDs, HUDs, GUIs, scenery etc.
So it *needs* to be fast enough, if it isn't fast enough - it will be optimized to make it faster.
But drawing simple graphs is not really heavy performance-wise. So you should be just fine.

Using the canvas tutorials, creating a simple x/y plotting widget should not take much longer than about 45 minutes, even if you are new to Nasal.

But, I already did some updates and posted it into sourceforge.

Feel free to add your project to the upcoming newsletter (see my sig).
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: 11376
Joined: Tue Mar 25, 2008 8:40 am

Re: Flightgear plotter updated.

Postby kuifje09 » Mon May 20, 2013 3:50 pm

Thanks Hooray, I will have a look at howto plot in nasal. I already did some calculations, which where not difficult.
(Just had q quick look at the canvas-module. Its fairly new but I see a possibility for the fgplot ...)
Last edited by kuifje09 on Mon May 20, 2013 4:07 pm, edited 1 time in total.
kuifje09
 
Posts: 579
Joined: Tue May 17, 2011 8:51 pm

Re: Flightgear plotter updated.

Postby Hooray » Mon May 20, 2013 3:54 pm

Nasal/Canvas use OpenVG paths to do plotting - TheTom may still have some sample code around to get you started more quickly.

You will probably want to add a new Nasal submodule (=folder) to $FG_ROOT/Nasal - for example, something like $FG_ROOT/Nasal/fgplot/fgplot.nas
For details, please see: http://wiki.flightgear.org/Creating_new ... ub_modules

Then you can start adapting the canvas demo code. Having a simple property plotter in FG is a long-standing idea and feature request: http://www.mail-archive.com/flightgear- ... 03651.html
With Tom's recent work, you can even add a full plotting GUI widget - that responds to GUI events.
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: 11376
Joined: Tue Mar 25, 2008 8:40 am

Re: Flightgear plotter updated.

Postby kuifje09 » Mon May 20, 2013 4:48 pm

I just uploaded my latest 03b version. http://sourceforge.net/projects/fgplot/?source=navbar
kuifje09
 
Posts: 579
Joined: Tue May 17, 2011 8:51 pm

Re: Flightgear plotter updated.

Postby Hooray » Mon May 20, 2013 5:06 pm

I tried to run fgplot, the binary has missing dependencies here - and building from source also does not succeed. The problem is your makefile, which seems to lack a configure script to find the relevant libs/headers on different Linux distros - so that the makefile must be edited and fixed manually.

If you want to continue with your fgplot code, it would probably be a good idea to stop using motif/xlib and instead use a cross-platform library like Qt or wxWidgets, including a multi-platform build system like qmake or cmake, to ensure that people can actually build/run it.

That said, looking at your code in fgplot.c it should be really easy for you to pick up Nasal, which is much easier to learn than C. In fact, I'd guess that porting fgplot in its current form to use a cross platform library and build system, would be more work than re-implementing fgplot in FlightGear using Nasal/Canvas, it would probably feel to you like rapid prototyping in comparison.
Given that you have already experience implementing fgplot, doing the same thing directly in FlightGear should get you going pretty quickly.

Keep in mind, that you also won't have to create a pipe, but could directly access the property tree via getprop/setprop.
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: 11376
Joined: Tue Mar 25, 2008 8:40 am

Re: Flightgear plotter updated.

Postby TheTom » Mon May 20, 2013 7:50 pm

Hooray wrote in Mon May 20, 2013 3:54 pm:Nasal/Canvas use OpenVG paths to do plotting - TheTom may still have some sample code around to get you started more quickly.

I can't find the sample code for now, but it was very simple. Basically calling Path.lineTo(x,y) for each data point. For modifying existing plots either the according 'coord' nodes in the property tree can be modified or just start again after removing everything from a path with Path.reset().
TheTom
 
Posts: 321
Joined: Sun Oct 09, 2011 10:20 am

Re: Flightgear plotter updated.

Postby kuifje09 » Tue May 21, 2013 2:26 pm

Hi Hooray, sorry to hear you had trouble to get it to work.
You need the x11 developers libs and the motif developers libs for your platform. ( and the runtime too )
libX11(-dev) libMotif(-dev)
Then also G++ and the libs. In fact a whole developers toolset.
I have tried to build a static version, but that seems to be impossible. I think it would become very big indeed then.
It would need all the attributes to build all parts of the program in one file....
If someone can point me to how create a configer file, feel free to advice me. I know that would be very great to add to the file-set.

( when running the program it may complain about which libs it misses ? )

Also I was not just sitting and posted the last version ( 0.9.b ) for the moment. It is rather fine now I think but a few minor details.

b.t.w. I think putting an executable in the tar is not the best idea, most people don't trust that kind of program's.
which can be considred as valid. But not all people know how to handle source.
Besides, you run usually into dependency problems. But that is the same with source only programs.

Then, This was besides a little help for a few who like to play with the autopilots, some learning project for me.
Now I have some time to spent on see if I can manage a same tool in nasal with the "canvas tools."
kuifje09
 
Posts: 579
Joined: Tue May 17, 2011 8:51 pm

Re: Flightgear plotter updated.

Postby Hooray » Tue May 21, 2013 4:06 pm

I have meanwhile succeeded building fgplot and running it - but I agree that this requires currently lots of manual work, which is unfortunate for people who are not developers, and who primarily want to use fgplot to help with AP development.

So I think it is great to hear that you are considering a more native FlightGear/Nasal approach now, because that will make fgplot available to all FlightGear users, without having to build stuff from source.

You should be able to get started quickly by adapting Tom's "Canvas Window" demo code (see the canvas-gui-demo branch) - which is to be found in menubar.xml for now. You will probably want to copy it and move it to a dedicated file like $FG_ROOT/Nasal/fgplot/fgplot.nas and start adapting it to add plotting support:

http://wiki.flightgear.org/Howto:Canvas ... submodules
Code: Select all
var module_name = "fgplot"; # should be saved in $FG_ROOT/Nasal/test/test.nas

var setup = func( root ) {

var text = root.createChild("text")
 .setText("Hello world from "~ module_name~" !")
 .setTranslation(10, 30)
 .setAlignment("left-top")
 .setFontSize(14)
 .setFont("LiberationFonts/LiberationSans-Regular.ttf")
 .set("max-width", 380)
 .setColor(0,0,0);

var graph = root.createChild("group");

var x_axis = graph.createChild("path", "x-axis")
          .moveTo(10, 150)
          .lineTo(380, 150)
          .setColor(1,0,0)
          .setStrokeLineWidth(3);

var y_axis = graph.createChild("path", "y-axis")
                    .moveTo(10, 30)
                    .lineTo(10, 250)
                    .setColor(1,0,0)
                    .setStrokeLineWidth(3);

var plot = graph.createChild("path", "data")
      .setStrokeLineWidth(2)
      .setColor(0,0,1)
      .moveTo(10,150); # origin

   var samples = [       # absolute coordinates
            [50, 150], [100,140], [200,110], [270, 55]
         ];

foreach(var set; samples)
   plot.lineTo( set[0], set[1] );

}

var init = func() {
                removelistener( listener_id );
      var dlg = canvas.Window.new([400,300]);
      var my_canvas = dlg.createCanvas()
                         .setColorBackground(0,0,0,0);
      var root = my_canvas.createGroup();
      var title_bar = root.createChild("group");
      title_bar.addEventListener("drag", func(e) { dlg.move(e.deltaX, e.deltaY); });
      var x = 0;
      var y = 0;
      var rx = 8;
      var ry = 8;
      var w = 400;
      var h = 20;
      title_bar.createChild("path")
          .moveTo(x + w - rx, y)
          .arcSmallCWTo(rx, ry, 0, x + w, y + ry)
          .vertTo(y + h)
          .horizTo(x)
          .vertTo(y + ry)
          .arcSmallCWTo(rx, ry, 0, x + rx, y)
          .close()
          .setColorFill(0.25,0.24,0.22)
          .setStrokeLineWidth(0);
      y = 20;
      h = 280;
      root.createChild("path")
          .moveTo(x + w, y)
          .vertTo(y + h)
          .horizTo(x)
          .vertTo(y)
          .setColorFill(1,1,1)
          .setColor(0,0,0);
      x = 8;
      y = 5;
      w = 10;
      h = 10;
      title_bar.createChild("path", "icon-close")
          .moveTo(x, y)
          .lineTo(x + w, y + h)
          .moveTo(x + w, y)
          .lineTo(x, y + h)
          .setColor(1,0,0)
          .setStrokeLineWidth(3)
          .addEventListener("click", func dlg.del());
      title_bar.createChild("text", "dialog-caption")
          .setText( module_name )
          .setTranslation(x + w + 8, 4)
          .setAlignment("left-top")
          .setFontSize(14)
          .setFont("LiberationFonts/LiberationSans-Bold.ttf")
          .setColor(1,1,1);
      setup( root ); # pass our root canvas to the setup routine (could be anything, even the whole env using closure() )
}
var listener_id = _setlistener("/nasal/"~module_name~"/loaded", init );


Note that it is really easy to change the style of the graph (color, stroke, fill etc) just by using the property tree. You could probably even add the property browser widget to the fgplot window, so that people can select properties to be plotted. So there are tons of options, just by looking at existing code.

Please let us know if you need any help regarding Nasal/Canvas, or just use the Canvas forum to post any follow-ups: viewforum.php?f=71
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: 11376
Joined: Tue Mar 25, 2008 8:40 am

Re: Flightgear plotter updated.

Postby kuifje09 » Thu May 23, 2013 2:30 pm

Okay, I have made a little start with the testnas as above.
But I have forgotten a lot I think. it has been some time ago I did
some work in nas, but for some reason I cannot find what is wrong.
And handling a new created window is all new for me.

First, The created window should be a floating window, or I should say,
not conneted or projected on anything else the just the flightgear screen.

Maybe you can push me a bit in the right direction.

I am sure when I can create a floating window, I can fix the rest.

This works in the provided tests but is "fitted" in the grey frame.
canvas-demo.nas:
Code: Select all
var m = { parents: [canvas_demo] };
canvas-test.nas
    # create a new canvas...
    m.canvas = canvas.new({
      "name": "PFD-Test",
      "size": [1024, 1024],
      "view": [768, 1024],
      "mipmapping": 1
    });



But this does not :
fgplot.nas :

Code: Select all
 var dlg = canvas.Window.new([400,300]);


gives this error:
Nasal runtime error: No such member: Window
at /usr/share/games/flightgear/Nasal/fgplot/fgplot.nas, line 45

This is my flightgear version:
FlightGear version: 2.10.0
SimGear version: 2.10.0
PLIB version: 185

Evenmore flabberguested. I added a menuitem to the c172p-menu.xml
I can see it is added, but text is not visable, although the function is working. I just copied an item above. Show/Hide yoke.
I only gave it my own name my-name . An exact copy does work fine.
Maybe I did not sleep wel ? or forgot almost anything ?
kuifje09
 
Posts: 579
Joined: Tue May 17, 2011 8:51 pm

Re: Flightgear plotter updated.

Postby Hooray » Thu May 23, 2013 3:48 pm

You didn't post all of your code, does the example I provided work for you ?
I am asking because you seem to be using a sub module without using a listener to initialize it - please test the example I provided first, and then start adapting it.

gives this error:
Nasal runtime error: No such member: Window
at /usr/share/games/flightgear/Nasal/fgplot/fgplot.nas, line 45


Do you get this error when running the unmodified demo ?
See: http://wiki.flightgear.org/Howto:Canvas ... submodules
And note how the code is ONLY invoked after the sub module has been loaded:
Code: Select all
var listener_id = _setlistener("/nasal/"~module_name~"/loaded", init );


PS: I suggest to move the discussion over to the canvas sub forum.
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: 11376
Joined: Tue Mar 25, 2008 8:40 am

Re: Flightgear plotter updated.

Postby jam007 » Thu May 23, 2013 4:30 pm

It might be some parsing problem. If the code doesn't parse you get this error if you then calls the function/method from "outside". I know this from experience :wink:
jam007
 
Posts: 477
Joined: Sun Dec 16, 2012 10:04 am
Location: Uppsala, Sweden
Version: 2017.3.1
OS: Ubuntu 16.04

Re: Flightgear plotter updated.

Postby Philosopher » Thu May 23, 2013 4:35 pm

@jam: I believe the canvas.Window object is in the core FGData and is thus Tom's code, so there for sure wouldn't be a parse error ;).
@kuifje: I believe Hooray is right here: check your listeners!
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

Next

Return to Development

Who is online

Users browsing this forum: No registered users and 1 guest