set Axis to middle

Official forum for open source FreePIE discussion and development.
Post Reply
Veteran66
One Eyed Hopeful
Posts: 15
Joined: Fri Dec 20, 2019 2:27 am

set Axis to middle

Post by Veteran66 »

Hi all

i use a SpaceMouse Pro
with SPACE i will set my Axis to 0
it will work with this scripts, but when i release the SPACE button the axes jump to the last position.
so, how i can set my vjoy Axis to middle

Code: Select all

if starting:
        import time
        axis_mult = (vJoy[0].axisMax / 1000)


vJoy[0].x =             (joystick[3].x + 1                              ) * axis_mult
vJoy[0].y =             (joystick[3].y + 1                              ) * axis_mult


if keyboard.getKeyDown(Key.Space):
	vJoy[0].x = 0

Jabberwock
Cross Eyed!
Posts: 160
Joined: Mon Mar 02, 2015 3:58 pm

Re: set Axis to middle

Post by Jabberwock »

I am not sure what you are trying to do...

With each run vJoy axes are set to joystick[3] values and then zeroed when Space is pressed. At another run they are set to joystick values again. What is supposed to happen?

Veteran66
One Eyed Hopeful
Posts: 15
Joined: Fri Dec 20, 2019 2:27 am

Re: set Axis to middle

Post by Veteran66 »

i use a SpaceMouse Pro, it have not a spring back like a Joystick.
so i will use a button to spring back to 0 like a Joystick

(sorry for my bad english)

Jabberwock
Cross Eyed!
Posts: 160
Joined: Mon Mar 02, 2015 3:58 pm

Re: set Axis to middle

Post by Jabberwock »

That is not possible or I still do not understand the issue.

You constanly obtain the axis values from joystick[3]. Suppose that the joystick[3].x value outputs 50 and you press the button to zero the vjoy value. If the value remained that way, then what should happen if you moved the spacemouse back to the center, so the joystick[3].x is equal zero?

Veteran66
One Eyed Hopeful
Posts: 15
Joined: Fri Dec 20, 2019 2:27 am

Re: set Axis to middle

Post by Veteran66 »

yes I hoped there was a way to force the input value from the joystick to zero like a TrackIR imput

i have this "set zero" effect when i stop and run the Freepie script, maybe this is a way

follow script responds the Axis but the joystick does not go to zero

Code: Select all

if starting:
        import time
        axis_mult = (vJoy[0].axisMax / 1000)

vJoy[0].x =             (joystick[3].x + 1                              ) * axis_mult
vJoy[0].y =             (joystick[3].y + 1                              ) * axis_mult

if starting:
	vJoy[0].x = 0
	enabled = True
	
if enabled:
	vJoy[0].x = joystick[3].x + 1                           
	
	
if keyboard.getPressed(Key.Space):
	enabled = not enabled

Jabberwock
Cross Eyed!
Posts: 160
Joined: Mon Mar 02, 2015 3:58 pm

Re: set Axis to middle

Post by Jabberwock »

If you want recentering like TrackIR, then you should have two global variables (they must be defined at the beginning of the script in a procedure) that would track the recentered values.

For example:

Code: Select all

def variables():
    global recenterX

if starting:
   recenterX = 0

if keyboard.getPressed(Key.Space):
	recenterX = joystick[3].x

vJoy[0].x = joystick[3].x - recenterX
I am not sure how FreePIE/vJoy will react when you try to assign out of bound values to vJoy axes - if that is a problem, adjust the values accordingly.

Veteran66
One Eyed Hopeful
Posts: 15
Joined: Fri Dec 20, 2019 2:27 am

Re: set Axis to middle

Post by Veteran66 »

wauu yes this work, thx

Jabberwock
Cross Eyed!
Posts: 160
Joined: Mon Mar 02, 2015 3:58 pm

Re: set Axis to middle

Post by Jabberwock »

Glad to help!

Veteran66
One Eyed Hopeful
Posts: 15
Joined: Fri Dec 20, 2019 2:27 am

