Board index FlightGear Support Interfacing

Starting helicopter from a specific position with rotors on

Connecting two computers, using generic protocol, connecting with Matlab?

Starting helicopter from a specific position with rotors on

Postby alexklibisz » Sat Jul 16, 2016 4:58 am

Short question: Which arguments should I pass or properties in the property tree should I modify so that the helicopter simulation starts with the rotors spinning? How do I mimic the { and } commands via property tree?

Longer explanation:

I'm attempting to train a neural network to keep a helicopter hovering in a stable position. Currently I'm using the Raven R44 but may switch to the BO105 eventually. I'm able to read/write properties to/from the property tree over a UDP socket using the Generic Protocol and --generic argument.

I would like to be able to start the helicopter from a specific position with the rotors on. For example, start at an altitude of 100ft with rotors spinning.

I'm able to use the --altitude argument to start at a specific altitude. However, I have not been able to figure out which properties in the property tree correspond to turning the rotors on/off.

I've tried modifying mostly properties within the /controls/engines/engine/ tree. I've also looked up several other issues which were never completely answered: https://forum.flightgear.org/viewtopic.php?f=17&t=15238, https://forum.flightgear.org/viewtopic.php?f=25&t=28881

Maybe I'm going about it the wrong way? Should I instead be using a Nasal script that executes when the simulator launches?
alexklibisz
 
Posts: 14
Joined: Sat Jul 16, 2016 4:47 am

Re: Starting helicopter from a specific position with rotors

Postby Thorsten » Sat Jul 16, 2016 6:26 am

The set of properties you need to init in a dynamical situation is rather aircraft-specific, so it's hard to give general advice and I don't think there is a comprehensive answer.

(With a helicopter, I'd immediately start to wonder about torque when it's in-air, rotors on - wouldn't it start to spin madly immediately?.)

I have learned how to save/resume unpowered flight (and it requires scripting). There's a couple of potential situations which require properties to be set in sequence, i.e. there may be the need to wait a frame from setting the first set to setting the second set and these never work via commandline properties.

So I guess the answer is that this really is an open question - someone needs to sit down for a few days and figure out how this can be made to work and what the relevant properties for a helicopter are.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Starting helicopter from a specific position with rotors

Postby chriscalef » Sat Jul 16, 2016 8:34 am

That sounds like a really cool experiment though, good luck! Please come back with your results!
chriscalef
 
Posts: 279
Joined: Wed Feb 20, 2013 10:28 pm

Re: Starting helicopter from a specific position with rotors

Postby alexklibisz » Sat Jul 16, 2016 3:33 pm

Is there any simple way to diff the property tree between two points in time? Maybe a logging flag that can be set?

So I would take a snapshot before starting the helicopter and another once it's 100 ft. in the air. Then I could diff the two to figure out what properties need to be modified.
alexklibisz
 
Posts: 14
Joined: Sat Jul 16, 2016 4:47 am

Re: Starting helicopter from a specific position with rotors

Postby Thorsten » Sat Jul 16, 2016 5:11 pm

You can dump the whole property tree, if you do it on two time instances, I suppose you can run a diff. It's going to return lots of irrelevants though...

For instance, FG has multiple ways of displaying speeds (inertial speed, earth-relative speed, airspeed, Mach number, the body axis speeds, equivalent airspeed,...) but there's (to my knowledge) only one set (uBody, vBody and wBody) that can be set upon init, the rest are dependent properties and get overwritten.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Starting helicopter from a specific position with rotors

Postby Hooray » Sat Jul 16, 2016 6:14 pm

Yeah, you could certainly use Nasal scripting for this, even for the NN part - e.g. see: http://wiki.flightgear.org/Howto:Neural ... s_in_Nasal

You will need some training data (e.g. pre-recorded flights) especially to deal with the situations Thorsten mentioned - but otherwise, a NN should be perfectly capable to implement PID-like behavior. If in doubt, you could use GA/GP to evolve a NN for different PIDs.

For the property tree dump, see props.nas in $FG_ROOT/Nasal

diff'ing the whole thing means doing tree traversal on a sub-node of the global tree (think /fdm)

If I were to do something like this, I would probably use the built-in autopilot system to come up with training data for the NNs that you need (think hover, heading, gradient climb/descent) and then use that data to train the ANN using different locations, but also different surrounding data.

To evaluate the "fitness" of the NN, you would measure the error by computing the delta between the desired output and the actual output (think altitude, airspeed, groundspeed, heading/course).

My suggestion would be to look at the wiki article and to consider using Nasal scripting for this - it's all there, and you can easily adapt existing JavaScript NN libs to use those in FG that way - i.e. no external software needed, which also improves your chances of getting support here, because people can more easily replicate your setup, i.e. you really just need to share your code with others - or even just get involved in writing a NN tutorial for the wiki
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: Starting helicopter from a specific position with rotors

Postby alexklibisz » Mon Jul 18, 2016 2:13 pm

I'm not so much concerned about the neural network because I actually have to use an external model for this project.

The NN gets trained using evolutionary optimization. So it's crucial that we can quickly restart simulations, which is why I'm focusing on starting FGFS with the helicopter hovering.

Does anyone know of some nasal scripting examples that I could look at for this specific task?
alexklibisz
 
Posts: 14
Joined: Sat Jul 16, 2016 4:47 am

Re: Starting helicopter from a specific position with rotors

Postby alexklibisz » Mon Jul 18, 2016 4:26 pm

Hooray wrote in Sat Jul 16, 2016 6:14 pm:For the property tree dump, see props.nas in $FG_ROOT/Nasal


Could you explain a little more specifically what I should do or be looking for with this script?
alexklibisz
 
Posts: 14
Joined: Sat Jul 16, 2016 4:47 am

Re: Starting helicopter from a specific position with rotors

Postby alexklibisz » Mon Jul 18, 2016 6:04 pm

Good news! I figured out that setting the "/controls/engines/engine/magnetos" property to 1 will turn the rotors on. I did this with a little python script that grabs all of the properties over the http json API, then used that script to take a "snapshot" with the rotors off and another with the rotors on.

So this will start the helicopter with the rotors spinning:

fgfs --aircraft=uh1 --prop:/controls/engines/engine/magnetos=1

Interestingly, it does not work for --aircraft=raven. The OH-1 also works.

Next step will be to see if I can have them spinning at a specific RPM immediately.
alexklibisz
 
Posts: 14
Joined: Sat Jul 16, 2016 4:47 am

Re: Starting helicopter from a specific position with rotors

Postby Hooray » Mon Jul 18, 2016 10:37 pm

there is debug.dump() and props.dump() IIRC - but any recursively calling function will likely contain property traversal code, think props.copy() etc

Also note that the presets stuff is currently being revamped, and that there are a few long-standing issues relating to it (see the wiki), there is currently a state-management feature in the works - not sure though if it is intended to support arbitrary aircraft, like helicopters.

The GA/GP part could certainly be implemented in Nasal, too - but the genome itself could also be Nasal blocks, too.
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: Starting helicopter from a specific position with rotors

Postby Thorsten » Tue Jul 19, 2016 5:51 am

The state-management feature is just a container - the aircraft maintainer still needs to figure out and define what goes into the state - which is the basic issue in this thread.

I simply don't know it for helicopter engines, I just know what you need for unpowered glider flight.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Starting helicopter from a specific position with rotors

Postby Hooray » Wed Jul 20, 2016 9:37 pm

Also, Nasal scripting has previously been used to do this sort of thing - i.e. the acstate.nas script created by Melchior
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


Return to Interfacing

Who is online

Users browsing this forum: No registered users and 7 guests