It is currently Sat Oct 19, 2019 6:57 am



Reply to topic  [ 13 posts ] 
 GlovePIE to FreePIE script conversion 
Author Message
One Eyed Hopeful

Joined: Tue May 14, 2013 3:49 pm
Posts: 39
Reply with quote
Hi again,

I've been using the following GlovePIE script to map the mini joystick axis on my Logitech G940 as mouse (the Logitech profiler software allows mapping the mini-stick button as mouse button):

Code:
mouse.DirectInputX = mouse.DirectInputX + 30*deadzone(joystick.dial)
mouse.DirectInputY = mouse.DirectInputY + 30*deadzone(joystick.slider)


I'd like to convert this into its FreePIE equivalent so I can incorporate it into my Zeiss Cinemizer Headtracking script so I don't have to run both GlovePIE & FreePIE. Looked at all the examples but not quite sure what I should be using for this.

Regards

Mars


Sat Aug 17, 2013 3:48 am
Profile
Petrif-Eyed

Joined: Mon Jun 22, 2009 8:36 am
Posts: 2160
Location: Stockholm, Sweden
Reply with quote
Mars wrote:
Hi again,

I've been using the following GlovePIE script to map the mini joystick axis on my Logitech G940 as mouse (the Logitech profiler software allows mapping the mini-stick button as mouse button):

Code:
mouse.DirectInputX = mouse.DirectInputX + 30*deadzone(joystick.dial)
mouse.DirectInputY = mouse.DirectInputY + 30*deadzone(joystick.slider)


I'd like to convert this into its FreePIE equivalent so I can incorporate it into my Zeiss Cinemizer Headtracking script so I don't have to run both GlovePIE & FreePIE. Looked at all the examples but not quite sure what I should be using for this.

Regards

Mars


Something like this maybe? You will have to test with different values for deadZone and deltaFactor

Code:
if starting:
   deadZone = 10
   deltaFactor = 50

mouse.deltaX = filters.deadband(joystick[0].sliders[0], deadZone) / deltaFactor


Dial maybe is a slider[1] you will have to test, I do not have a joystick test with right now

_________________
FreePIE
My blog


Sat Aug 17, 2013 4:24 am
Profile
One Eyed Hopeful

Joined: Tue May 14, 2013 3:49 pm
Posts: 39
Reply with quote
Thanks!


Sat Aug 17, 2013 10:06 am
Profile
One Eyed Hopeful

Joined: Tue May 14, 2013 3:49 pm
Posts: 39
Reply with quote
The following works except the Y axis constantly drifts down and does not center after the ministick is used:

Code:
mouse.deltaX = filters.deadband(joystick[0].sliders[1], deadZone) / deltaFactor
mouse.deltaY = filters.deadband(joystick[0].sliders[0], deadZone) / deltaFactor


Tue Aug 20, 2013 3:45 pm
Profile
Petrif-Eyed

Joined: Mon Jun 22, 2009 8:36 am
Posts: 2160
Location: Stockholm, Sweden
Reply with quote
Mars wrote:
The following works except the Y axis constantly drifts down and does not center after the ministick is used:

Code:
mouse.deltaX = filters.deadband(joystick[0].sliders[1], deadZone) / deltaFactor
mouse.deltaY = filters.deadband(joystick[0].sliders[0], deadZone) / deltaFactor


increased deadzone? maybe you will have to have different deadzones for the two axis, if they differ to much in drift

edit: this worked perfect for my Logitech Rumblepad

Code:
if starting:
   deadZone = 100
   deltaFactor = 1000

mouse.deltaX = filters.deadband(joystick[0].x, deadZone) / deltaFactor
mouse.deltaY = filters.deadband(joystick[0].y, deadZone) / deltaFactor

_________________
FreePIE
My blog


Tue Aug 20, 2013 4:14 pm
Profile
One Eyed Hopeful

Joined: Tue May 14, 2013 3:49 pm
Posts: 39
Reply with quote
Yes it simply needed higher values:

deadZone = 200
deltaFactor = 500

Cheers!


Tue Aug 20, 2013 11:05 pm
Profile
One Eyed Hopeful

Joined: Tue Sep 17, 2013 4:40 pm
Posts: 3
Reply with quote
Hello guys,

sorry for highjacking this thread but I thought I don't need to open a new thread only for one question.

What is the FreePIE equivalent to this GlovePIE code?
Code:
PPJoy1.analog2 = (MapRange(-Joystick.Z, -1, 1, 0, 1))

I need a solution for VJoy.

Thanks in Advance. :)


Tue Sep 17, 2013 4:48 pm
Profile
One Eyed Hopeful

