Board index FlightGear Support Hardware

Example of getting the raw value from axis in Nasal

Joysticks, pedals, monitors.

Example of getting the raw value from axis in Nasal

Postby vanosten » Sat Aug 25, 2018 10:43 am

Hi

I would like to be able t manipulate the "scale" of my throttle axis such that values between 0.0 to 0.7 are proportionally calculated up to the threshold of afterburner (ca. 0.9 in the F14B), then from 0.7 to 0.8 keep the value stable ("deadband") and then > 0.8 afterburner (stages depending on jet).

I know that I can get the value from props /controls/engines/engine[..]/throttle, but that is due to currently doing
Code: Select all
      <binding>
         <command>nasal</command>
         <script>controls.throttleAxis()</script>
      </binding>


I would like to manipulate as above the raw value from the throttle axis before assigning to a property. But: how can I get this raw value, such that I can do some maths in nasal and then set the property?
Maintaining osm2city. Contributing with ground attack stuff to the OPRF FlightGear military-simulation community.
vanosten
 
Posts: 540
Joined: Sat Sep 25, 2010 6:38 pm
Location: Denmark - but I am Swiss
Pronouns: he/his
Callsign: HB-VANO
Version: latest
OS: Win 10 and Ubuntu

Re: Example of getting the raw value from axis in Nasal

Postby Thorsten » Sat Aug 25, 2018 11:40 am

Since this is to be processed by the FDM, I assume a JSBSim table would be best?

The point is that you probably move the physical throttle linearly forward (which is what /controls/engines/engine/... stands for) but you want the engine to give a non-linear response to that movement - so you don't need to change the control position, you need to change the engine input.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Example of getting the raw value from axis in Nasal

Postby vanosten » Sat Aug 25, 2018 12:24 pm

Maybe I do not understand, but I do not think so.

As a pilot I would to be able to [A] use a primitive throttle without hardware clicks as if it had (because I do not want e.g. to go into afterburner without knowing) - i.e. using throttle "distance" and my own placed "deadzones" as proxies, and [B] I want to be able to do so far different jets (e.g. F14B vs Viggen) which have a different amount of AB stages and different thresholds for where the AB starts relative to /controls/engines/engine. I.e. I want to be able to do so in my joystick configuration vs bothering the aircraft authors. And therefore I guess instead of binding /controls/engines/engine indirectly through controls.throttleAxis() to joystick binding-magic, I would rather be able to get the raw axis value, manipulate the value and the on my own set the /controls/engines/engine, which then is interpreted by the FDM.
Maintaining osm2city. Contributing with ground attack stuff to the OPRF FlightGear military-simulation community.
vanosten
 
Posts: 540
Joined: Sat Sep 25, 2010 6:38 pm
Location: Denmark - but I am Swiss
Pronouns: he/his
Callsign: HB-VANO
Version: latest
OS: Win 10 and Ubuntu

Re: Example of getting the raw value from axis in Nasal

Postby vanosten » Sat Aug 25, 2018 12:37 pm

Oh, I found out by chance:

Code: Select all
      <binding>
         <command>nasal</command>
         <script>
            var input_value = cmdarg().getNode("setting").getValue();
            gui.popupTip(sprintf("Throttle raw: %.2f", input_value));
            controls.throttleAxis();
         </script>



I still need to manipulate the value, but at least I get the value. (Why do I find stuff after having asked a question?! sorry)
Maintaining osm2city. Contributing with ground attack stuff to the OPRF FlightGear military-simulation community.
vanosten
 
Posts: 540
Joined: Sat Sep 25, 2010 6:38 pm
Location: Denmark - but I am Swiss
Pronouns: he/his
Callsign: HB-VANO
Version: latest
OS: Win 10 and Ubuntu

Re: Example of getting the raw value from axis in Nasal

Postby Thorsten » Sat Aug 25, 2018 12:47 pm

Sorry, only in hindsight it becomes clear to me that this is a question about joystick calibration - it's not very explicit from the way you asked it...

(Yeah, I might have seen the subforum title, but I came across it using 'active topics'...)
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Example of getting the raw value from axis in Nasal

Postby WoodSTokk » Sat Aug 25, 2018 10:19 pm

You can pull in a second control layer.
I use on the Citation II three properties for throttle.

throttle-lever -> this value hold the actual position of the lever in the cockpit
throttle -> thats the raw value
throttle-real -> thats the output value that the FDM recieve and work

The same goes on for the reverser.
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: Example of getting the raw value from axis in Nasal

Postby Richard » Wed Aug 29, 2018 5:46 pm

This is the code from my logitech-3d XML file.