Re: set Axis to middle

Post by Veteran66 »

first step solved :D
# 1=X (Pan Left/Right)
# 2=Y (Pan front/back)
# 3=Z (Up/Down)
# 4=RX (Nod)
# 5=RY (Lean Left/Right)
# 6=RZ (Left/Right)


if starting:
import time
axis_mult = (vJoy[0].axisMax / 3000)


vJoy[0].x = (joystick[3].x + 1 ) * axis_mult
vJoy[0].y = (joystick[3].y + 1 ) * axis_mult
vJoy[0].z = (joystick[3].z + 1 ) * axis_mult
vJoy[0].rx = (joystick[3].xRotation + 1 ) * axis_mult
vJoy[0].ry = (joystick[3].yRotation + 1 ) * axis_mult
vJoy[0].rz = (joystick[3].zRotation + 1 ) * axis_mult

# Centering

def variables():
global recenterX
global recenterY
global recenterZ
global recenterRY
global recenterRX
global recenterRZ

if starting:
recenterX = 0
recenterY = 0
recenterZ = 0
recenterRY = 0
recenterRX = 0
recenterRZ = 0

if keyboard.getPressed(Key.Space):
recenterX = joystick[3].x
recenterY = joystick[3].y
recenterZ = joystick[3].z
recenterRX = joystick[3].xRotation
recenterRY = joystick[3].yRotation
recenterRZ = joystick[3].zRotation

vJoy[0].x = joystick[3].x - recenterX
vJoy[0].y = joystick[3].y - recenterY
vJoy[0].z = joystick[3].z - recenterZ
vJoy[0].rx = joystick[3].xRotation - recenterRX
vJoy[0].ry = joystick[3].yRotation - recenterRY
vJoy[0].rz = joystick[3].zRotation - recenterRZ

next step limiter for the Axis, now the SpaceMouse Joystick run over 100% vJoy Axis

vJoy -100----------0----------+100
SpaceMouse -----------------------------0--------------------------------- have no limit

Jabberwock
Cross Eyed!
Posts: 160
Joined: Mon Mar 02, 2015 3:58 pm

Re: set Axis to middle

Post by Jabberwock »

I am afraid I do not follow...

Veteran66
One Eyed Hopeful
Posts: 15
Joined: Fri Dec 20, 2019 2:27 am

Re: set Axis to middle

Post by Veteran66 »

please see screenshot

Image

my SpaceMouse Axis do not stop on 100%
You do not have the required permissions to view the files attached to this post.

Jabberwock
Cross Eyed!
Posts: 160
Joined: Mon Mar 02, 2015 3:58 pm

Re: set Axis to middle

Post by Jabberwock »

I see. Yes, you need to clip the values to the valid range.

Veteran66
One Eyed Hopeful
Posts: 15
Joined: Fri Dec 20, 2019 2:27 am

Re: set Axis to middle

Post by Veteran66 »

this have no effect
from System import Int16

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

Veteran66
One Eyed Hopeful
Posts: 15
Joined: Fri Dec 20, 2019 2:27 am

Re: set Axis to middle

Post by Veteran66 »

my aktuell script

Code: Select all

# 1=X (Pan Left/Right)
# 2=Y (Pan front/back)
# 3=Z (Up/Down)
# 4=RX (Nod)
# 5=RY (Lean Left/Right)
# 6=RZ (Left/Right)

from System import Int16

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

if starting:
        import time
        axis_mult = (vJoy[0].axisMax / 9000)


# Centering

def variables():
    global recenterX
    global recenterY
    global recenterZ
    global recenterRY
    global recenterRX
    global recenterRZ
    
if starting:
   recenterX = 0
   recenterY = 0
   recenterZ = 0
   recenterRY = 0
   recenterRX = 0
   recenterRZ = 0

