Board index FlightGear Development Aircraft

Don't round up OSGtext, any way to do this?

Questions and discussion about creating aircraft. Flight dynamics, 3d models, cockpits, systems, animation, textures.

Don't round up OSGtext, any way to do this?

Postby Octal450 » Wed Jan 11, 2017 10:07 pm

I have to take my instrumentation/altimeter/indicated-altitude-ft and do a /100 on it, so it shows the altitude from the hundreds place only. But the number is now rounded when I put it into the OSGtext for my PFD.
How I can fix this?

Code: Select all
setlistener("/instrumentation/altimeter/indicated-altitude-ft", func {
   setprop("/instrumentation/altimeter/indicated-altitude-ft-pfd", getprop("/instrumentation/altimeter/indicated-altitude-ft") / 100);
});


Code: Select all
   <text>
      <name>osgtext-green</name>
      <offsets>
         <x-m>0.0010</x-m>
         <y-m>0.0553</y-m>
         <z-m>0.0002</z-m>
      </offsets>
      <alignment>right-center</alignment>
      <axis-alignment>yz-plane</axis-alignment>
      <type type="string">number-value</type>
      <format type="string">%3.0f</format>
      <property>/instrumentation/altimeter/indicated-altitude-ft-pfd</property>
      <truncate type="bool">false</truncate>
      <font type="string">helvetica_bold.txf</font>
      <draw-text type="bool">true</draw-text>
      <draw-alignment type="bool">false</draw-alignment>
      <draw-boundingbox type="bool">false</draw-boundingbox>
      <character-size>0.007</character-size>
      <font-resolution>
         <width type="int">32</width>
         <height type="int">32</height>
      </font-resolution>
   </text>
Octal450

FGFS Aircraft Developer
Lead Developer at Immersive Design Group (Join our Discord!)
Download High Quality Aircraft from Octal450 Hangar
Dream no small dream; it lacks magic. Dream large. Then make the dream real. - Donald Douglas
User avatar
Octal450
 
Posts: 4116
Joined: Tue Oct 06, 2015 12:51 pm
Location: A far corner of my room
Callsign: WTF450/Octal
Version: 2018.3.2
OS: Windows 10 x64

Re: Don't round up OSGtext, any way to do this?

Postby PINTO » Wed Jan 11, 2017 10:34 pm

So you don't want the altitude rounded? Just remove the '-pfd' from your property.

edit: also it's probably not a great choice to do a setlistener() on the indicated altitude property. I'd definitely recommend a timer there.
Actively developing the MiG-21bis (link to repo) (link to thread)

http://opredflag.com is an active flightgear dogfighting community (using a system that isn’t bombable)
User avatar
PINTO
 
Posts: 936
Joined: Wed Oct 21, 2015 6:28 pm
Callsign: pinto
Version: 2016.3.0
OS: Win10

Re: Don't round up OSGtext, any way to do this?

Postby Octal450 » Wed Jan 11, 2017 10:36 pm

You misunderstand me.
I need the altitude number to read ONLY from the hundreds place. But, that leaves decimals. Since I set my OSG to %3.0f, it doesn't display the decimals, so it rounds up the first number. the -pfd prop just has the altitude / 100ed.
Octal450

FGFS Aircraft Developer
Lead Developer at Immersive Design Group (Join our Discord!)
Download High Quality Aircraft from Octal450 Hangar
Dream no small dream; it lacks magic. Dream large. Then make the dream real. - Donald Douglas
User avatar
Octal450
 
Posts: 4116
Joined: Tue Oct 06, 2015 12:51 pm
Location: A far corner of my room
Callsign: WTF450/Octal
Version: 2018.3.2
OS: Windows 10 x64

Re: Don't round up OSGtext, any way to do this?

Postby PINTO » Wed Jan 11, 2017 10:39 pm

Do another property then. On mobile so forgive me not typing out the properties.

rounded_altitude = math.floor(indicated altitude / 100) * 100

Also, you shouldn't use a listener there but a timer instead.
Actively developing the MiG-21bis (link to repo) (link to thread)

