Board index FlightGear Support Hardware

Adjust the viewing with an axis

Joysticks, pedals, monitors.

Adjust the viewing with an axis

Postby Miko » Thu Jan 10, 2013 6:35 pm

Hello everybody,

some Joysticks have "Ministicks" built on them and it would be great if it's posible to adjust the view slow or fast depending on the movement of the axis.

But I don't get it working.

If I use property-scale command i just can look around and the view gets reseted after using the stick.
If i use property-adjust only on changes not reaching +-1.0 the view is moves a bit or when the stick value is +-1.0 the view moves with constant speed.
view.panViewDir don't gets arguments, so the screen is only moving when the stick reaches +-1.0 with constant speed.

Does anyone know how to solve the problem? I searched in the forum, wiki and in the web and didn't find anything.

I want something like this:
Stick is 0.0 on both axis: Nothing happens.
Stick is +x on X-axis: View changes in one direction (i.e. left) with speed +x*CONSTANT.
Stick is -x on X-axis: View changes in one direction (now right) with speed -x*CONSTANT.
Same on Y-Axis.

My goal is to control my view, fast and slow, in all scenarios, best smoothly, with the ministick. A solution would be great. I don't want to bind the viewing property to the stick, cause i want to stay the view when the stick is not used.

Greetings
Miko
Miko
 
Posts: 63
Joined: Tue Apr 22, 2008 7:24 pm
Location: Germany
OS: Debian

Re: Adjust the viewing with an axis

Postby Philosopher » Fri Jan 11, 2013 2:55 am

Hi Miko!

I bumped into this property while helping someone else with his bindings:

Code: Select all
<property>/sim/current-view/goal-pitch-offset-deg</property>


There's also a heading-offset for controlling the view left/right and probably a roll-offset which you will not need to use. Now the disclaimer: I'm not sure how well this works, though I am fairly confident in it. Anyways, the code for it should be fairly simple, something like this (just change the "prop" variable to "/sim/current-view/goal-heading-offset-deg" for the second axis):

Code: Select all
<script><![CDATA[
    var val = cmdarg().getNode("setting").getValue();
    var speed = 180; var deadband = 0.01;
    var prop = "/sim/current-view/goal-pitch-offset-deg";
    if (val <= deadband and val >= -deadband) return;
    # If we reached our limit, flip it around so we can keep going:
    if (getprop(prop) == 180 or getprop(prop) == -180)
        setprop(prop, -getprop(prop));
    if (val < 0)
        interpolate(prop, -180, speed/(getprop(prop) + 180));
    else
        interpolate(prop, 180, speed/(-getprop(prop) + 180));
]]></script>


The deadband variable is to prevent the view from drifting when you release the joystick, since flightgear might still read the value as something small. Speed is fairly self-explanatory, just that it will require tweaking on your end since it it probably on the fast side (or at least that is what my math says).

Tell me if something doesn't work,
Philosopher
Thanks,
Philosopher
(inactive but lurking occasionally...)
Philosopher
 
Posts: 1590
Joined: Sun Aug 12, 2012 6:29 pm
Location: Stuck in my head...
Callsign: AFTI
Version: Git
OS: Mac OS X 10.7.5

Re: Adjust the viewing with an axis

Postby sim » Fri Jan 11, 2013 9:47 pm

These demo vids show how versatile viewpoint movement can be in Flightgear. You won't find the scripts you need for your joystick in the WIKI either! You will find them in the xml LIBRARY at top of "hardware" topics page.
Cheers, :wink: sim

http://db.tt/zvvoSrP



Last edited by sim on Sun Jul 20, 2014 7:00 pm, edited 1 time in total.
User avatar
sim
 
Posts: 1329
Joined: Tue Jun 30, 2009 2:13 pm
Location: Shropshire England
Callsign: Fly4Fun
Version: 0.9.10 up
OS: 64 Win 10 HD6450

Re: Adjust the viewing with an axis

Postby macnab » Sat Jan 12, 2013 3:01 am

Regarding Philosopher's code:
I have been experimenting (and still am.)
1) The limits for heading is 140 either side. The limits for pitch is 90 either side.
2) These are "tied" values. The significance for this is that if you change heading-offset-deg to say, -90, within a second it changes to 270. If you then try to go to +90, it tries to go clockwise, and of course hits the limit of 220 (-140). After the interpolation runs out, it jumps to the correct setting.

