psmove rotational and positional data to opentrack (its working)

Official forum for open source FreePIE discussion and development.
Post Reply
VerdeMsk
One Eyed Hopeful
Posts: 2
Joined: Wed Mar 08, 2023 5:11 am

psmove rotational and positional data to opentrack (its working)

Post by VerdeMsk »

Hi all. Registered just to share a script if somebody will be searching for a similar thing.
I was trying to make headtracking with a psmove controller.
Of course there are some apps which seems to be working in that way, but they are limited to positional data via light bulb and ps eye camera. And I needed rotational data.
Also Freepie has feature to convert data to freetrack, but for some reason not all apps I've seen reads it (driver4vr for example). Also it's hard to tune for a newbies and has no filters, etc.
So I was searching for a way to send it to opentrack instead.
First I asked chatgpt to write me a script, but it was only half working (still it's awesome - it helped me to understand code a little bit).
Then I've found a post on that forum by Me4huk who posted a script for trackir, I edited it a little bit, tested with opentrack's UDP over network and voila - it's working.
I don't have a ps eye camera, so psmove sends only rotational data, but looks like positional data will also work.
In opentrack it's possible to use fusion input, so it's available to mix it with aruco, neuralnet and other sources.
In order to use it you will need psmove service(or psmoveserviceEX) and psmovefreepiebridge running.
In opentrack choose UDP over network input (or fusion with same setting).
If some axis doesn't work upon starting push recenter button.

I hope it helps somebody :)

Code: Select all

# based on code for trackir posted by Me4huk. edited by VerdeMsk

import socket
import struct

def update():

	#numbers in brackets are multipliers. change them if there are too much or not enough rotation/position.
	##could be also tuned in opentrack, but for some apps whitch reads only raw data tune it with these numbers instead.
	#also you can swap all axis according to mounting of your psmove controller.
	#roll is disabled initially, because I don't think it's useful. delete # if you need this axis to work.
	yaw = (-freePieIO[0].yaw * 120)
	pitch = (freePieIO[0].pitch * 120)
	#roll = (freePieIO[0].roll * 1)
	#x = (freePieIO[0].x * 10)
	#y = (freePieIO[0].y * 10)
	#z = (freePieIO[0].z * 10)

	#if keyboard.getKeyDown(Key.C):	y = 200
	#else:							y = freePieIO[0].y

	#4242 in brackets is a number in opentrack's UDP over network port setting.
	opentrack_UDPsender.sendto(struct.pack("dddddd", x, y, z, yaw, pitch, roll), ("localhost", 4242))
	#SendOsc('localhost', 6666, "/glovepie/pithon", yaw, pitch, roll, x, y, z)

	diagnostics.watch(yaw)
	diagnostics.watch(pitch)
	diagnostics.watch(roll)
	diagnostics.watch(freePieIO[0].yaw)
	diagnostics.watch(freePieIO[0].pitch)
	diagnostics.watch(freePieIO[0].roll)
	diagnostics.watch(x)
	diagnostics.watch(y)
	diagnostics.watch(z)	

if starting:
	global yaw, pitch, roll, x, y, z
	x , y , z , yaw , pitch , roll = 0,0,0,0,0,0
	opentrack_UDPsender = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
	freePieIO[0].update += update
Gustave
One Eyed Hopeful
Posts: 1
Joined: Fri May 26, 2023 2:07 am

Re: psmove rotational and positional data to opentrack (its working)

Post by Gustave »

You're able to use a script that Me4huk posted on a forum for the TrackIR device, and then modified it to work with the PS Move controller and OpenTrack. This allowed you to send the PS Move's rotational data to OpenTrack via UDP over network input, and then use OpenTrack's fusion input feature to combine it with other sources such as ArUco or neural net data.
trap the cat
JohnHood
One Eyed Hopeful
Posts: 2
Joined: Thu Jun 22, 2023 10:44 pm

Re: psmove rotational and positional data to opentrack (its working)

Post by JohnHood »

VerdeMsk wrote: Wed Mar 08, 2023 6:22 am Hi all. Registered just to share a script if somebody will be searching for a similar thing.
I was trying to make headtracking with a psmove controller.
Of course there are some apps which seems to be working in that way, but they are limited to positional data via light bulb and ps eye camera. And I needed rotational data.
Also Freepie has feature to convert data to freetrack, but for some reason not all apps I've seen reads it (driver4vr for example). Also it's hard to tune for a newbies and has no filters, etc.
So I was searching for a way to send it to opentrack instead.
First I asked chatgpt to write me a script, but it was only half working (still it's awesome - it helped me to understand code a little bit).
Then I've found a post on that forum by Me4huk who posted a script for trackir, I edited it a little bit, tested with opentrack's UDP over network and voila - it's working.
I don't have a ps eye camera, so psmove sends only rotational data, but looks like positional data will also work.
In opentrack it's possible to use fusion input, so it's available to mix it with aruco, neuralnet and other sources.
In order to use it you will need psmove service(or psmoveserviceEX) and psmovefreepiebridge running.
In opentrack choose UDP over network input (or fusion with same setting).
If some axis doesn't work upon starting push recenter button. roller baller

I hope it helps somebody :)

Code: Select all

# based on code for trackir posted by Me4huk. edited by VerdeMsk

import socket
import struct

def update():

	#numbers in brackets are multipliers. change them if there are too much or not enough rotation/position.
	##could be also tuned in opentrack, but for some apps whitch reads only raw data tune it with these numbers instead.
	#also you can swap all axis according to mounting of your psmove controller.
	#roll is disabled initially, because I don't think it's useful. delete # if you need this axis to work.
	yaw = (-freePieIO[0].yaw * 120)
	pitch = (freePieIO[0].pitch * 120)
	#roll = (freePieIO[0].roll * 1)
	#x = (freePieIO[0].x * 10)
	#y = (freePieIO[0].y * 10)
	#z = (freePieIO[0].z * 10)

	#if keyboard.getKeyDown(Key.C):	y = 200
	#else:							y = freePieIO[0].y

	#4242 in brackets is a number in opentrack's UDP over network port setting.
	opentrack_UDPsender.sendto(struct.pack("dddddd", x, y, z, yaw, pitch, roll), ("localhost", 4242))
	#SendOsc('localhost', 6666, "/glovepie/pithon", yaw, pitch, roll, x, y, z)

	diagnostics.watch(yaw)
	diagnostics.watch(pitch)
	diagnostics.watch(roll)
	diagnostics.watch(freePieIO[0].yaw)
	diagnostics.watch(freePieIO[0].pitch)
	diagnostics.watch(freePieIO[0].roll)
	diagnostics.watch(x)
	diagnostics.watch(y)
	diagnostics.watch(z)	

if starting:
	global yaw, pitch, roll, x, y, z
	x , y , z , yaw , pitch , roll = 0,0,0,0,0,0
	opentrack_UDPsender = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
	freePieIO[0].update += update
That's great to hear that you were able to find a solution for your specific needs! It's always beneficial to customize and adapt existing scripts to fit your requirements. Thank you for sharing your experience and the steps you took to make the headtracking with a psmove controller work for you. This information may be helpful for others who are looking to achieve a similar setup. If you have any more questions or need further assistance, feel free to ask!
Post Reply

Return to “FreePIE”