http://opredflag.com is an active flightgear dogfighting community (using a system that isn’t bombable)
User avatar
PINTO
 
Posts: 936
Joined: Wed Oct 21, 2015 6:28 pm
Callsign: pinto
Version: 2016.3.0
OS: Win10

Re: Don't round up OSGtext, any way to do this?

Postby PINTO » Wed Jan 11, 2017 10:40 pm

Or even cheaper,

math.round(indicated altitude,100)
Actively developing the MiG-21bis (link to repo) (link to thread)

http://opredflag.com is an active flightgear dogfighting community (using a system that isn’t bombable)
User avatar
PINTO
 
Posts: 936
Joined: Wed Oct 21, 2015 6:28 pm
Callsign: pinto
Version: 2016.3.0
OS: Win10

Re: Don't round up OSGtext, any way to do this?

Postby Octal450 » Wed Jan 11, 2017 10:47 pm

I'll give it a go.
I use a listener because It needs to update constantly, as I am using it as the main altimeter.
Octal450

FGFS Aircraft Developer
Lead Developer at Immersive Design Group (Join our Discord!)
Download High Quality Aircraft from Octal450 Hangar
Dream no small dream; it lacks magic. Dream large. Then make the dream real. - Donald Douglas
User avatar
Octal450
 
Posts: 4116
Joined: Tue Oct 06, 2015 12:51 pm
Location: A far corner of my room
Callsign: WTF450/Octal
Version: 2018.3.2
OS: Windows 10 x64

Re: Don't round up OSGtext, any way to do this?

Postby sanhozay » Wed Jan 11, 2017 11:25 pm

If it's updated constantly, presumably at FDM rate, wouldn't you be better with a property rule?
sanhozay
 
Posts: 1207
Joined: Thu Dec 26, 2013 11:57 am
Location: EGNM
Callsign: G-SHOZ
Version: Git
OS: Ubuntu 16.04

Re: Don't round up OSGtext, any way to do this?

Postby Octal450 » Thu Jan 12, 2017 4:01 am

Probably.

But that still won't solve my problem ;)
Octal450

FGFS Aircraft Developer
Lead Developer at Immersive Design Group (Join our Discord!)
Download High Quality Aircraft from Octal450 Hangar
Dream no small dream; it lacks magic. Dream large. Then make the dream real. - Donald Douglas
User avatar
Octal450
 
Posts: 4116
Joined: Tue Oct 06, 2015 12:51 pm
Location: A far corner of my room
Callsign: WTF450/Octal
Version: 2018.3.2
OS: Windows 10 x64

Re: Don't round up OSGtext, any way to do this?

Postby sanhozay » Thu Jan 12, 2017 10:58 pm

I suspect it will if you can express your requirement correctly in expression syntax.

I have read this thread several times and I'm still not 100% sure what the problem is. If it was a simple rounding issue you would have accepted PINTO's advice. My best guess is that you want to truncate the fractional part of the decimal after dividing by 100, e.g.

10550 / 100 = 105.5, expressed in %3.0f format is 106.

In this case, if you want 105, you need a floor or int on the 105.5 before formatting it. You can do that with an expression in a property rule. You can also do it in Nasal if you insist, but firing a listener off an FDM generated property is not a good idea.

http://wiki.flightgear.org/Expressions
http://wiki.flightgear.org/Nasal_library#int.28.29
https://en.m.wikipedia.org/wiki/Decimal
https://en.m.wikipedia.org/wiki/Truncation
sanhozay
 
Posts: 1207
Joined: Thu Dec 26, 2013 11:57 am
Location: EGNM
Callsign: G-SHOZ
Version: Git
OS: Ubuntu 16.04

Re: Don't round up OSGtext, any way to do this?

Postby D-ECHO » Sat Jan 14, 2017 7:04 am

Just a short note, as I saw OSGtext in the title, maybe it's not a good idea to use this at all, as it breaks the rain animation, IIRC
User avatar
D-ECHO
 
Posts: 1473
Joined: Sat May 09, 2015 12:31 pm

Re: Don't round up OSGtext, any way to do this?