It always tries to go clockwise, regardless of the start and end values. So one needs to step the value in the way the hat-switch does. ie with fgcommand.

I might look at it later, but I am too busy now.
macnab
 
Posts: 885
Joined: Tue Aug 02, 2011 7:20 am
Location: Johannesburg, South Africa
Callsign: ZS-ILH
Version: Git
OS: Win7Pro 64bit SP1

Re: Adjust the viewing with an axis

Postby Philosopher » Sat Jan 12, 2013 5:03 am

Thanks for the report macnab! But busy? I thought you were retired! ;)

Probably a better solution would be using the native view.panViewXxx() functions inside of a loop. Something like this:
Code: Select all
<script><![CDATA[
    var val = cmdarg().getNode("setting").getValue();
    var deadband = 0.01;
    if (val =< deadband and val >= deadband) pan_dir_active = 0;
    else pan_dir_active = 1;
]]></script>

And then add this to (or create) a <nasal><script> section near the top:
Code: Select all
var loop1 = func {
    if (!pan_dir_active) {settimer(loop1, 0); return;}
    #replace with the correct path to the axis you want to use:
    view.panViewDir(getprop("input/joysticks/js[0]/axis[0]/binding/setting")*0.5);
    #note that 0.5 is a speed setting you might want to adjust
    settimer(loop1, 0);
}

Repeat with different variable names for panViewPitch().

Apologies if this still doesn't work, I have been able to code in a while and views is not my area of expertise (though hacking joysticks is :D)
Thanks,
Philosopher
Thanks,
Philosopher
(inactive but lurking occasionally...)
Philosopher
 
Posts: 1590
Joined: Sun Aug 12, 2012 6:29 pm
Location: Stuck in my head...
Callsign: AFTI
Version: Git
OS: Mac OS X 10.7.5

Re: Adjust the viewing with an axis

Postby macnab » Sat Jan 12, 2013 5:56 am

That looks promising. Will "play" with it later. I like the concept of using axes this way, even though I don't have an available one.

BTW There is a difference between being retired and being idle. :)
macnab
 
Posts: 885
Joined: Tue Aug 02, 2011 7:20 am
Location: Johannesburg, South Africa
Callsign: ZS-ILH
Version: Git
OS: Win7Pro 64bit SP1

Re: Adjust the viewing with an axis

Postby sim » Sat Jan 12, 2013 11:56 am

Both these codes below will pan view to left or right. Change "Dir" or "heading" to "pitch" to pan view up or down. Interesting but not much help probably.
Either code seems to meet the criteria you ask Miko. Both pan your view at constant speed and
stop the view where it is on releasing the HAT button. You can adjust the speed by making 0.5 bigger or smaller. You could have a two speed system using a modifier. Be nice if there was a seperate way of adjusting the speed of panning view by controlling the 0.5 value smoothly up and down using another button (or ministick). Anyone have the answer how that might be done? Is that what Miko is seeking?
:idea: Seems it is, always a bit slow catching on!



Code: Select all
<axis n="6"> <low> <repeatable>true</repeatable> <binding> <command>nasal</command> <script> view.panViewDir(0.5);</script> </binding> </low>
<high> <repeatable>true</repeatable> <binding> <command>nasal</command> <script> view.panViewDir(-0.5);</script> </binding> </high> </axis>


Code: Select all
<axis n="6"> <low> <repeatable>true</repeatable> <binding> <command>nasal</command> <script> setprop("/sim/current-view/goal-heading-offset-deg", 0.5 + getprop("/sim/current-view/goal-heading-offset-deg"));</script> </binding> </low>
<high> <repeatable>true</repeatable> <binding> <command>nasal</command> <script>setprop("/sim/current-view/goal-heading-offset-deg", -0.5 + getprop("/sim/current-view/goal-heading-offset-deg"));</script> </binding> </high> </axis>
Last edited by sim on Sat Jan 12, 2013 2:16 pm, edited 4 times in total.
User avatar
sim
 
Posts: 1329
Joined: Tue Jun 30, 2009 2:13 pm
Location: Shropshire England
Callsign: Fly4Fun
Version: 0.9.10 up
OS: 64 Win 10 HD6450

Re: Adjust the viewing with an axis

Postby macnab » Sat Jan 12, 2013 1:35 pm

@sim: He particularly wants a joystick to handle pan and pitch

I have been experimenting and this is what I have come up with - made a bot fancier.

