Board index FlightGear Development Nasal

Is there interest in a Nasal introduction?

Nasal is the scripting language of FlightGear.

Is there interest in a Nasal introduction?

Postby Thorsten » Wed Jul 28, 2010 7:35 am

I was wondering if there are people who would be interested in a series of short introductionary lessons to Nasal. The target group would be chiefly people who have some experience in modelling aircraft or scenery and have been using xml tags for their needs, but would like to have the freedom to go beyond the pre-defined possibilities (which Nasal offers).

The scope of the introduction would roughly be like

* various options for loading and starting Nasal
* control loops, Nasal control structures
* Nasal access to the property tree
* geospatial computations in Nasal
* simple physics problems in Nasal

Prerequisite knowledge would be a basic understanding of coding (I don't want to explain what a variable is) and elementary physics (I don't want to explain what the force has to do with acceleration). The introduction would not deal with specific problems (I don't want this to become me doing codes for anyone who asks). It would also not deal with Object Orientated Programming (because I don't know much about this).

The way I imagine this to work is that for each topic the participants will get a template code, we will talk about the template and explain how it works, introduce related options and a problem to extend the template to do some task will be given as 'homework', to be discussed later. For example, I could think of placing a model into the scenery and let it fall down by solving the free-fall with friction equations from Nasal and measure the time to impact as a toy problem.

If you're interested, please let me know. If sufficient people are, I'll actually do it (and if it works, I would be sort of hoping that someone else does the same thing for writing shaders or other interesting stuff).
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Is there interest in a Nasal introduction?

Postby i4dnf » Wed Jul 28, 2010 7:56 am

Where were you two months ago when I started poking my IAR80 with nasal code to make it crash :P.. I for one would be interested, as I'm shure the nasal mumbo-jumbo I wrote for that plane would make anyone with some scripting knowledge run away in despair :P.
i4dnf
Retired
 
Posts: 743
Joined: Wed Sep 09, 2009 8:17 am
Location: LRBS
Callsign: YR-I4D
Version: GIT
OS: Gentoo Linux ~amd64

Re: Is there interest in a Nasal introduction?

Postby Hooray » Wed Jul 28, 2010 10:46 am

I am interested .... in contributing. As you may have seen, I actually started something like this in the current newsletter: http://wiki.flightgear.org/index.php/Fl ... or_newbies

The idea was basically the same. I just wasn't sure about the most suitable format, I was thinking of either having a monthly (or even weekly) column in the Nasal forum or simply adding those things to the newsletter, like I did a couple of days ago.

I was actually planning to do this for a quite a while, to help populate the Nasal forum. And to help new users to get started coding in Nasal.

