Electrical systems... xml or nasal?

05 Aug 2021 10:49 #50852 by ScottBouch
Replied by ScottBouch on topic Electrical systems... xml or nasal?

Let me give you a short introduction to the autopilot system and how I use it for sound design using interpolation tables.


Geed - thank you so much for taking the time to provide this tutorial, it is much appreciated.

I have a lot to learn here, but this example will be of great use.

Thanks again, Scott.

Please Log in to join the conversation.

05 Aug 2021 10:52 #50853 by ScottBouch
Replied by ScottBouch on topic Electrical systems... xml or nasal?
The interpolation tables shown here are also perfect for engine modelling.

Thanks for sharing maths, and interpolation, but I have one further question though, is it possible to carry out logic (and, or, if, etc..) in an AP config?
And can you build and call functions as you would in other scripting languages?

Please Log in to join the conversation.

05 Aug 2021 10:59 #50854 by timi

Please Log in to join the conversation.

05 Aug 2021 11:04 #50855 by ScottBouch

Please Log in to join the conversation.

05 Aug 2021 11:08 #50856 by timi
Replied by timi on topic Electrical systems... xml or nasal?
And here's the reference for expression.
wiki.flightgear.org/Expressions
The following user(s) said Thank You: ScottBouch

Please Log in to join the conversation.

05 Aug 2021 11:47 #50857 by ScottBouch
Replied by ScottBouch on topic Electrical systems... xml or nasal?
How do you create a property tree property using AP xml?

In Nasal, the properties can be generated once when the script is loaded, then it goes into the loops / functions where the properties are read / written. Is there a way to use an AP xml to only create properties once before getting into looping the program? If not, isn't it wasteful to be creating properties that were created during the last iteration?

Or, is it best practice to create properties in an accompanying Nasal script, and leave the AP to just read from / write to them?

Cheers,

Please Log in to join the conversation.

05 Aug 2021 12:05 #50858 by timi
Replied by timi on topic Electrical systems... xml or nasal?
A property gets automatically created when you define it as the output of a filter. So it doesn't need to be defined in any other way than that.
The following user(s) said Thank You: ScottBouch

Please Log in to join the conversation.

05 Aug 2021 12:11 #50859 by timi
Replied by timi on topic Electrical systems... xml or nasal?
And I suppose sometimes there are some internal properties you can't overwrite and then you would just roll your own instead for the output.

Please Log in to join the conversation.

05 Aug 2021 12:20 - 05 Aug 2021 12:24 #50860 by ScottBouch
Replied by ScottBouch on topic Electrical systems... xml or nasal?
Ah, thank you.

So, going back to an earlier point - why bother with Nasal if AP can do it all at either frame rate or FDM rate?

One guess is that sometimes frame rates can drop (my old laptop is often down at 6 fps (166mS)).. so If I was using data externally (like my hardware sim) the PC having a rubbish GPU could cause some external hiccups. If Nasal was used, then you could guarantee the steady timing of program execution. Unless you did everything at FDM speed.....

My external hardware sim talks to flightgear at 30Hz (33ms), a lot faster than the 166ms in worst case scenario.

Could the variable rate also affect co-pilot multiplayer?

Please Log in to join the conversation.

05 Aug 2021 12:40 #50862 by timi
Replied by timi on topic Electrical systems... xml or nasal?
I think enrogue already gave an example why not to use Nasal when frame rates drop.
Since the FDM runs independent of frame rate then the AP system isn't affected by
the hiccups caused by frame rate drops and thus the control surfaces move like they
are supposed to even in case of frame rate issues.

So it might just be that people are used to coding in Nasal and don't know any better.
And I started using AP because I didn't want to learn Nasal. And it had some nice
performance benefits as a side product too.

Please Log in to join the conversation.

05 Aug 2021 12:59 #50863 by timi
Replied by timi on topic Electrical systems... xml or nasal?
The AP documentation also had this to say:

Expose to Nasal

Given that Nasal is a widely-known bottleneck, people should not use it for implement FDM/AP or route-manager functionality in scripting space. However, for the time being, the underlying C++ code is not exposed to scripting space, so that aircraft developers tend to reinvent the wheel. Thus, it would make sense to expose the AP/property-rule/state machine subsystems to scripting space using the Nasal/CppBind framework, to ensure that existing C++ code can be used for such purposes.