At the top of the joystick.xml file
Code: Select all
<PropertyList>
  <name>Saitek Saitek Pro Flight Yoke</name>
  <name>Saitek Pro Flight Yoke</name>
  <nasal>
    <script>
      var joystickNum = 0;         # I used to have a joystick, and then got a yoke and pedals, so my property-browser has
                                           # js[0], js[1] and js[2]. The value will probably be 0 with most people.
      var panAxis = 4;                # Check in Debug-Browse Properties
      var panSpeed = 0.3;          # Change to suite your needs
      var pan_dir_active = 0;
      var pitchAxis = 3;
      var pitchSpeed = 0.4;         # Change to suite your needs
      var pitch_dir_active = 0;

      var axisDeadBand = 0.05;

      var panViewLoop = func {
         if (!pan_dir_active) {
           settimer(panViewLoop, 0);
           return
         }

         view.panViewDir(getprop("input/joysticks/js[" ~ joystickNum ~ "]/axis[" ~ panAxis ~ "]/binding/setting") * panSpeed);

         settimer(panViewLoop, 0);
      }

      var pitchViewLoop = func {
         if (!pitch_dir_active) {
           settimer(pitchViewLoop, 0);
           return
         }

         view.panViewPitch(getprop("input/joysticks/js[" ~ joystickNum ~ "]/axis[" ~ pitchAxis ~ "]/binding/setting") * pitchSpeed);

         settimer(pitchViewLoop, 0);
      }

      settimer(panViewLoop, 0);
      settimer(pitchViewLoop, 0);
   </script>
</nasal>


The code for pan is
Code: Select all
  <axis>
    <number>
       <unix>3</unix>
       <windows>4</windows>
    </number>
    <desc>Pan with Axis</desc>
    <binding>
      <command>nasal</command>
      <script>
        <![CDATA[
        var val = cmdarg().getNode("setting").getValue();
        if (math.abs(val) > axisDeadBand)
          pan_dir_active = 1
        else
          pan_dir_active = 0;
        ]]>
      </script>
    </binding>
  </axis>


The code for pitch is
Code: Select all
  <axis>
    <number>
       <unix>4</unix>
       <windows>3</windows>
    </number>
    <desc>Pitch with Axis</desc>
    <binding>
      <command>nasal</command>
      <script>
        <![CDATA[
        var val = cmdarg().getNode("setting").getValue();
        if (math.abs(val) > axisDeadBand)
          pitch_dir_active = 1
        else
          pitch_dir_active = 0;
        ]]>
      </script>
    </binding>
  </axis>


The axes numbers will depend on your joystick. Mine seem to be the Windows numbers in the joystick.xml and the Unix numbers in Browse Properties (and thus in panAxis and pitchAxis.)

EDIT: Fixed unmatched braces.
Last edited by macnab on Thu Jan 31, 2013 1:54 am, edited 1 time in total.
macnab
 
Posts: 885
Joined: Tue Aug 02, 2011 7:20 am
Location: Johannesburg, South Africa
Callsign: ZS-ILH
Version: Git
OS: Win7Pro 64bit SP1

Re: Adjust the viewing with an axis

Postby Miko » Sat Jan 12, 2013 1:40 pm

Hi,

thank you for all the example code. But tell me if I'm wrong, but the nasal commands will only be called if the axis is +1.0 or -1.0. For example +0.8 doesn't trigger the command. That's only happening with command property-*.

I want to change the speed of looking by the value of the axis.

Greetings
Miko
Miko
 
Posts: 63
Joined: Tue Apr 22, 2008 7:24 pm
Location: Germany
OS: Debian

Re: Adjust the viewing with an axis

Postby Philosopher » Sat Jan 12, 2013 1:46 pm

Wow macnab, that's a major cleanup! Looks pleasing to the eyes now (and mind). And yes, usually the index in the property browser is the windows number, but it's actually the order in which they appear in the file. That's why I have mine numbered very explicitly:
Code: Select all
<axis n="4">
    <number>
        <windows>3</windows>
        <linux>4</linux>
        <unix>4</unix>
    </number>
    <!--.....-->
</axis>


Thanks for the cleanup, macnab!

@Miko: Looking at the nasal code behind this, it will call it proportionally (like you want). We're you using <high> and <low> tags before? That would make it only trigger at -1.0 or 1.0, but the code uses a simple call to controls.slewProp() which entirely maintains the original number put in to view.panViewXxx()....
Thanks,
Philosopher
(inactive but lurking occasionally...)
Philosopher
 