Joined: Tue Sep 17, 2013 8:49 pm
Posts: 1
Reply with quote
FreePIE may have a function for that built in already, but I wouldn't know so here you go, put this function somewhere:
Code:
def map_range(n, lu, hu, lm, hm):
    return lm + (hm - lm) * float(n - lu) / (hu - lu)


And then you can probably do something like:
Code:
ppJoy[0].setAxis(AxisTypes.X, map_range(-joystick[0].sliders[0], -1, 1, 0, 1))

Not sure about that. The function should work though.


Tue Sep 17, 2013 8:58 pm
Profile
Petrif-Eyed

Joined: Mon Jun 22, 2009 8:36 am
Posts: 2160
Location: Stockholm, Sweden
Reply with quote
There is no generic util function built in as of current version (Will fix for next release). But both the ppJoy, Joystick plugin has its own range functions so you could do

Code:
if starting:
   joystick[0].setRange(min, max)
   ppJoy[0].setRange(min, max)


If you are usign vJoy you have to get a little more creative because it does not have a setRange function. The range of the vJoy SDK is int16 so do

Code:
from System import Int16

if starting:
   joystick[0].setRange(Int16.MinValue, Int16.MaxValue)


edit: btw, ther i a 5 minute time limit in current version of Vjoy SDK use this dll to disable that
https://github.com/AndersMalmgren/FreeP ... y/VJoy.dll

_________________
FreePIE
My blog


Wed Sep 18, 2013 1:16 am
Profile
One Eyed Hopeful

Joined: Tue Sep 17, 2013 4:40 pm
Posts: 3
Reply with quote
@Ideka: Thanks for your map_range function. It works great even with vJoy. :)

@CyberVillain: Thanks for the dll. How does the setRange function work? I can't specify an axis with this command so does that mean that all axis are mapped to this range? Maybe I missunderstood this function. :)

I'm using the function provided by Ideka for my script and the axis is mapped correct.
But it doesn't update because the function is in the starting block of the script but I didn't find a way to update the vjoy like other devices such as freetrack.update, etc.
Code:
def map_range(n, lu, hu, lm, hm):
   return lm + (hm - lm) * float(n - lu) / (hu - lu)

if starting:
   vJoy[0].z = map_range(joystick[0].z, 1000, -1000, 0, 1000)
   diagnostics.watch(vJoy[0].z)


Personally I would use a while loop as long as the script runs but is there a better way to do that in Python / FreePie? I'm new at Python but have experience in Java.
EDIT: This loop works but my vJoy doesn't update:
Code:
def map_range(n, lu, hu, lm, hm):
   return lm + (hm - lm) * float(n - lu) / (hu - lu)

def update():
   while (1) :
      vJoy[0].z = map_range(joystick[0].z, 1000, -1000, 0, 1000)

if starting:
   update

diagnostics.watch(vJoy[0].z)
diagnostics.watch(joystick[0].z)


Wed Sep 18, 2013 5:29 am
Profile
Petrif-Eyed

Joined: Mon Jun 22, 2009 8:36 am
Posts: 2160
Location: Stockholm, Sweden
Reply with quote
Cyborg11 wrote:
...


vJoy is a write only plugin so no update, and joystick uses polling under the hood so now update event there either. So you need to use old fashion polling. The problem with your script is that you use the if starting block. Remove that and it willl work. if starting is only fired the first time and not for the rest. You do not need a while loop since thats taken care of by FreePie. Jus tremove the starting and your set.

And yes setRange is for all axis. Your example above with 1000 wont work very well for vJoy since it expects small int (Int16)

This script should work

Code:
from System import Int16

if starting:
   joystick[0].setRange(Int16.MinValue, Int16.MaxValue)

vJoy[0].z = joystick[0].z


Or with Ideka map range
Code:
from System import Int16

vJoy[0].z = map_range(joystick[0].z, -1000, 1000, Int16.MinValue, Int16.MaxValue)


you cant use while loops like that, it will make FreePIE script thread hang.

_________________
FreePIE
My blog


Wed Sep 18, 2013 5:40 am
Profile
Petrif-Eyed

Joined: Mon Jun 22, 2009 8:36 am
Posts: 2160
Location: Stockholm, Sweden
Reply with quote
filters.mapRange added to FreePIE source, will be in next version

https://github.com/AndersMalmgren/FreeP ... 0b41b73fd1

_________________
FreePIE
My blog


Wed Sep 18, 2013 5:58 am
Profile
One Eyed Hopeful

Joined: Tue Sep 17, 2013 4:40 pm
Posts: 3
Reply with quote
Thanks for your help. :)

It's very good to have an better alternative to GlovePIE. 8-)


Wed Sep 18, 2013 6:09 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 13 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by STSoftware.