Board index FlightGear Support Compiling

How to assign the value of a property to another property

Building FlightGear from source, and in the need for help?

How to assign the value of a property to another property

Postby Dris » Wed Mar 09, 2022 3:05 pm

Hi guys!

I'm trying to assign the value of the property slant-distance-m (double property) to the nav-distance property (double property). They are located in diferent directories, and when I use the following command line it doesn´t work.

setprop( "/instrumentation/nav[0]/nav-distance", getprop( "/instrumentation/nav[0]/vor/slant-distance-m" ));

Anyone knows how to solve it?

Thanks!
Dris
 
Posts: 36
Joined: Thu Feb 17, 2022 10:34 pm

Re: How to assign the value of a property to another propert

Postby erik » Wed Mar 09, 2022 3:27 pm

Personally I would go for a property rule in such cases:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<PropertyList>
  <filter>
   <type>gain</type>
   <gain>1.0</gain>
   <input>/instrumentation/nav[0]/vor/slant-distance-m/input>
   <output>/instrumentation/nav[0]/nav-distance</output>
  </filter>
</PropertyList>

Reference:
https://wiki.flightgear.org/Autopilot_c ... figuration

It allows for unit conversions if needed and is probably faster.

Erik
Current: Parachutist, Paraglider, Pterosaur, Pilatus PC-9M and variants, ERCO Ercoupe, Fokker Dr.1, Fokker 50, Fokker 100
Less active: Cessna T-37, T-38, Santa Claus. Previous: General Dynamics F-16. Worked on: Wright Flyer
erik
 
Posts: 2245
Joined: Thu Nov 01, 2007 2:41 pm

Re: How to assign the value of a property to another propert

Postby Dris » Wed Mar 09, 2022 3:42 pm

Hi Erik!

This happens when adding that to the Senecall-base.xml file:

https://ibb.co/hXxz196
https://ibb.co/xKZzqQ6
Dris
 
Posts: 36
Joined: Thu Feb 17, 2022 10:34 pm

Re: How to assign the value of a property to another propert

Postby Thorsten » Wed Mar 09, 2022 3:42 pm

Yet it ought to work in Nasal, and if it doesn't for some reason, the property rule probably will not work for the same reason.

So what happens that 'doesn't work' - is there an error in the console, is the property not created at all, is it not updated, is it created elsewhere?
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: How to assign the value of a property to another propert

Postby WoodSTokk » Wed Mar 09, 2022 3:43 pm

Yue should use a DME for the distance. The value will than be under '/instrumentation/dme[n]/indicated-distance-nm'.
WoodSTokk
 
Posts: 1077
Joined: Tue Oct 17, 2017 3:30 pm
Location: Milky Way/Sol/Earth/Europe
Callsign: SX-W57
IRC name: WoodSTokk
Version: 2020.4.0
OS: Debian Bullseye

Re: How to assign the value of a property to another propert

Postby Thorsten » Wed Mar 09, 2022 3:44 pm

Well, you could have spotted this yourself, it's a mismatched tag as the error says, the last input here doesn't close:

Code: Select all
   <input>/instrumentation/nav[0]/vor/slant-distance-m/input>
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: How to assign the value of a property to another propert

Postby Dris » Wed Mar 09, 2022 3:51 pm

Hi Thorsten, I'll give you some SS of the property. When I introduce it in the Nasal file the console of the FG1000 appears black.

This is the property whose value i want:
https://ibb.co/dc5wHNp

This is the property where i want to set te value:
https://ibb.co/2kV298K

This is how i wrote it in the Senecall.nas file:
https://ibb.co/PY48dQ7

This is the FG1000 before introducing the command line:
https://ibb.co/PgZTppz

This is the FG1000 after introducing the command line:
https://ibb.co/RDQJYQQ