Posts: 1590
Joined: Sun Aug 12, 2012 6:29 pm
Location: Stuck in my head...
Callsign: AFTI
Version: Git
OS: Mac OS X 10.7.5

Re: Adjust the viewing with an axis

Postby macnab » Sat Jan 12, 2013 1:49 pm

No, the speed depends on the joystick deflection.

This
Code: Select all
view.panViewDir(getprop("input/joysticks/js[" ~ joystickNum ~ "]/axis[" ~ panAxis ~ "]/binding/setting") * panSpeed);


Can be written, in plain English as
Code: Select all
pan-the-view-direction-at-speed(joystick-deflection * panSpeed);


panSpeed is best adjusted by going to one end (with the stick moved to one end) and then slam the joystick over to the other end and see how fast it changes.
If you move the joystick just a tiny bit past center, the view pans s-l-o-w-l-y.
macnab
 
Posts: 885
Joined: Tue Aug 02, 2011 7:20 am
Location: Johannesburg, South Africa
Callsign: ZS-ILH
Version: Git
OS: Win7Pro 64bit SP1

Re: Adjust the viewing with an axis

Postby macnab » Sat Jan 12, 2013 1:53 pm

@Philosopher. I never thought of using n= and <windows>, <unix>, etc together. I thought they were mutually exclusive - must play a bit and see the effect.
macnab
 
Posts: 885
Joined: Tue Aug 02, 2011 7:20 am
Location: Johannesburg, South Africa
Callsign: ZS-ILH
Version: Git
OS: Win7Pro 64bit SP1

Re: Adjust the viewing with an axis

Postby sim » Sat Jan 12, 2013 2:33 pm

Interesting thought, As there is no ministick on my AV8R-01 and assuming you guys get this new "panspeed" facility up and running. AV8R-01 has 2 throttles so 2nd throttle axis could do fine control of "panspeed" ? :idea:
User avatar
sim
 
Posts: 1329
Joined: Tue Jun 30, 2009 2:13 pm
Location: Shropshire England
Callsign: Fly4Fun
Version: 0.9.10 up
OS: 64 Win 10 HD6450

Re: Adjust the viewing with an axis

Postby macnab » Sat Jan 12, 2013 2:51 pm

@sim. Completely different. But there is nothing to stop the 2nd throttle value being used as a speed control for the hat-switch. It means the hat-switch will need to call routines in the nasal section, but not a problem. I see you use 0.5 as the current speed, so I'll make it go from a dead crawl to 1.

In fact, you could operate the hat-switch with one hand and the "speed-control" with the other. (If physically possible with layout.)

I'll get to it tomorrow. Time to do supper now.

To make things easier for others who might like it, post a new thread asking for it. You can put in the post that I will be looking at it.

I like your idea and I like Miko's idea (it was fun trying it out), so I think I'll do a wiki for each.
macnab
 
Posts: 885
Joined: Tue Aug 02, 2011 7:20 am
Location: Johannesburg, South Africa
Callsign: ZS-ILH
Version: Git
OS: Win7Pro 64bit SP1

Re: Adjust the viewing with an axis

Postby sim » Sat Jan 12, 2013 3:39 pm

Thanks McNab, Maybe there might be a way of substituting a value link in place of the 0.5 within the button script?
<script>setprop("/sim/current-view/goal-heading-offset-deg", 0.5 + getprop("/sim/current-view/goal-heading-offset-deg"));</script>

That would be really useful as there are so many other view settings adjustable by the
"setprop + n getprop" formula. Apart from PanViewPitch and PanViewDir, substituting the same "throttle value" device could control the speed of view movement for x-offset-m (and y and z) and field of view! All currently used by my AV8R on various buttons.

HAT presently controls PanViewPitch and PanViewDir, aileron trim and elevator trim, x-offset-m and y-offset-m according to the modifiers set.
Last edited by sim on Sun Jan 13, 2013 4:50 pm, edited 1 time in total.
User avatar
sim
 
Posts: 1329
Joined: Tue Jun 30, 2009 2:13 pm
Location: Shropshire England
Callsign: Fly4Fun
Version: 0.9.10 up
OS: 64 Win 10 HD6450

Next

Return to Hardware

Who is online

Users browsing this forum: No registered users and 6 guests