Page 1 of 1

FreePIE bytes format

Posted: Tue Oct 28, 2014 2:10 pm
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!

Re: FreePIE bytes format

Posted: Wed Oct 29, 2014 9:17 am
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

Re: FreePIE bytes format

Posted: Wed Oct 29, 2014 9:22 am
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

Re: FreePIE bytes format

Posted: Wed Oct 29, 2014 9:30 am
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

Re: FreePIE bytes format

Posted: Wed Oct 29, 2014 10:17 am
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 ?

Re: FreePIE bytes format

Posted: Wed Oct 29, 2014 10:35 am
by CyberVillain
Well thats the whole point, to run FreePIE in the background so users can use any tracker.

Re: FreePIE bytes format

Posted: Wed Oct 29, 2014 1:00 pm
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 ?

Re: FreePIE bytes format

Posted: Wed Oct 29, 2014 1:17 pm
by CyberVillain
Yes, freepie.exe <script> /r

Re: FreePIE bytes format

Posted: Wed Oct 29, 2014 2:02 pm
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.

Re: FreePIE bytes format

Posted: Wed Oct 29, 2014 4:43 pm
by CyberVillain
Can this c++ example help?

Re: FreePIE bytes format

Posted: Thu Oct 30, 2014 9:47 am
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..

Re: FreePIE bytes format

Posted: Thu Oct 30, 2014 11:31 am
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);

Re: FreePIE bytes format

Posted: Thu Oct 30, 2014 12:53 pm
by Jackii
Worked!
Thanks CyberVillain!

Re: FreePIE bytes format

Posted: Thu Oct 30, 2014 1:11 pm
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

Re: FreePIE bytes format

Posted: Thu Oct 30, 2014 2:25 pm
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

Re: FreePIE bytes format

Posted: Fri Oct 31, 2014 6:29 am
by CyberVillain
Nice, whats the actual latency?

Re: FreePIE bytes format

Posted: Fri Oct 31, 2014 10:13 am
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?

Re: FreePIE bytes format

Posted: Fri Oct 31, 2014 2:23 pm
by CyberVillain
Today its not, but I have gotten the request before, I can fix it for next version.

Re: FreePIE bytes format

Posted: Fri Oct 31, 2014 3:41 pm
by Jackii
Great! looking forward.
Though how would it be like? android[0].gyro[0] instead of android[0].googleyaw for instance?

Re: FreePIE bytes format

Posted: Fri Oct 31, 2014 4:17 pm
by CyberVillain
or android[0].raw.gx etc