Postby Octal450 » Sat Jan 14, 2017 3:37 pm

[offtopic]Can you explain more?

I use OSGtext on all my glass gauges.[/offtopic]
Octal450

FGFS Aircraft Developer
Lead Developer at Immersive Design Group (Join our Discord!)
Download High Quality Aircraft from Octal450 Hangar
Dream no small dream; it lacks magic. Dream large. Then make the dream real. - Donald Douglas
User avatar
Octal450
 
Posts: 4116
Joined: Tue Oct 06, 2015 12:51 pm
Location: A far corner of my room
Callsign: WTF450/Octal
Version: 2018.3.2
OS: Windows 10 x64

Re: Don't round up OSGtext, any way to do this?

Postby D-ECHO » Sat Jan 14, 2017 4:28 pm

User avatar
D-ECHO
 
Posts: 1473
Joined: Sat May 09, 2015 12:31 pm

Re: Don't round up OSGtext, any way to do this?

Postby zakalawe » Wed Jan 25, 2017 2:22 pm

Please don't use a listener OR a timer for this, but rather an XML rule - this is much cheaper for a continuously updated value than nasal, zero allocations and hence no Nasal GC issues. You can use the <expression> syntax to scale and clamp the value, there might even be built-in rounding support, I forget.
zakalawe
 
Posts: 1152
Joined: Sat Jul 19, 2008 4:48 pm
Location: Edinburgh, Scotland
Callsign: G-ZKLW
Version: next
OS: Mac

Re: Don't round up OSGtext, any way to do this?

Postby Hooray » Wed Jan 25, 2017 2:26 pm

zakalawe wrote in Wed Jan 25, 2017 2:22 pm:Please don't use a listener OR a timer for this, but rather an XML rule - this is much cheaper for a continuously updated value than nasal, zero allocations and hence no Nasal GC issues. You can use the <expression> syntax to scale and clamp the value, there might even be built-in rounding support, I forget.


That is exactly why Torsten suggested originally to expose the property rule/autopilot system to Nasal space and make it accessible for such purposes:

Subject: 2 Questions: vacuum & electrical
Torsten wrote:I think, performance of Nasal code and XML based property rules is pretty close. The big advantage of the property rules is that they don't produce garbage that a garbage collector has to clean up. But as nothing in life comes for free (except FlightGear, of course) XML tends to be much more verbose - as you correctly stated.

My personal guideline for using one or the other system is:
  • Computing properties from a well defined set of other properties once per frame: use a property rule.
  • If there is no other way to get it done: use Nasal.
I have recently committed some code to allow runtime loading of <strike>autopilots</strike> property rules and have a Nasal binding for that in mind. This _might_ end up in something like
Code: Select all
var myPid = pidController.new();
myPid.Td = 0.0001;
myPid.Ti = 123.4;
myPid.Kp = 0.2;
myPid.input = "/foo";
myPid.reference = "/bar";
myPid.output = "/baz";

etc, etc.

But that's probably a little off topic now.



Note that this is one of the most common suggestions (porting Nasal update loops to become property rules), and until the corresponding SimGear/FlightGear APIs are exposed to scripting space (e.g. using cppbind), we will certainly continue to see such problematic implementations.
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: 11317
Joined: Tue Mar 25, 2008 8:40 am

Re: Don't round up OSGtext, any way to do this?

Postby Octal450 » Wed Jan 25, 2017 8:34 pm

Good idea.
A property rule much better fits this.

I've been testing a bunch of configs, will report soon.
Octal450

FGFS Aircraft Developer
Lead Developer at Immersive Design Group (Join our Discord!)
Download High Quality Aircraft from Octal450 Hangar
Dream no small dream; it lacks magic. Dream large. Then make the dream real. - Donald Douglas
User avatar
Octal450
 
Posts: 4116
Joined: Tue Oct 06, 2015 12:51 pm
Location: A far corner of my room
Callsign: WTF450/Octal
Version: 2018.3.2
OS: Windows 10 x64

Next

Return to Aircraft

Who is online

Users browsing this forum: No registered users and 2 guests