FreePIE bytes format

Official forum for open source FreePIE discussion and development.
Post Reply
Jackii
One Eyed Hopeful
Posts: 8
Joined: Tue Oct 28, 2014 2:02 pm

FreePIE bytes format

Post by Jackii »

Hey,
This is my first post here, so apologies if there are any mistakes.
Well recently I've been trying to integrate freePIE's android IMU into game engines. My current target is blender game engine, which uses python.
First of all, I'm an absolute newbie when it comes to networking in any language, though I could get python to read freePIE's orientation data from the IMU just fine, but in bytes.
I've started a thread on Blender artists forum, and the answer was that I needed to know what's being sent over/it's format in order to be able to encode it.
That's basically the question. What is the possible way to turn raw bytes into a string so I can extract the orientation matrix/accelerometer data?

Thanks!
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: FreePIE bytes format

Post by CyberVillain »

There is no need for you to rewrite FreePIE, use the FreePIE_IO plugin

https://github.com/AndersMalmgren/FreeP ... /IO-Plugin

With that the user can use any of the plugins in FreePIE with your software
Cercata
One Eyed Hopeful
Posts: 21
Joined: Fri Oct 17, 2014 1:50 am

Re: FreePIE bytes format

Post by Cercata »

You mean replace the FreePIE PC App by your python script on blender, and receive information from an android device directly ?

If yes, yo can see how the source code interprets the received data:

https://github.com/AndersMalmgren/FreeP ... in.cs#L103
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: FreePIE bytes format

Post by CyberVillain »

Going directly against the UDP packages sent by the Android App is going against what FreePIE stands for.
Pyhton can load C dlls, so please use that method and people can use any input supported by FreePIE.

http://blenderartists.org/forum/showthr ... hon-script
Jackii
One Eyed Hopeful
Posts: 8
Joined: Tue Oct 28, 2014 2:02 pm

Re: FreePIE bytes format

Post by Jackii »

Well I did try the DLL method previously but I wanted the process to be automated to a certain point.

Maybe I'm missing something and that you can get the data directly from the IO plugin without having to run freePIE with a script that writes a slot in the IO DLL ?
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: FreePIE bytes format

Post by CyberVillain »

Well thats the whole point, to run FreePIE in the background so users can use any tracker.
Cercata
One Eyed Hopeful
Posts: 21
Joined: Fri Oct 17, 2014 1:50 am

Re: FreePIE bytes format

Post by Cercata »

Jackii wrote:Well I did try the DLL method previously but I wanted the process to be automated to a certain point.
Then maybe you can launch FreePIE from pyhon ...

¿ Are there command line options to tell FreePIE to exec an script on launch ?
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: FreePIE bytes format

Post by CyberVillain »

Yes, freepie.exe <script> /r
Jackii
One Eyed Hopeful
Posts: 8
Joined: Tue Oct 28, 2014 2:02 pm

Re: FreePIE bytes format

Post by Jackii »

I'm a bit lost with reading slot data from IO, here's my current tiny code:

Code: Select all

import ctypes

yaw = ctypes.c_float(0.0)
pitch = ctypes.c_float(0.0)
roll = ctypes.c_float(0.0)

path = "C:/Program Files (x86)/FreePIE/freepie_io.dll" #temporary, just for testing

lib = ctypes.CDLL(path)

test =  lib.freepie_io_6dof_read(0, 0, yaw, pitch, roll);

print(yaw)
It outputs c_float(0.0), with valid slots and with other unused slots a writing violation error.
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: FreePIE bytes format

Post by CyberVillain »

Can this c++ example help?
Jackii
One Eyed Hopeful
Posts: 8
Joined: Tue Oct 28, 2014 2:02 pm

Re: FreePIE bytes format

Post by Jackii »

CyberVillain wrote:Can this c++ example help?
Which one? I've already tried to replicate the one on the IO's page but it's changing nothing in the variables as the code I've pasted above.

edit: I did it! Well sort of.... I got it to read the yaw data perfectly, though it's not reading the rest..
My code:

Code: Select all

from ctypes import*


yaw = c_float()
pitch = c_float()
roll = c_float()

path = "C:/Program Files (x86)/FreePIE/freepie_io.dll" #temporary, just for testing

lib = CDLL(path)

test =  lib.freepie_io_6dof_read(0, 1, byref(yaw), byref(pitch), byref(roll));

print(yaw.value, pitch.value, roll.value)
Prints the correct yaw, though the pitch and roll are still null for somehow..
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: FreePIE bytes format

Post by CyberVillain »

Missed the link sorry

https://github.com/AndersMalmgren/FreeP ... est/main.c

edit: The problem is that it takes a struct

Code: Select all

typedef struct freepie_io_6dof_data
{
    float yaw;
    float pitch;
    float roll;

    float x;
    float y;
    float z;
} freepie_io_6dof_data;

Code: Select all

int32_t freepie_io_6dof_read(uint32_t index, uint32_t length, freepie_io_6dof_data *output);
Jackii
One Eyed Hopeful
Posts: 8
Joined: Tue Oct 28, 2014 2:02 pm

Re: FreePIE bytes format

Post by Jackii »

Worked!
Thanks CyberVillain!
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: FreePIE bytes format

Post by CyberVillain »

Glad I could help, what will you use it for in Blender?

edit: Read the first post, didnt know they had a engine, I thought it was a render program only
Jackii
One Eyed Hopeful
Posts: 8
Joined: Tue Oct 28, 2014 2:02 pm

Re: FreePIE bytes format

Post by Jackii »

Blender game engine is a relatively powerful game engine with visual scripting and python along with GLSL node shaders and a super fast workflow for prototyping.
You're not the first person by any means to not know that Blender has a built in game engine. :P
I'm using freePIE for smartphone VR using the Trinus Gyre.

Edit: here's a quick video of it working with the Trinus Gyre in a simple demo game I made: http://youtu.be/1ybe3t7XSnU
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: FreePIE bytes format

Post by CyberVillain »

Nice, whats the actual latency?
Jackii
One Eyed Hopeful
Posts: 8
Joined: Tue Oct 28, 2014 2:02 pm

Re: FreePIE bytes format

Post by Jackii »

Tracking latency is almost nothing in both cases of wireless and USB tethered. Though it sometimes stutters in wireless. The streaming latency is the one that's relatively high at high resolutions and deeper color channels.

Edit: Since there's a "send raw data" option in the android IMU, is there a way to access that from FreePIE and write it into the IO DLL?
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: FreePIE bytes format

Post by CyberVillain »

Today its not, but I have gotten the request before, I can fix it for next version.
Jackii
One Eyed Hopeful
Posts: 8
Joined: Tue Oct 28, 2014 2:02 pm

Re: FreePIE bytes format

Post by Jackii »

Great! looking forward.
Though how would it be like? android[0].gyro[0] instead of android[0].googleyaw for instance?
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: FreePIE bytes format

Post by CyberVillain »

or android[0].raw.gx etc
Post Reply

Return to “FreePIE”