It would also not deal with Object Orientated Programming (because I don't know much about this).

I can handle that part, but there is also a pretty good introduction in the Nasal wiki article.
And I even posted a very basic introduction in the local weather thread, when we were talking about turning some of that code into OOP style: http://www.flightgear.org/forums/viewto ... =15#p70986

OOP is all about creating "things" (i.e. a cloud) with "actions" (transform,draw,update) (or "messages").
Where a class (or hash in Nasal) is the "template" for a "thing" containing a number of member fields.
So the class only describes the "layout" or properties of objects that can be created.

These member fields can be variables (e.g. lat, lon, alt) or functions (setAlt, setPos).
And the actual instance (cloud[n] in the property tree) of such a thing is then called an "object".
Functions that work with instance specific state are called "methods", they may refer to instance specific state using a "self reference" (me) in Nasal, that ensures that access to a field or method is using the right instance specific data.

In OOP, internal state is managed by wrapping everything in a class using accessor functions for modifying and getting internal values.
So internal state would in turn only be modified by an abstract interface: class "methods".

For example, instead of doing something like cloud.lat=10.22; cloud.lon=43.22; you would have a method accepting lat/lon variables: cloud.setPos(lat, lon);

That means that the actual variables containing the values for lat/lon are not exposed or used outside the actual object. This is called encapsulation and provides you with a way to manage state and ensure that internal state is valid at all times, because other code may only use the external interface.

This allows you for example to simply rename a class variable, without having to change any of the code that uses the object, because other code only uses class methods.

Another important thing in OOP is separation of concerns, i.e. you don't want to end up with huge bloated "super classes" that manage all sorts of different state, but instead use different classes where appropriate to split code into abstract "modules" with well defined responsibilities.

So, one of the very first steps to convert procedural code to OOP code would be to group your code into a number of logical "classes" (e.g. cloud, cloud field ).

Classes may be composed of other classes, i.e. a "cloud field" class would in turn contain "cloud" classes.
This is then called "composition".

Another way is inheritance, where a type may inherit properties (fields:variables and methods) from a "parent" class. Imagine it like taking a "template" for the class and then saying "make a new class using this template".

Inheritance has the added advantage of providing a means to customize class behavior without having to modify the actual class, because all member fields can be parametrized.

For example, a "cumulus" cloud class could be derived from the "cloud" class, just by parametrizing it (different cloud model, different texture, different transformations), without touching anything in the actual "cloud" class.

This is basically how OOP may be understood: things are classified according to "is a" or "has a" relationship.

Of course, one may still use objects like conventional variables for passing and returning parameters.


Other things that I'd personally be interested in, would be having introductions for functional programming in Nasal, as well as multi-threaded programming using the threads module. That should help increase its adoption, as well as foster the process of making all Nasal APIs fully thread safe.


I really think improving the existing Nasal documentation is an important step to make it easier for people to contribute by scripting.

The homework/assignment idea is actually interesting, but I am not sure if it's too much work?
Personally, I was really thinking in terms of either having columns or "mini howtos".
I am not sure if I could really help with reviewing assignments and such, while I am pretty confident that mini articles would be useful either way...

For the time being, I have added all suggestions to the wiki: http://wiki.flightgear.org/index.php/Nasal_introduction

There are probably other potential contributors who have done their fair share of Nasal programming, like flug, xiii or AndersG ??
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: Is there interest in a Nasal introduction?

Postby clrCoda » Wed Jul 28, 2010 4:11 pm

Please get around to explaining to everyone, eventually, how nasal can be used to update liveries. Also please get around to explaining how Nasal can be triggered by external conditions, such as in multi-player. Then, please tell everyone how these two concepts can go together so that some outside influence can trigger the nasal livery-updater to change the default livery you have selected for an individual plane that you are flying, or triggered so often and so many times a second as to have an over all effect on sim performance, dragging frame rates down.


Much thanks for this thread, can't wait for the education. :-)
Ray St. Marie
clrCoda
 
Posts: 1225
Joined: Wed Apr 07, 2010 12:04 pm

Re: Is there interest in a Nasal introduction?

Postby Tuxklok » Wed Jul 28, 2010 4:46 pm

clrCoda wrote:Please get around to explaining to everyone, eventually, how nasal can be used to update liveries. Also please get around to explaining how Nasal can be triggered by external conditions, such as in multi-player. Then, please tell everyone how these two concepts can go together so that some outside influence can trigger the nasal livery-updater to change the default livery you have selected for an individual plane that you are flying, or triggered so often and so many times a second as to have an over all effect on sim performance, dragging frame rates down.


Much thanks for this thread, can't wait for the education. :-)

You can have a look at the code for livery updating (mp and not) in DATA/Nasal/aircraft.nas, and the model setup for it in almost any aircraft with livery selection.

In a nutshell: At a certain interval (default 10 seconds, but many aircraft use bigger) the nasal codes checks if the livery has changed, and if so copies the name of the new livery to the multiplayer property for the aircraft. In turn the AI aircraft you see on mp will set it's livery based on this property, so that you will see the same livery that the person has set. If you don't have a livery with that particular name, then it will just fall back to the default one, it does not download any liveries for you. So it is triggered at most every 'interval' seconds, and only if the livery has been changed. An effect on your sim can happen for a few reasons, such as the aircraft having heavy liveries that take a long time to load, many of the same aircraft in question visible using different liveries (sim has to load all of them), person changing the livery often...though the update interval limits this effect on you, so is most apparent when there is a larger number of the aircraft in question and many of them are playing with their liveries at the same time. You'll see the greatest impact when the aircraft has heavy liveries, there is multiple of that aircraft visible, and many/most of them are cycling through there liveries at approximately the same time. Since flightgear does resource loading in the main thread, flightgear will stall while loading models and textures (eg aircraft and liveries), causing stuttering.

cheers!
The Austria Scenery Project - more info
fg-scenery-tools - gitorious | videos
fgcomgui - Open source, cross platform, gui front end for fgcom. more info

More random musings and doings can be found on my personal site. (work in progress)
User avatar
Tuxklok
 
Posts: 1320
Joined: Tue Apr 21, 2009 7:04 pm
Location: Orlando, FL
Callsign: Tuxklok / N1292P
OS: GNU/Linux

Re: Is there interest in a Nasal introduction?

Postby Thorsten » Wed Jul 28, 2010 5:24 pm

The homework/assignment idea is actually interesting, but I am not sure if it's too much work?
Personally, I was really thinking in terms of either having columns or "mini howtos".


At university, we give classes for students. There are all the books, and papers around, in principle anyone could learn on his own (I've actually done that for solid state physics) - and yet, it's not quite the same thing. It doesn't target the same audience, it requires a different level of self-discipline and so on.

I suppose anyone who is able to pick up how things work from resources can work with the Wiki documentation as is and fill in a few gaps with forum questions. But an introduction is a bit different - you know there is a person who has already solved the problem and who will be there to answer in case of problems, and you even know who that person is for starters.

I have no idea if it would work - but I thought that maybe it's worth thinking about.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Is there interest in a Nasal introduction?

Postby Hooray » Thu Jul 29, 2010 4:48 pm

Yes, you are right.
But I still think that having a "class format" depends too much on having "teachers and students".
So the whole thing may fail if either part is missing. That is why I think that standalone documentation, in the form of mini articles and howtos could work better.
I can completely relate to your reasoning, auto-didacting learning requires a certain skill set and motivation.
But I am simply not sure how many people are currently willing to participate in such a "Nasal class room" project, students and mentors I mean.

On the other hand, it might be better to look for potential participants in the aircraft/scenery forums - I mean, anybody who reads the Nasal forum is either already familiar with it, or at least pretty interested in learning more about it.

But maybe there are other people who might be interested in a Nasal tutoring effort, but who don't currently bother following this forum?

Regardless of the format being used, I am convinced that the whole idea would be very worthwhile.
Personally, I just find it easier to write something and add it here to the forum or to the wiki, where it will certainly be "somewhat useful" in the long run.

On the other hand, the format you suggest has a bunch of other obvious advantages, such as getting immediate feedback.

I have added a bunch of other topics to the wiki, that could be covered sooner or later.

I am coming to the conclusion however that it would be better to ask potential students what sort of topics shall be covered in the long run.
I mean, someone who already knows Nasal scripting is maybe not the best person for creating a beginner's introduction.

Especially when it comes terminology like functions, variables, loops, scope/namespace and such.
Most of which will require a certain background, or at least introductory explanations.
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: Is there interest in a Nasal introduction?

Postby Gijs » Wed Aug 11, 2010 12:17 pm

Splendid idea Thorsten! I would love to learn more about Nasal and contribute to the classes where my limited knowledge applies to.
However, I support Hooray in his worries about a class-style teaching. We have tried to set this up for a fligth school before and found out that it is not easy to achieve. The thing is that we have a lot of people around here that can spend free-time at irregular base/length. If I sign in for a virtual class next Saturday at 10:00 GMT for example, there will be a high risk that I won't have the time by then. Better, IMO and my case, would be to have an IRC channel, in which people can popup with questions at any time. Beside that, the wiki should be extended with more documentation to read.

clrCoda wrote:Please get around to explaining to everyone, eventually, how nasal can be used to update liveries.

The good "old" wiki comes in useful: http://wiki.flightgear.org/index.php/Livery_over_MP ;)

Cheers,
Gijs
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: Is there interest in a Nasal introduction?

Postby Thorsten » Wed Aug 11, 2010 5:22 pm

Well, given the fate of this thread, it seems Hooray is right in assuming that mini-howtos and such like would work better - so I'll have a look into what I can contribute to these efforts.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Is there interest in a Nasal introduction?

Postby HHS » Wed Aug 11, 2010 7:04 pm

The idea is great!

We have already a wiki-article about a first simple NASAL-script for an instrument. It helps a lot for the beginning.

So my wish would be that we get much more such nice How-To's. :D
Up, up and away
User avatar
HHS
 
Posts: 3625
Joined: Thu Jul 19, 2007 9:09 am
Version: GIT

Re: Is there interest in a Nasal introduction?

Postby Gijs » Wed Aug 11, 2010 8:09 pm

HHS wrote:So my wish would be that we get much more such nice How-To's. :D

So, if we all add our knowledge (even the tiniest bit of it!), we will be able to fullfill your (and my) wish. Thinking about that, I though I should take a lead:
- Implement copilot announcements
- Calculate V-speeds
Please note that those scripts were written from scratch by myself, and probably could be much better optimised! Feel free to edit the article when you know of any improvements ;)
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: Is there interest in a Nasal introduction?

Postby redneck » Wed Aug 11, 2010 9:26 pm

Nice job guys. Maybe I might learn this stuff some day. :D Just wondering, instead of printing the callouts to the screen, how would I go about making voice callouts? I suppose I would record myself saying "V1", "V2", "rotate", etc. and then somehow reference the WAV files in the script. I'm just not sure how exactly to go about doing that, but I think it would be very nice to have in FG. I know FSX doesn't have anything like that :wink:
Oh, I wanted to add this feature to the 787, with voice callouts if I can get some help, but it looks like your Vspeed calculator only works for JSBSim planes, right? The 787 is YASim. Plus, it would need to be able to do a check for flaps 5, as 10 or 20 would be way too much for the 787. Looks like the code is currently tailored for the 744.
Call Signs: redneck, ATCredn (unspecified freq atc)
FGFSCopilot
FGFSCopilotATCEdition
System Specs
Model: Alienware M15x, OS: Windows 7 Professional 64-bit, RAM: 3 GB, CPU: Intel i3 quad core at 2.4 GHz, GPU: Nvidea GeForce GTX 460M 1.5 GB GDDR5
redneck
 
Posts: 3617
Joined: Mon Feb 02, 2009 3:17 am
Location: Pennsylvania, USA
Version: 240

Re: Is there interest in a Nasal introduction?

Postby Gijs » Wed Aug 11, 2010 9:35 pm

Please wait a couple of more minutes. I'm currently testing a better script provided by AndersG. Will update the wiki when it works.
Voice callouts should be no problem, just set a prperty (eg copilot/v1) to true (instead or beside printing it to the screen) when V1 speed is reached. Then, in your aircraft's sound file, you can add a sound that monitors that property and plays the sound once when it is set to true.
redneck wrote: I know FSX doesn't have anything like that

Maybey not per default, but there are addons available that have ;)