Basically what I do is to assign two buttons to allow split throttles (you can remove this part, it's here in case you want it).

Upto 50% throttle is MIL, and the rest afterburner. This file is a bit specific for the F-14, but it will work with other craft, maybe a bit strangely for non augmented engines.

Code: Select all
  <axis n="2">
    <desc type="string">Throttle (all)</desc>
      <binding>
        <command type="string">nasal</command>
        <script type="string">
            <![CDATA[
                tempv = cmdarg().getNode("setting").getValue();
                tempv = (1 - tempv) / 2;
                deadzone=0.0;

                # numbers for the F-14:
                # mil = 0.9172

                if (tempv < 0.5) # midway is mil
                     vv = tempv / 0.545137375;
                else if (tempv < 0.6)
                     vv = 0.9172;
                else vv = 0.9172 + (tempv - 0.6)*0.207;

                v1 =vv;
                #print("throttle",tempv,": ",v1," -> ",vv);
                #
                # this uses the two buttons on the joystick (next to the throttle control)
                # to allow independent control of the engines. The lower button toggles the left engine
                # and the upper the right engine
                if (getprop("/controls/engines/engine[0]/active") == nil)
                    setprop("/controls/engines/engine[0]/active",1);
                if (getprop("/controls/engines/engine[1]/active") == nil)
                    setprop("/controls/engines/engine[1]/active",1);

                setprop("/controls/engines/throttle-dmd",vv);

                if (getprop("/controls/engines/engine[0]/active"))
                    setprop("/controls/engines/engine[0]/throttle", vv);

                if (getprop("/controls/engines/engine[1]/active"))
                    setprop("/controls/engines/engine[1]/throttle", vv);
            ]]>
        </script>
    </binding>
  </axis>


    <button n="10">
        <desc type="string">LeftThrottle Toggle</desc>
        <repeatable type="string">false</repeatable>
        <binding>
            <command>property-toggle</command>
            <property>/controls/engines/engine[0]/active</property>
        </binding>
        <binding>
            <command type="string">nasal</command>
            <script type="string">
                <![CDATA[
                    if (getprop("/controls/engines/engine[0]/active"))
{
#setprop("/controls/engines/engine[0]/throttle", getprop("/controls/engines/throttle-dmd"));
                    gui.popupTip("Left Engine Control Active");
}
else
                    gui.popupTip("Left Engine Control Inactive");
                    if (getprop("/controls/engines/engine[0]/active"))
                    setprop("/controls/engines/engine[0]/throttle", getprop("/controls/engines/throttle-dmd"));
]]>
            </script>
        </binding>
    </button>
    <button n="11">
        <desc type="string">Right Throttle Toggle</desc>
        <repeatable type="string">false</repeatable>
        <binding>
            <command>property-toggle</command>
            <property>/controls/engines/engine[1]/active</property>
        </binding>
        <binding>
            <command type="string">nasal</command>
            <script type="string">
                <![CDATA[

if (getprop("/controls/engines/engine[1]/active"))
{
#setprop("/controls/engines/engine[1]/throttle", getprop("/controls/engines/throttle-dmd"));
                    gui.popupTip("Right Engine Control Active");
}
else
                    gui.popupTip("Right Engine Control Inactive");
                    if (getprop("/controls/engines/engine[1]/active"))
setprop("/controls/engines/engine[1]/throttle", getprop("/controls/engines/throttle-dmd"));
]]>
            </script>
        </binding>
    </button>
Richard
 
Posts: 810
Joined: Sun Nov 02, 2014 11:17 pm
Version: Git
OS: Win10

Re: Example of getting the raw value from axis in Nasal

Postby Isaak » Wed Aug 29, 2018 9:07 pm

If it is still of any use, this is the script I use to arm/deploy the spoilers using a throttle lever on my Saitek Quadrant:

Code: Select all
   <axis>
    <name>Speedbrakes</name>
    <number>
     <unix>0</unix>
     <mac>0</mac>
     <windows>0</windows>
    </number>
      <desc type="string">Speedbrakes</desc>
      <binding>
      <command>nasal</command>
      <script>
      <![CDATA[
      var PSO = getprop("/controls/flight/speedbrake-lever");
      var SI = getprop("/devices/status/joysticks/joystick[2]/axis");
      if(SI < -0.90) {
       var SO = 0; #Speedbrakes down
      } elsif (SI < -0.75) {
       var SO = 1; #Speedbrakes armed
      } else {
       var SO = ((SI +2.5)/1.75); #speedbrakes deployed linear with the speedbrake lever
      }
      if (SO != PSO ) {
       setprop("/controls/flight/speedbrake-lever", SO);
      }
      ]]>
      </script>
      </binding>
  </axis>


PSO = previous speedbrake output (the current setting of the speedbrake itself)
SO = speedbrake output (the new/calculated setting of the speedbrake itself)
SI = the current setting of the speedbrake lever

Only if there's a difference between SO and PSO the speedbrake setting is modified, this to prevent that a slight movement/stutter of the lever when the speedbrakes are down results in the speedbrake lever clicking sound being triggerd :)
Want to support medical research with your pc? Start Folding at Home and join team FlightGear!
Isaak
 
Posts: 768
Joined: Sat Jun 04, 2011 3:52 pm
Location: Hamme, Belgium
Pronouns: he, him
Callsign: OO-ISA
Version: next
OS: Windows 10

Re: Example of getting the raw value from axis in Nasal

Postby vanosten » Fri Aug 31, 2018 7:12 pm

My throttle code is at the moment a bit more primitive than Richard's:
Code: Select all
var afterburnerStage = -1; # 0 means just before the first stage, -1 means outside

var setThrottle = func(rawValue) {
   var foo = 1.0 - rawValue;
   var foo = foo / 2;
   if (foo <= 0.9) {
      if (foo >= 0.7) {
         if (afterburnerStage == -1) {
            afterburnerStage = 0;
            gui.popupTip("Before afterburner");
         }
         foo = 0.9;
      } else {
         afterburnerStage = -1;
         foo = foo * 9 / 7;
      }
   }
    foreach(var e; controls.engines) {
        if(e.selected.getValue()) {
         setprop("/controls/engines/engine[" ~ e.index ~ "]/throttle", foo);
      }
    }
}
Maintaining osm2city. Contributing with ground attack stuff to the OPRF FlightGear military-simulation community.
vanosten
 
Posts: 540
Joined: Sat Sep 25, 2010 6:38 pm
Location: Denmark - but I am Swiss
Pronouns: he/his
Callsign: HB-VANO
Version: latest
OS: Win 10 and Ubuntu


Return to Hardware

Who is online

Users browsing this forum: No registered users and 5 guests