Board index FlightGear Support Hardware

Joystick XML - Set rate of change instead of absolute value

Joysticks, pedals, monitors.

Joystick XML - Set rate of change instead of absolute value

Postby poinu » Tue Oct 24, 2017 10:28 pm

Hi!

I'm looking forward to configure a joystick axis in order to set the property change ratio as opposed to setting its absolute value directly. The idea behind this is to be able to achieve smooth precise adjustments on a given property.

Let me use an example to clarify:
Imagine that you want to map the "pitch" axis of your joystick to the "vertical view" property. If you mapped the property directly using the 'property-scale' command, releasing the stick would make the "vertical view" go back to "default position", as the joystick would return to the axis center position. Instead, imagine you want this "pitch" axis to control the "vertical view" movement ratio: Pushing the stick a 50% would make the view go up, for instance, 1 unit per second, while pushing it 100% would make the view go up at 2 units per second ratio. In that fashion, releasing the stick would make the view to stay still (at the current value) and pulling it a 25% would make the view go down 0.5 units per second, just to say something.

I've tried to achieve a similar behaviour using the following nasal binding (following the pitch - vertical view example):

Code: Select all
    <axis n="1">                                   
        <desc>Vertical view</desc>                                                   
        <binding>                                                               
            <command>nasal</command>                                           
            <script>                                                           
                var input_value = cmdarg().getNode("setting").getValue();       
                var step = 2.0;                                                 
                var value = getprop("/sim/current-view/goal-pitch-offset-deg") + input_value*step;
                setprop("/sim/current-view/goal-pitch-offset-deg", value);       
            </script>                                                           
        </binding>                                                             
    </axis>                                                                     


The previous code has in mind the idea of "change ratio" but it has an important issue: The nasal code is only called once for each different value the axis takes. That is, if you push the stick to 50% and hold it there steadily, the 'setprop' function will only be called once, and this makes it unusable for this purpose.

For me, this is somehow related to repeatable buttons, I would like to be able to specify that an axis is "repeatable", meaning that the binding should be called more than one time for a given value.

Is there any way to achieve this kind of behaviour?

I haven't been able to find any post/XML configuration trying to achieve the same, but maybe I'm just using the wrong keywords.
In any case, I would really appreciate any help!

PS. This might seem a weird question, but just think of how movement/camera are controlled when using a video game console controller analog joysticks. :wink:
poinu
 
Posts: 8
Joined: Sat Sep 30, 2017 4:57 pm
Version: 2017.3.1
OS: Linux

Re: Joystick XML - Set rate of change instead of absolute va

Postby Isaak » Wed Oct 25, 2017 11:58 am

This sounds very interesting. I have no idea how to do this, but I 'm curious about a possible solution.
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: Joystick XML - Set rate of change instead of absolute va

Postby sim » Wed Oct 25, 2017 6:39 pm

imagine you want this "pitch" axis to control the "vertical view" movement ratio: Pushing the stick a 50% would make the view go up, for instance,


If by "view movement ratio" you mean "rate of change of view movement" then slewprop is the property that fits the bill.
the slewprop works by utilizing another named axis. For example my AV8R-01 joystick has two throttles, the first is windows axis No 2 and the second throttle is axis No 4. Since the second axis is spare (unless I require it to run twin engines) then it can be named as slewprop [4] in any other axis that moves my view. Then for example viewpanpitch is controlled by my windows HAT axis 7 fore and aft movement. Pushing HAT forward does nothing until throttle 2 ( axis]4] ) is eased forward, then view movement will
pan downward slowly at first then faster as throtte 4 is advanced further.

Although I control many views on several other axes where slewprop controls rate of view change:
Here is the way I have HAT axis 7 configured
Code: Select all
<axis n="7"> <desc>HAT 02-VERTVIEW Fas-Slo,  13-Elevator Trim, 4 Y-ax Fas, 5 Y-ax Slo/LandLights 135-FlapsUp</desc>
 <low> <repeatable>true</repeatable> <binding> <command>nasal</command> <script>
 m = get_mode(); if (m == 0) {view.panViewPitch(1-getprop("input/joysticks/js[0]/axis[4]/binding/setting"));}
elsif (m == 1){controls.elevatorTrim(-0.75);} elsif (m == 2)
{view.panViewPitch(1-getprop("input/joysticks/js[0]/axis[4]/binding/setting"));} elsif (m == 3)
{controls.elevatorTrim(-0.75);} elsif (m == 4)
{setprop("/sim/current-view/y-offset-m", getprop("/sim/current-view/y-offset-m") + (1 - getprop("input/joysticks/js[0]/axis[4]/binding/setting"))/10);} elsif (m == 5) {setprop("/sim/current-view/y-offset-m", 5 + getprop("/sim/current-view/y-offset-m"));} </script> </binding> </low>
 