For flaps, you need to set /instrumentation/fmc/to-flap to a value (10 or 20 with the 744 script), like you would enter in the CDU in a RL aircraft.
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: Is there interest in a Nasal introduction?

Postby redneck » Wed Aug 11, 2010 9:47 pm

This stuff seems to be way over my head, actually. I guess I'll have to spend more time with the wiki to learn both XML and nasal. I was hoping I may be able to pick it up in an hour or so :lol:
Call Signs: redneck, ATCredn (unspecified freq atc)
FGFSCopilot
FGFSCopilotATCEdition
System Specs
Model: Alienware M15x, OS: Windows 7 Professional 64-bit, RAM: 3 GB, CPU: Intel i3 quad core at 2.4 GHz, GPU: Nvidea GeForce GTX 460M 1.5 GB GDDR5
redneck
 
Posts: 3617
Joined: Mon Feb 02, 2009 3:17 am
Location: Pennsylvania, USA
Version: 240

Re: Is there interest in a Nasal introduction?

Postby Gijs » Wed Aug 11, 2010 9:48 pm

Redneck, I updated both wiki articles, please have a look. It also explains how to simplify vspeeds calculation, so you don't need to set a takeoff flap setting.
Be prepared to see more changes in the upcoming days ;)
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

Next

Return to Nasal

Who is online

Users browsing this forum: No registered users and 4 guests