if keyboard.getPressed(Key.Space):
	recenterX = joystick[3].x
	recenterY = joystick[3].y
	recenterZ = joystick[3].z
	recenterRX = joystick[3].xRotation
	recenterRY = joystick[3].yRotation
	recenterRZ = joystick[3].zRotation
	
vJoy[0].x = (joystick[3].x - recenterX  ) * axis_mult
vJoy[0].y = (joystick[3].y - recenterY  ) * axis_mult
vJoy[0].z = joystick[3].z - recenterZ
vJoy[0].rx = joystick[3].xRotation - recenterRX
vJoy[0].ry = joystick[3].yRotation - recenterRY
vJoy[0].rz = joystick[3].zRotation - recenterRZ

Veteran66
One Eyed Hopeful
Posts: 15
Joined: Fri Dec 20, 2019 2:27 am

Re: set Axis to middle

Post by Veteran66 »

Jabberwock wrote:
Thu May 14, 2020 5:26 am
I see. Yes, you need to clip the values to the valid range.
you know how to do?
i find nothing how make

Veteran66
One Eyed Hopeful
Posts: 15
Joined: Fri Dec 20, 2019 2:27 am

Re: set Axis to middle

Post by Veteran66 »

setRange not work :cry:

Code: Select all

# 1=X (Pan Left/Right)
# 2=Y (Pan front/back)
# 3=Z (Up/Down)
# 4=RX (Nod)
# 5=RY (Lean Left/Right)
# 6=RZ (Left/Right)

from System import Int16

if starting:
    system.setThreadTiming(TimingTypes.HighresSystemTimer)
    system.threadExecutionInterval = 5        # loop delay
    joystick[4].setRange(Int16.MinValue / 2.001, Int16.MaxValue / 2.001) #Range of vJoy axis


# Centering

def variables():
    global recenterX
    global recenterY
    global recenterZ
    global recenterRY
    global recenterRX
    global recenterRZ
    
if starting:
   recenterX = 0
   recenterY = 0
   recenterZ = 0
   recenterRY = 0
   recenterRX = 0
   recenterRZ = 0

if keyboard.getPressed(Key.Space):
	recenterX = joystick[4].x
	recenterY = joystick[4].y
	recenterZ = joystick[4].z
	recenterRX = joystick[4].xRotation
	recenterRY = joystick[4].yRotation
	recenterRZ = joystick[4].zRotation
	
vJoy[0].x = joystick[4].x - recenterX
vJoy[0].y = joystick[4].y - recenterY
vJoy[0].z = joystick[4].z - recenterZ
vJoy[0].rx = joystick[4].xRotation - recenterRX
vJoy[0].ry = joystick[4].yRotation - recenterRY
vJoy[0].rz = joystick[4].zRotation - recenterRZ

Jabberwock
Cross Eyed!
Posts: 160
Joined: Mon Mar 02, 2015 3:58 pm

Re: set Axis to middle

Post by Jabberwock »

No, this will not work.

Suppose that you recenter at the minimal value of x. When you then move the physical controller to the middle, the recentered value for vjoy.x will be its maximum value. But physically you can move it even farther, so you will exceed the maximum value.

You would need to do something like:

Code: Select all

vJoy[0].x = max(vjoyminvalue, joystick[3].x - recenterX)
vJoy[0].x = min(vjoymaxvalue, joystick[3].x - recenterX)
(I do not remember now the min and max values for vjoy.) That way, if the recentered value is lower than the vjoy minimum, the value stays at the minimum, etc.

Veteran66
One Eyed Hopeful
Posts: 15
Joined: Fri Dec 20, 2019 2:27 am

Re: set Axis to middle

Post by Veteran66 »

ok thy for your answer, i will try it

Veteran66
One Eyed Hopeful
Posts: 15
Joined: Fri Dec 20, 2019 2:27 am

Re: set Axis to middle

Post by Veteran66 »

thx for your support :D

now i find a way, i use UCR this tool have all i need for my SpacsMouse Pro

Link:
https://github.com/Snoothy/UCR

Post Reply

Return to “FreePIE”