<high> <repeatable>true</repeatable> <binding> <command>nasal</command> <script>
 m = get_mode(); if (m == 0) {view.panViewPitch(-(1-getprop("input/joysticks/js[0]/axis[4]/binding/setting")));}
elsif (m == 1) {controls.elevatorTrim(0.75); } elsif (m == 2)
{view.panViewPitch(-(1-getprop("input/joysticks/js[0]/axis[4]/binding/setting")));} elsif (m == 3)
{controls.elevatorTrim(0.75);} elsif (m == 4)
{setprop("/sim/current-view/y-offset-m", getprop("/sim/current-view/y-offset-m") - (1 - getprop("input/joysticks/js[0]/axis[4]/binding/setting"))/10);} elsif (m == 5)
{setprop("/sim/current-view/y-offset-m", -10 + getprop("/sim/current-view/y-offset-m"));}</script>
 </binding> </high> </axis>
.
You may need a little help to extract the essential slewprop codes from the 6 modifier states and the nose up/down trim controls!
Untested but bare bones should look something like:
Code: Select all
<axis n="7"> <desc>HAT VERTVIEW Fas-Slo</desc>

<low> <repeatable>true</repeatable> <binding> <command>nasal</command> <script>
{view.panViewPitch(1-getprop("input/joysticks/js[0]/axis[4]/binding/setting"));} </script> </binding> </low>
 
<high> <repeatable>true</repeatable> <binding> <command>nasal</command> <script>{view.panViewPitch(-(1-getprop("input/joysticks/js[0]/axis[4]/binding/setting")));}</script>
 </binding> </high> </axis>

And poinu you may not have a spare throttle axis and decide to try using whatever spare axis you do have and will have to change the slewprop code from axis[4] to whatever axis you wish to use to control the speed of view movement..
User avatar
sim
 
Posts: 1431
Joined: Tue Jun 30, 2009 3:13 pm
Location: Shropshire England
Callsign: Fly4Fun
Version: 0.9.10 up
OS: 64 Win 10 HD6450

Re: Joystick XML - Set rate of change instead of absolute va

Postby poinu » Mon Oct 30, 2017 8:32 pm

Hi sim!

Thanks for the answer and apologies for the delayed reply, I've busy lately...

I've been testing your code and I thought it was a great idea when it comes to control the rate of change of a given axis, but unfortunately it's not quite what I was looking for :(

I feel that my initial post was perhaps a bit confusing, so instead of my first explanation, just think of how the controls work when you are playing your favorite action game in Playstation (or whichever platform you prefer!):

In those kind of games, the left stick usually controls the character movement in the following way: If you slightly move it towards a direction (keeping it close to the center), the character will start walking in that given direction. If you then move it further towards that direction, the character will start walk faster and finally start running. In short, the speed (rate of change) of the character is given by "how far" the stick is pushed from the center. The camera is usually controlled by the right stick in a similar fashion.

I'm looking forward to achieve that kind of movement, which doesn't require any spare axis to adjust it.

Hopefully this time is a bit more clear than in the first post, but English is not my first language, so please don't hesitate to ask for further clarification!

P.S. Thanks for the idea of controlling the rate of change using an spare axis, I might be using it soon for other stuff :mrgreen:
poinu
 
Posts: 8
Joined: Sat Sep 30, 2017 4:57 pm
Version: 2017.3.1
OS: Linux

Re: Joystick XML - Set rate of change instead of absolute va

Postby sim » Mon Oct 30, 2017 11:42 pm

So poinu,
(1) your walking figure's direction is from 0 to 360 degrees dependant on direction stick is moved.
Presume that stick direction code is already working?

(2) Walking figure stands still when stick is neutral then progressively increases pace as stick moves further away from neutral point. Attaining maximum speed at full stick deflection.

Simply reference the SlewProp code to the same axis?

You will need to derive value "0" at stick neutral and value "1" at full stick deflection to feed SlewProp code.

Not sure it will be that simple so Good Luck :wink: !
User avatar
sim
 
Posts: 1431
Joined: Tue Jun 30, 2009 3:13 pm
Location: Shropshire England
Callsign: Fly4Fun
Version: 0.9.10 up
OS: 64 Win 10 HD6450

Re: Joystick XML - Set rate of change instead of absolute va

Postby poinu » Thu Nov 02, 2017 1:12 pm

sim wrote in Mon Oct 30, 2017 11:42 pm:(1) your walking figure's direction is from 0 to 360 degrees dependant on direction stick is moved.
Presume that stick direction code is already working?


I don't think you actually need any "code" to have this working. The stick is presented by the joystick driver as two separate axis, so you would simply map one of those axis to the vertical movement and the other to the horizontal movement. In that case, I don't think you need to worry about the direction as it's implicitly computed. (maybe I didn't understand your point (?)).

