Board index FlightGear Support Hardware

Map axis to view direction?

Joysticks, pedals, monitors.

Map axis to view direction?

Postby D-ECHO » Sat Jan 06, 2018 10:19 am

Hello!
I'd like to map my throttle's hat (consists of two axis for vertical and horizontal move) to the view direction, so adjusting
Code: Select all
/sim/current-view/goal-heading-offset-deg
and
Code: Select all
/sim/current-view/goal-pitch-offset-deg
, at the moment I'm using the <low> and <high> bindings, but like this only move or no-move can be detected while I'd like to have the view moved more the more the hat is moved (the higher the axis value is). Unfortunately I'm not sure how this would be coded in the joystick file. Could someone give me a hint?
Regards
D-ECHO
User avatar
D-ECHO
 
Posts: 1512
Joined: Sat May 09, 2015 12:31 pm

Re: Map axis to view direction?

Postby sim » Sun Jan 07, 2018 1:21 pm

I'd like to have the view moved more the more the hat is moved (the higher the axis value is

You will not be able to do that unless your throttle hat switch is anologue.
Most joystick HAT switches have 8 directional positions but 4 will suffice for UP/DOWN and LEFT/RIGHT ( ViewPanPitch and ViewPanDir ) view movement.
If you test a HAT switch in js_demo you will normally get output readings of +1 and -1 at each HIGH or LOW point.
Reading will be zero in between!
Your Throttle axis on the other hand is quite likely to be true analogue with output values progressing smoothly up to 1
:wink:

I am able to speed up or slow down both the ViewPanPitch and ViewPanDir on my AV8R-01 joystick.
This is possible by utilizing a spare analogue axis and the slewprop property in the xml code for the HAT axis.
.
User avatar
sim
 
Posts: 1443
Joined: Tue Jun 30, 2009 2:13 pm
Location: Shropshire England
Callsign: Fly4Fun
Version: 0.9.10 up
OS: 64 Win 10 HD6450

Re: Map axis to view direction?

Postby D-ECHO » Sun Jan 07, 2018 4:48 pm

The hat actually is analogue :D
Image
(see the first two values assigned "custom")
User avatar
D-ECHO
 
Posts: 1512
Joined: Sat May 09, 2015 12:31 pm

Re: Map axis to view direction?

Postby sim » Sun Jan 07, 2018 9:37 pm

OK D-ECHO, Your HAT is analogue. I am impressed but not sure if it's possible to write a PanViewDir and PanViewPitch code where the speed of view movement is controlled by the intermediate readings on your analogue HAT axis. Also if it can be done the HAT axis with it's small physical range of movement will be unlikely to give the sort of fine control that can be achieved with for example a spare analogue throttle.
I had help on how to utilise the SlewProp property from Macnab and Philosopher as I am no expert myself on writing complicated xml code where the PanViewDir and PanViewPitch code contains refererence to SlewProp values fed in from the same axis. Hope that does not cause positive feedback problems and instability.
Hoffe es klappt. Viel Glück :wink:
User avatar
sim
 
Posts: 1443
Joined: Tue Jun 30, 2009 2:13 pm
Location: Shropshire England
Callsign: Fly4Fun
Version: 0.9.10 up
OS: 64 Win 10 HD6450

Re: Map axis to view direction?

Postby D-ECHO » Mon Jan 08, 2018 4:09 pm

Thank you very much sim :D Actually thought I was just missing an obvious possibility, didn't thought it was going to be more complicated, in this case I don't think it's worth spending too much time on it
User avatar
D-ECHO
 
Posts: 1512
Joined: Sat May 09, 2015 12:31 pm

Re: Map axis to view direction?

Postby sim » Mon Jan 08, 2018 8:55 pm

Here is the code for windows computer axis 6 panning view to left or to right. Speed of panning is controlled by Throttle No 2 windows axis [4] which is spare except when required for independent control of twin engine planes.
Note two modifier states 0 for panview and 1 for aileron trim.
You can remove modifier 1 if you don't need the HAT for aileron trim but if you don't use a modifier the code may work as currently written as default state 0 will presumably apply.
Wish to see if this code works for you? You can test it by disabling your normal throttle code (with <!--code--> arrows) and use keyboard as throttle. Your own Throttle axis No will need to be substituted in place of [4] which occurs twice!
Axis for ViewPanPitch will be the same code but change x-offset to y-offset and change axis No of course.
Code: Select all
<axis n="6">
 <desc>HAT PANVIEWDIR VAR SPEED</desc>
 <low>
 <repeatable>true</repeatable>
   <binding>
 <command>nasal</command>
 <script>m = get_mode();
 if (m == 0) {controls.slewProp("/sim/current-view/x-offset-m", (1 - getprop("input/joysticks/js[0]/axis[4]/binding/setting"))* 10);} elsif (m == 1)
{controls.aileronTrim(-0.75);}</script>
 </binding> </low>
 
<high>
 <repeatable>true</repeatable>
 <binding>
 <command>nasal</command>
 <script>
 m = get_mode();
 if (m == 0) {controls.slewProp("/sim/current-view/x-offset-m", (1 - getprop("input/joysticks/js[0]/axis[4]/binding/setting"))* -10);} elsif (m == 1)
{controls.aileronTrim(0.75); }</script>
 </binding> </high> </axis>