On the other hand, introducing this command lines to the Senecall-base.xml file doesn`t give a value to the property nav-distance (look the SS below):
https://ibb.co/2kV298K

<filter>
<type>gain</type>
<gain>1.0</gain>
<input>/instrumentation/nav[0]/vor/slant-distance-m</input>
<output>/instrumentation/nav[0]/nav-distance</output>
</filter>


Thanks!
Last edited by Dris on Wed Mar 09, 2022 3:59 pm, edited 1 time in total.
Dris
 
Posts: 36
Joined: Thu Feb 17, 2022 10:34 pm

Re: How to assign the value of a property to another propert

Postby erik » Wed Mar 09, 2022 3:57 pm

Thorsten wrote in Wed Mar 09, 2022 3:44 pm:Well, you could have spotted this yourself, it's a mismatched tag as the error says, the last input here doesn't close:

Code: Select all
   <input>/instrumentation/nav[0]/vor/slant-distance-m/input>

oops, copy and paste error.

Erik
Current: Parachutist, Paraglider, Pterosaur, Pilatus PC-9M and variants, ERCO Ercoupe, Fokker Dr.1, Fokker 50, Fokker 100
Less active: Cessna T-37, T-38, Santa Claus. Previous: General Dynamics F-16. Worked on: Wright Flyer
erik
 
Posts: 2245
Joined: Thu Nov 01, 2007 2:41 pm

Re: How to assign the value of a property to another propert

Postby Dris » Wed Mar 09, 2022 5:17 pm

Hi WoodSTokk!

I tried with the property /instrumentation/dme[n]/indicated-distance-nm and it seems to work, but the problem is that this property is 0 and i don`t know why. I'll give you SSs:

- The value of the variable /instrumentation/dme[0]/indicated-distance-nm in this moment is:
https://ibb.co/R4gcLpk


- When I introduce this command line:
setprop( "/instrumentation/nav[0]/nav-distance", getprop("/instrumentation/dme[0]/indicated-distance-nm") );

This happens:
https://ibb.co/2hcQXHM


- When I introduce the value of the property manually with this command line:
setprop( "/instrumentation/nav[0]/nav-distance", 3.4 );

Then it works:
https://ibb.co/gSNLFdW



Anyone knows how to solve it?

I'm sorry for doing this kind of questions.


Thanks!
Dris
 
Posts: 36
Joined: Thu Feb 17, 2022 10:34 pm

Re: How to assign the value of a property to another propert

Postby Dris » Wed Mar 09, 2022 6:10 pm

Hi again!

I think that this happens because /instrumentation/dme[n]/indicated-distance-nm is a dynamic variable that is changing during flight, and when I use this command line: setprop( "/instrumentation/nav[0]/nav-distance", getprop("/instrumentation/dme[0]/indicated-distance-nm") );, it only assigns the value of the variable one time when I open the aircraft in FlightGear and not always it changes. Is there any way to assign the value of the variable /instrumentation/dme[0]/indicated-distance-nm in a dynamic way?

Thanks!
Dris
 
Posts: 36
Joined: Thu Feb 17, 2022 10:34 pm

Re: How to assign the value of a property to another propert

Postby Thorsten » Wed Mar 09, 2022 6:54 pm

it only assigns the value of the variable one time when I open the aircraft in FlightGear and not always it changes.


Well, you put it into a loop and run the loop at the frquency needed, if you run it once, it only runs once.

Btw, it's not helpful to get an external screenshot for everything - if there's an error on the console, just report the error. If you want to show your own code, paste it into here in code tags. I simply don't have the time to click through 10 images to find the answer to a simple question I asked.

If I need an image for debug purposes, I ask specifically for what I need.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: How to assign the value of a property to another propert

Postby WoodSTokk » Thu Mar 10, 2022 1:19 am

As erik allready said, a prop-filter will do the trick.
Save this in a file (like 'nav-distance.xml') and add it in the set.xml as property-rule (run every frame):
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<PropertyList>

    <filter>
        <name>nav0-distance</name>
        <debug>false</debug>
        <type>gain</type>
        <input>instrumentation/dme[0]/indicated-distance-nm</input>
        <output>instrumentation/nav[0]/nav-distance</output>
    </filter>

</PropertyList>
WoodSTokk
 
Posts: 1077
Joined: Tue Oct 17, 2017 3:30 pm
Location: Milky Way/Sol/Earth/Europe
Callsign: SX-W57
IRC name: WoodSTokk
Version: 2020.4.0
OS: Debian Bullseye

Re: How to assign the value of a property to another propert

Postby S&J » Thu Mar 10, 2022 9:29 am

A lot of heavy weather being made of this.
Drop this into your fdm

Code: Select all
<function  name="instrumentation/nav[0]/nav-distance">                                                                                    
   <property>instrumentation/dme[0]/indicated-distance-nm</property>                                                               
</function>
"Stay away from negative people.They have a problem for every solution." - Albert Einstein
S&J
 
Posts: 794
Joined: Wed Aug 26, 2020 7:31 pm

Re: How to assign the value of a property to another propert

Postby Thorsten » Thu Mar 10, 2022 10:41 am

Drop this into your fdm


This won't work if the FDM is YaSim because it is JSBSim syntax, and it will be inefficient because the FDM runs faster than instrumentation updates.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am


Return to Compiling

Who is online

Users browsing this forum: No registered users and 5 guests