Please Log in to join the conversation.

05 Aug 2021 13:48 - 05 Aug 2021 13:50 #50864 by ScottBouch
Replied by ScottBouch on topic Electrical systems... xml or nasal?
Thank you,

So really taking that comment into account, would you say to build a good aircraft in modern flightgear, are we best off using AP at FDM rate for most aircraft systems (keeping external hardware happy) such as electrics and hydraulics, and AP at frame rate for on-screen graphics such as gauge pointers?

This is making the assumption that most modern PC's should be able to handle the processing load of doing the majority of the processing at the fastest rate, and we won't need to slow down any work by using Nasal where we can set the loop timer.

A nice fix would be a way to tell the AP system the speed at which certain xml files are to be executed, as some may not need to be as fast as the FDM, but also can't be upset by an unpredictable frame rate due to GPU hardware constraints.

Please Log in to join the conversation.

05 Aug 2021 14:54 #50865 by timi
Replied by timi on topic Electrical systems... xml or nasal?
The documentation also seemed to suggest a combination of AP and property
rules where frame rate is enough.


Autopilot vs. property-rule configurations
The main difference between XML based autopilot and property-rule systems is the update rate:

Autopilot configurations run at FDM rate
Property-rule configurations run at frame rate

Performance considerations

Using property-rule elements for things that does not have to run a FDM rate can improve the frame rate, in particular for complex systems and on weaker computers. Depending on FlightGear settings and the hardware, the FDM rate is about 2–10 times higher than the frame rate.

It is possible to implement a system using both autopilot and property-rule based elements. They can communicate with each other using properties. The only disadvantage is that they will be split between an autopilot and a property-rule configuration file.

For example would a fly-by-wire flight control system element augmenting an unstable aircraft need to run at FDM rate, while an element depending on the flap extension would work just as well at frame rate.

Please Log in to join the conversation.

05 Aug 2021 15:30 #50866 by timi
Replied by timi on topic Electrical systems... xml or nasal?
Then there are these JSBSim specific FCS controls where you can define
the execution rate as well.

github.com/NikolaiVChr/f16/blob/master/Systems/jsb-misc.xml

Please Log in to join the conversation.

05 Aug 2021 23:00 #50868 by ScottBouch
Replied by ScottBouch on topic Electrical systems... xml or nasal?
I get the feeling that this model would benefit from a ground up organised rebuid using AP.

I recently put in a lot of work to the systems on Nasal.

I think a total rebuild is a massive job, but one for the future.. for now I am inclined to carry on and finish off what I started in Nasal to give it a touch more realism, but then fork it off to an AP driven model to end up with something wholly better in the long run.

Sounds like more work, but it would improve the current model, and will provide an opportunity to learn snippets of AP code in small chunks first before a ground up rebuild.

Cheers, Scott

Please Log in to join the conversation.

09 Aug 2021 20:14 #50890 by Richard
Replied by Richard on topic Electrical systems... xml or nasal?
I've had a look at your Nasal code and really I'd recommend that you continue along this route for an electrical system.

You can do great things with the autopilot XML - and probably even all of your logic; but really to change track you'd need a compelling reason. One thing that the autopilot does provide is a state machine - which is very useful. I rewrote my master caution (for the F-15) using a state machine and it tidied it up nicely.

The two things that generally cause performance issues with Nasal are doing too much each frame and garbage collection. Garbage collection must be minimised by declaring as many variables at global scope; and avoiding having local variables.

I don't think you need to worry about either of these in your current code; and if you keep to that format then it garbage collection won't be a problem in the future.
The following user(s) said Thank You: ScottBouch

Please Log in to join the conversation.

10 Aug 2021 14:15 #50895 by ScottBouch
Replied by ScottBouch on topic Electrical systems... xml or nasal?
Thank you for that advice, its good to hear both sides before committing to any drastic changes.

I'd not come across garbage collection, so thanks for the tips there, will keep as many variables as possible global.

Cheers, Scott

Please Log in to join the conversation.

Time to create page: 0.214 seconds
Powered by Kunena Forum

Latest Forum Posts

PM Notifications

You are not logged in.

PM Mailbox

You are not logged in.