PS "Didn't Thought" does not work in xml code or in English. "Hadn't Thought" or "Didn't Think" is ok
No idea what will happen if :idea: you accidentally substitute [4] with your own HAT axis number ! :wink:
User avatar
sim
 
Posts: 1443
Joined: Tue Jun 30, 2009 2:13 pm
Location: Shropshire England
Callsign: Fly4Fun
Version: 0.9.10 up
OS: 64 Win 10 HD6450

Re: Map axis to view direction?

Postby D-ECHO » Wed Jan 10, 2018 5:04 pm

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

Re: Map axis to view direction?

Postby panash » Sun Feb 11, 2018 6:34 pm

I'm struggling with this big time as well.

I'm using vJoy just to emulate a joystick and, although the axis aren't mapped properly, you can work out pretty easily which axis you are varying.

I must have been through all the forums and tried every single combination of joystick.xml file & nasal snippet and got it to click through 30 degrees at a time. Before I actually start posting code snippets let's just step back and ask "how do you associate a joystick axis with a control in the joystick control GUI? For example how would I associate a joystick axis with something that isn't in the GUI like head roll. There is only "view(horizontal)" and "view(vertical)". How do you put or find "view(roll)" in the GUI for example? Or "X" offset?

setprop("/sim/current-view/x-offset-m", getprop("/sim/view/config/x-offset-m"));

Please answer this question in general - not specifically.

Example snippet copied from
viewtopic.php?f=36&t=16052 (head tracking is the ultimate objective)

<name>vJoy Device</name>
<axis n="0">
<desc>6DOFYaw</desc>
<binding>
<command>property-scale</command>
<property>/sim/current-view/goal-heading-offset-deg</property>
<factor type="double">180.0</factor>
</binding>
</axis>

I stress I'm trying to bind an axis to a view in a continuous way, NOT a button or key.
panash
 
Posts: 23
Joined: Thu Oct 30, 2014 3:02 pm

Re: Map axis to view direction?

Postby sim » Mon Feb 12, 2018 8:51 pm

how do you associate a joystick axis with a control in the joystick control GUI?


Sorry Panash Can't help you with using GUI to set joystick axes/buttons or mess up my joystick settings, which is likely if I ever tried to use the GUI joystick settings! I have never used GUI as I suspect it would simply work against the axis/button codes in my AV8R-01 joystick.xml file.
You don't need the GUI to fettle any joystick. All you need to do is write each axis/button code yourself or copy codes from other joysticks in Flightgear/Data/input/joysticks folder. :wink:
User avatar
sim
 
Posts: 1443
Joined: Tue Jun 30, 2009 2:13 pm
Location: Shropshire England
Callsign: Fly4Fun
Version: 0.9.10 up
OS: 64 Win 10 HD6450

Re: Map axis to view direction?

Postby panash » Mon Feb 12, 2018 9:22 pm

I thought it must be something like this as the GUI is rarely talked about. Unfortunately I can't try anything until the weekend as I'm away from home and my laptop isn't man enough to run FG.

Does FG simply by-pass the GUI unless you open it? Does simply opening the GUI re-assign the bindings? I take it that you never open the GUI?

Presumably one can check the binding by looking at the back of the plane using an external view?
panash
 
Posts: 23
Joined: Thu Oct 30, 2014 3:02 pm

Re: Map axis to view direction?

Postby wkitty42 » Tue Feb 13, 2018 2:45 pm

there are default joystick xml files that are compared to your equipment... if a match is found, it is loaded from the defaults... if you make changes to button or axis assignments (via the GUI), the default file is copies to $FGHOME/Input/Joysticks with the same name and the changes... then when the sim is loaded, it also looks in $FGHOME for matching xml files... if there are any, they are used instead of the default xml files...

opening the input GUI will load the custom xml for the equipment from $FGHOME/Input/Joysticks OR it will open the default xml if a custom one does not exist... it is possible that the GUI might strip out some option code in a manually written custom xml because the GUI simply doesn't know what it is and it doesn't fit its template...
"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: 5644
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: Map axis to view direction?

Postby sim » Tue Feb 13, 2018 11:38 pm

Does simply opening the GUI re-assign the bindings?

No!

I take it that you never open the GUI?

To set joystick characteristics and assign what each button or axis does, no never!
I would regard anyone doing that as a beginner in a hurry to fly Flightgear without having found the correct joystick.xml or better still customizing their own xml to suit their particular joystick and their own style of flying!

very much the latter in my case as I like to fly by the seat of my pants! :)
User avatar
sim
 
Posts: 1443
Joined: Tue Jun 30, 2009 2:13 pm
Location: Shropshire England
Callsign: Fly4Fun
Version: 0.9.10 up
OS: 64 Win 10 HD6450

Re: Map axis to view direction?

Postby panash » Thu Feb 15, 2018 11:14 am

mmmm - something that's not made clear
panash
 
Posts: 23
Joined: Thu Oct 30, 2014 3:02 pm

Re: Map axis to view direction?

Postby wkitty42 » Thu Feb 15, 2018 3:24 pm

what is not made clear, panash?
"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: 5644
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: Map axis to view direction?

Postby panash » Thu Feb 15, 2018 3:33 pm

how the GUI interacts with the XML binding files
panash
 
Posts: 23
Joined: Thu Oct 30, 2014 3:02 pm

Next

Return to Hardware

Who is online

Users browsing this forum: No registered users and 11 guests