Board index FlightGear Development Nasal

Reset aircraft via Nasal script

Nasal is the scripting language of FlightGear.

Reset aircraft via Nasal script

Postby markuskaufmann » Wed Oct 24, 2018 9:26 am

Hello

I am currently involved in a project to teach FlightGear how to land with artificial intelligence using a selected aircraft.
Part of this project includes the implementation of a correct environment reset function which should re-position our selected aircraft (Cessna 172p Skyhawk) in the simulator (implied by given parameters like latitude, longitude, altitude, airspeed, ...) after a specified amount of time.
We already implemented a prototype script in Nasal for said purpose (and it seems to work in most situations), but in case of an accident the reset results in complete chaos. While our reset function repairs all damage before setting the aircraft back and does place the aircraft in the correct reset position, the aircraft behaves erratically. It turns upside down after it flies for 0.5 seconds, does barrel rolls etc. After a few subsequent resets, the plane stops behaving erratically.

Does anyone have experience with the reset function? Is such a reset procedure even possible without changing the internal subsystems to an inconsistent state?


Kind Regards


Reset Properties:

var cp2_aileron = 0;
var cp2_elevator = 0.3;
var cp2_rudder = 0;
var cp2_flaps = 1;
var cp2_throttle = 0.2;
var cp2_mixture = 0.5;
var cp2_latitude_deg = 21.3252466948;
var cp2_longitude_deg = -157.946;
var cp2_altitude_ft = 66;
var cp2_airspeed_kt = 33;
var cp2_pitch_deg = -5;
var cp2_roll_deg = 0;
var cp2_heading_deg = 90;
markuskaufmann
 
Posts: 2
Joined: Tue Sep 18, 2018 9:42 am

Re: Reset aircraft via Nasal script

Postby Thorsten » Wed Oct 24, 2018 10:17 am

The Space Shuttle approach trainer does a reset from the runway to the beginning of the final approach.

The main enemies you are facing are finite time effects in the FDM

* control surfaces take a while to get into the correct position
* PID controllers may have the integrator completely wrong
* ...

In the case of an accident you might have un-resolved spring forces from the contact points for instance - as well as aerodynamic coefficients 'suddenly' snapping back to their value (and likely all controllers and surfaces are far off their nominal positions, so finite time effects are pretty bad).

So you can't do 'just' a Nasal reset of properties, the FDM needs flags which allow you to deal with the transients caused by these finite time effects (or instance in using a different <kinematic> block which is used for a few seconds in which the surface is allowed to move much faster.

It really depends on the plane you're working with, I don't think there's a 'one size fits all' approach.
Thorsten
 
Posts: 10239
Joined: Mon Nov 02, 2009 8:33 am

Re: Reset aircraft via Nasal script

Postby wlbragg » Wed Oct 24, 2018 7:30 pm

I think Thorsten explained the simulator crash situation issue well. That is one area I have not dealt with extensively and don't have much insight to offer.

In the most recent version (in Git), you may want to look at mooring.nas, save.nas maybe even the tutorial system for doing a standard set reset. They all deal with relocation but from a sane starting point. Maybe there is something in them that might help that you overlooked.
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
User avatar
wlbragg
 
Posts: 4418
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Debain/nVGT640

Re: Reset aircraft via Nasal script

Postby vanosten » Sat Feb 23, 2019 3:18 pm

Is there a possiblity to do a "hard" reset through Nasal - i.e. the same as File->Reset through the menu? And while we are at it exiting the simulator like File->Quit in Nasal (without prompting the user)?
Maintaining osm2city
vanosten
 
Posts: 371
Joined: Sat Sep 25, 2010 5:38 pm
Location: Denmark - but I am Swiss
Callsign: HB-VANO
Version: latest
OS: Win 10 and Ubuntu

Re: Reset aircraft via Nasal script

Postby Hooray » Sun Feb 24, 2019 4:34 pm

yes, of course - you can always open up menubar.xml to see for yourself.
You can then see that it's triggering so called fgcommands (bindings).
You can invoke those from Nasal via the fgcommand() API

The wiki has all the docs that you need, but like I said, looking at menubar.xml should actually suffice
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: 11292
Joined: Tue Mar 25, 2008 8:40 am

Re: Reset aircraft via Nasal script

Postby vanosten » Mon Feb 25, 2019 6:28 pm

Thanks for the help. You are right - apart from the fact that the wiki and README's not mentioning "reset" as a fgcommand. I have updated the Telnet Usage wiki article accordingly.
Maintaining osm2city
vanosten
 
Posts: 371
Joined: Sat Sep 25, 2010 5:38 pm
Location: Denmark - but I am Swiss
Callsign: HB-VANO
Version: latest
OS: Win 10 and Ubuntu


Return to Nasal

Who is online

Users browsing this forum: No registered users and 1 guest