sim wrote in Mon Oct 30, 2017 11:42 pm:Simply reference the SlewProp code to the same axis?


The problem using the SlewProp scheme you showed us in the previous post is that the code is only executed at full stick deflection due to the <low> and <high> tags. This could be easily fixable if you bind the axis directly to the property (see the code I posted in the first post). But then, one would still have the problem that the code is only executed whenever the value of the bound axis changes, and that would mean that steadily holding the stick at some (non-neutral) point would make the figure stand still.
poinu
 
Posts: 8
Joined: Sat Sep 30, 2017 4:57 pm
Version: 2017.3.1
OS: Linux

Re: Joystick XML - Set rate of change instead of absolute va

Postby sim » Thu Nov 02, 2017 7:27 pm

The problem using the SlewProp scheme you showed us in the previous post is that the code is only executed at full stick deflection due to the <low> and <high> tags.


Searched through the view scripts on my AV8R-01 xml but other view scripts without <high> <low> markers use buttons not axes. The <high> <low> markers on axes 6 and 7 in my original codebox use HAT switch which is of course not a true "axis"
but makes HAT work as 4 way toggle switch! Not much help! .

The stick is presented by the joystick driver as two separate axis

Sounds like elevator and aileron axes in Flightgear. So the stick controlling the walker probably incorporates 2 axes too. With different scripts these axes could by cross-referenced to read direction and distance to control a walker. Speed of walker controlled by distance stick is from neutral position. In Flightgear position on a flat surface is determined by offset-x and offset-z. Similar to GPS fix using LATITUDE & LONGITUDE Flightgear uses X and Y coordinates to determine position with respect to neutral (0 0 reading with stick centralised).
Aileron and Elevator axes both read *0" at neutral stick position and "1" at extreme stick movement then "-1" at opposite extremity. and Z axis operates at 90 degrees to X axis just as LAT & LONG coordinates do. Quite how Z and X coordinates are interpreted into direction from zero neutral position and also into distance (distance then used to control speed) from that position and written into xml script is too challenging for me but other folk on this forum may be able to do it! :roll:
User avatar
sim
 
Posts: 1431
Joined: Tue Jun 30, 2009 3:13 pm
Location: Shropshire England
Callsign: Fly4Fun
Version: 0.9.10 up
OS: 64 Win 10 HD6450

Re: Joystick XML - Set rate of change instead of absolute va

Postby poinu » Mon Nov 06, 2017 1:07 pm

I think it wouldn't be too dificult to obtain the direction and distance from the axis "raw" values (from -1 to 1, being 0 the neutral), as you suggest.
The only problem I don't really know how to tackle is about how to "continuously" run a piece of code (or xml property) even if the axis value remains unchanged (sort of what is done in repeatable buttons, whose code is called every "timestep" while the button is pushed). For now, I have only achieved "executing the code" if the axis value changes or the stick is moved to one of the extremes (with <high> and <low> tags).

Thanks one more time for your answers, sim :)
poinu
 
Posts: 8
Joined: Sat Sep 30, 2017 4:57 pm
Version: 2017.3.1
OS: Linux

Re: Joystick XML - Set rate of change instead of absolute va

Postby Thorsten » Mon Nov 06, 2017 5:18 pm

The only problem I don't really know how to tackle is about how to "continuously" run a piece of code (or xml property) even if the axis value remains unchanged


If I understand correctly, what you want is commonly known as an integrator, and this is available as a property rule - see the AP configuration reference for how to set this up.

(The integrator reads in for instance the velocity and outputs the position, i.e. if you leave velocity a constant position increments at constant rate, or if you zero velocity position stays where it is).
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Joystick XML - Set rate of change instead of absolute va

Postby poinu » Mon Nov 06, 2017 10:05 pm

Following Throsten's advice, I've come up with the following (prototype) filter:

Code: Select all
    <filter>                                                                   
        <name>view control</name>                                             
        <type>integrator</type>                                                 
        <gain>1.0</gain>                                                       
        <input>                                                                 
            <property>/input/joysticks/js/axis[1]/binding/setting</property>                   
        </input>                                                               
        <output>                                                               
            <property>/sim/current-view/goal-heading-offset-deg</property>     
        </output>                                                               
    </filter>                                                                   


This should do the trick (for a single axis). However, I haven't been able to make it work.

When I insert this code into the <PropertyList> tag of my joystick XML, a new /input/joysticks/js/filter branch appears into the property tree. That being said, I don't know what else needs to be done to "enable" the filter so that it actually computes something.

Is there any place where I can be referred to learn about this? I've been looking the AP configuration page, but I couldn't figure it out :P
poinu
 
Posts: 8
Joined: Sat Sep 30, 2017 4:57 pm
Version: 2017.3.1
OS: Linux

Re: Joystick XML - Set rate of change instead of absolute va

Postby Thorsten » Tue Nov 07, 2017 8:40 am

Well, it doesn't go into the joystick configuration, it has to be loaded as property rule under /sim/systems as explained in the already mentioned Autopilot configuration reference
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Joystick XML - Set rate of change instead of absolute va

Postby poinu » Tue Nov 07, 2017 6:50 pm

Correct me if I'm wrong, but aren't the property rules under /sim/systems relative to each of the installed aircrafts? If possible, I'm rather interested in a, somehow, portable solution, so that I don't need to add those new properties for every new aircraft I want to try out :? . I also think a portable solution would be easier to share to the rest of the community :)
poinu
 
Posts: 8
Joined: Sat Sep 30, 2017 4:57 pm
Version: 2017.3.1
OS: Linux

Re: Joystick XML - Set rate of change instead of absolute va

Postby Thorsten » Tue Nov 07, 2017 7:39 pm

No, sim/systems is relative to the aircraft, but /sim/systems is FG-wide. You can take a look into how property rules are read in by defaults.xml for instance - you have to add yours in the same way.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Joystick XML - Set rate of change instead of absolute va

Postby wkitty42 » Tue Nov 07, 2017 9:36 pm

just to clarify Thorsten's statement... there is a leading '/' on one of those but not the other... the property tree works just like directories on a hard drive... you can work absolute from the root '/' or you can work relative from the craft...
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 9148
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 20.04

Re: Joystick XML - Set rate of change instead of absolute va

Postby poinu » Wed Nov 15, 2017 12:23 am

Thanks for the replies, and sorry for the delay...! I struggle to find time for my hobbies lately...

I understand the difference between absolute and relative paths in the Property Tree. However, I'm not able to get the configuration files properly detected yet.

I'm running FlightGear as follows:
Code: Select all
fgfs --launcher --config=<$FG_HOME>/my-config.xml

And these are the configuration files I have so far:

$FG_HOME/my-config.xml
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>                                         
                                                                               
<PropertyList>                                                                 
    <sim>                                                                       
        <systems>                                                               
            <property-rule n="150">                                             
                <name>My properties</name>                                     
                <path>Systems/my-properties.xml</path>                     
            </property-rule>                                                   
        </systems>                                                             
    </sim>                                                                     
</PropertyList>

$FG_HOME/Systems/my-properties.xml
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>                                         
                                                                               
<PropertyList>                                                                                                                                           
    <foo type="int">1</foo>                                                     
    <bar type="int">1</bar>                                                     
                                                                               
    <filter>                                                                   
        <name>Myfilter</name>                                                   
        <debug>true</debug>                                                     
        <input>/foo</input>   <!-- should it be "foo"? -->
        <output>/bar</output> <!-- should it be "bar"? -->                                                 
    </filter>                                                                   
</PropertyList>

$FG_HOME/my-config.xml gets properly detected once I launch FlightGear, but I can see the following error on the terminal:

Code: Select all
Cannot find property-rule configuration file 'Systems/my-properties.xml'.

I have tried moving the my-properties.xml file to the same directory as my-config.xml, and changing the option to <path>my-properties.xml</path>, but that didn't work. I also tried moving the file to the Aircraft directory subsystem, but I couldn't make it work either.

From what I understand from the wiki (http://wiki.flightgear.org/Resolving_Paths), $FG_HOME is a low-priority (but valid) location to place my configurations. What am I doing wrong? :?
poinu
 
Posts: 8
Joined: Sat Sep 30, 2017 4:57 pm
Version: 2017.3.1
OS: Linux


Return to Hardware

Who is online

Users browsing this forum: No registered users and 5 guests