iPhone support

Official forum for open source FreePIE discussion and development.
pAnatiC
One Eyed Hopeful
Posts: 34
Joined: Fri Jan 18, 2013 4:49 pm

Re: iPhone support

Post by pAnatiC »

CyberVillain wrote:
pAnatiC wrote:
CyberVillain wrote:I tried to make a scrpt for you but it looks like there is a bug in the Keyboard plugin. Only the modifiers can be pressed and kept down, all the others wont work like that. Do you have any input Brantlew?
The modifiers are strg & alt, right? i guess that wouldnt be a big problem. should be possible to bind in game
Strange,if i use FreePIE to set left shift down and type something it will type everything in capital letters, so it works for typing. But if i assign a function in a game to left shift it does not work so it seems our keyboard emulation isnt 100%
Some updates? :D
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: iPhone support

Post by CyberVillain »

I'm sorry, dont have much time for coding lately (Got a little preborn son 2 weeks ago). I will try to look at it, but cant promise anything.

For a starter please try this.

Code: Select all

keyboard.setKey(Key.A, True)
or

Code: Select all

keyboard.setKey(Key.LeftShift, True)
Assign the key to one of the two above and start the script, run the game and see if the button is pressed in game

edit: Strange,

keyboard.setKey(Key.A, mouse.leftButton)

This works (Press left mousebutton to simulate A)

But sending a constant key down does not, also I tried to write a script that sends press down on certain degrees (Using an android since i dont own a iPhone) and that didnt work either
pAnatiC
One Eyed Hopeful
Posts: 34
Joined: Fri Jan 18, 2013 4:49 pm

Re: iPhone support

Post by pAnatiC »

CyberVillain wrote:I'm sorry, dont have much time for coding lately (Got a little preborn son 2 weeks ago). I will try to look at it, but cant promise anything.

For a starter please try this.

Code: Select all

keyboard.setKey(Key.A, True)
or

Code: Select all

keyboard.setKey(Key.LeftShift, True)
Assign the key to one of the two above and start the script, run the game and see if the button is pressed in game

edit: Strange,

keyboard.setKey(Key.A, mouse.leftButton)

This works (Press left mousebutton to simulate A)

But sending a constant key down does not, also I tried to write a script that sends press down on certain degrees (Using an android since i dont own a iPhone) and that didnt work either
No problem! No need to hurry! Your preborn is way more important than some shitty iphone code :)
If youre son is crying in the future, just give him the oculus rift with some cartons :D
User avatar
cybereality
3D Angel Eyes (Moderator)
Posts: 11406
Joined: Sat Apr 12, 2008 8:18 pm

Re: iPhone support

Post by cybereality »

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

Re: iPhone support

Post by CyberVillain »

Thanks guys!

We are both away from work (And living at the hospital with the little guy) to tend to him and between his meals etc its pretty nice to kill some time with FreePIE, so no worries :D
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: iPhone support

Post by CyberVillain »

Got it to work (dont know what i did wrong the first time around)

Code: Select all

if starting:
   centerYaw = 0   
   yaw = 0
   yawDegrees = 0
   moveLeft = False
   moveRight = False
   moveAtDeegree = 25
   
   iPhone.continuousYawMode = True

yaw = iPhone.yaw
yawDegrees =  math.degrees(yaw - centerYaw)

moveLeft = yawDegrees < -moveAtDeegree
moveRight = yawDegrees > moveAtDeegree

keyboard.setKey(Key.LeftShift, moveLeft)		
keyboard.setKey(Key.RightShift, moveRight)

if keyboard.getKeyDown(Key.LeftControl) and keyboard.getPressed(Key.C):
   centerYaw = yaw
   
diagnostics.watch(yawDegrees)
diagnostics.watch(moveLeft)
diagnostics.watch(moveRight)
Its tested with the android plugin so cant guarantee it will work perfect with iPhone
Run the script and look in the watch window

Note the yawDegrees, if you press Ctrl+C it should reset to 0 now move your head (Or phone) to the pos you want memorize the degree
Change moveAtDeegree to that value
Also change the two keys to teh ones you have assigned in game

edit: Forgot, when you are happy with the result remove the 3 diagnostics lines, they will hog some CPU
You do not have the required permissions to view the files attached to this post.
pAnatiC
One Eyed Hopeful
Posts: 34
Joined: Fri Jan 18, 2013 4:49 pm

Re: iPhone support

Post by pAnatiC »

Edit2: Now its working. But i have to press down and HOLD the button for the time i wanna show in one direction. Now its just for a millisecond.
Image

Dont know if its possitlbe at all?


Edit: after reinstall the script is running. Will give it a try! :D

############
##
If i try to run the script:

Die Sequenz enthält mehrere übereinstimmende Elemente.
=> The Sequence contains some correlate (same) elements?! :(
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: iPhone support

Post by CyberVillain »

Your image is exactly how i got it to work with my Android.

moveLeft moveRight in the watch window are they showing 'True' stable or is it toggling fast between True / False?

also to test the keyboard emulation with your game its best to exclude the iPhone code, just try

Code: Select all

keyboard.setKey(Key.A, mouse.leftButton)
Change A to correct key and try in game to press left mouse button, does it look left or right and stays there while the mouse i pressed?
pAnatiC
One Eyed Hopeful
Posts: 34
Joined: Fri Jan 18, 2013 4:49 pm

Re: iPhone support

Post by pAnatiC »

CyberVillain wrote:Your image is exactly how i got it to work with my Android.

moveLeft moveRight in the watch window are they showing 'True' stable or is it toggling fast between True / False?

also to test the keyboard emulation with your game its best to exclude the iPhone code, just try

Code: Select all

keyboard.setKey(Key.A, mouse.leftButton)
Change A to correct key and try in game to press left mouse button, does it look left or right and stays there while the mouse i pressed?
the code with the mousebutton works fine!
With the maincode, there is left and right in the wrong direction, wasnt the problem to swap.

And ya, it is stable in true - false. But it feels like, there has to be a center true-false.
it is either LEFT true or Right True. But never both false. So i will allways look in one direction at the moment.
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: iPhone support

Post by CyberVillain »

I must admin that I have to idea about the format the iphone plugin spits out.

If you set contiuneYawMode to False in the script and check the output of the watch window. Press Ctrl+C to recenter. if you turn the phone to the left and to the right one direction give you negative degrees and the other one positive degrees right?

Turn the phone to the desired angle, note the angle and use that in the script. You should now have a deadzone between -selectedDegree and +selectedDegree
pAnatiC
One Eyed Hopeful
Posts: 34
Joined: Fri Jan 18, 2013 4:49 pm

Re: iPhone support

Post by pAnatiC »

CyberVillain wrote:I must admin that I have to idea about the format the iphone plugin spits out.

If you set contiuneYawMode to False in the script and check the output of the watch window. Press Ctrl+C to recenter. if you turn the phone to the left and to the right one direction give you negative degrees and the other one positive degrees right?

Turn the phone to the desired angle, note the angle and use that in the script. You should now have a deadzone between -selectedDegree and +selectedDegree
have tested

iPhone.continuousYawMode = False

yaw = iPhone.yaw
yawDegrees = math.degrees(yaw - centerYaw)

moveLeft = yawDegrees < 4000000
moveRight = yawDegrees > -5900000

keyboard.setKey(Key.X, moveLeft)
keyboard.setKey(Key.C, moveRight)


The problem is: if i start the script, the "yawDegress" goes crazy. Shouldnt it stay even to some number?
the longer its lay on my desk the wilder it goes.
Every time i start the script, i have round about a completly different number.

https://dl.dropbox.com/u/10643056/Video ... 6%2009.mov (takes some time)
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: iPhone support

Post by CyberVillain »

Those values looks way off the chart, try to remove the math.degrees and use the raw value, looks like Brantlews iPhone plugin is broken. Are you using the same sensor program that he is etc? I dont know anything about the plugin so Brantlew could probably help ypu better here
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: iPhone support

Post by CyberVillain »

I'm guessing that they have changed someting in the data sent from that app, if I look at brantlews code an exception like that can happen if they contract is out of sync. Sadly I dont own a iPhone so either brantlew or someone with a iPhone needs to debug this.

He's not that active with FreePIE anymore, you could try PM him
Player2
One Eyed Hopeful
Posts: 16
Joined: Tue May 20, 2014 4:32 am

Re: iPhone support

Post by Player2 »

Hello!
First of all, as this is my first post, i want to THANK YOU CyberVillain for FreePIE. It is a long awaited program for me, and i enjoy the scripting again (last time when i did it i was coding in Clipper 3 - yes, long time ago).

I bought Wavefront Lab's Sensor Data (the full app) and ran into the same error as huzhekun.
But on their site i've found an example python script: http://accelerometer-simulator.googleco ... taccsim.py
If i set up the app to capture and send only "Euler angles" and run the example script in "Idle" - it works like a charm.
i got this response:

Client 192.168.2.21 said ``Timestamp,Roll,Pitch,Yaw''
Client 192.168.2.21 said ``1.001243,0.022880,-0.012092,0.000150''
Client 192.168.2.21 said ``2.001249,0.025592,-0.013849,-0.000504''
Client 192.168.2.21 said ``3.001241,0.025729,-0.013657,-0.001469''
...
Roll and Yaw will give you +ve values for clockwise movement from 0 to Pi and negative for counter clockwise motion, Pitch varies between -Pi/2 and Pi/2 if you move the phone from down to up.
If i try to run the example script in FreePIE, i get an error message: "Line: 419: error".

Additionally the app can provide lot more sensor data:
``Timestamp,Accel_X,Accel_Y,Accel_Z,Roll,Pitch,Yaw,Quat.X,Quat.Y,Quat.Z,Quat.W,RM11,RM12,RM13,RM21,RM22,RM23,RM31,RM32,RM33,GravAcc_X,GravAcc_Y,GravAcc_Z,
UserAcc_X,UserAcc_Y,UserAcc_Z,RotRate_X,RotRate_Y,RotRate_Z,MagHeading,TrueHeading,HeadingAccuracy,MagX,MagY,MagZ,Lat,Long,LocAccuracy,Course,Speed,Altitude,Proximity''

And here my knowledge stops. Unfortunately i don't know how to use Github, nor i can understand what the example script does.
Can you please help?
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: iPhone support

Post by CyberVillain »

Welcome to the forum. Is that the exact output of the app?
First a line with the order and then continuing with data lines?


Let me check brantlews code when I get home
Player2
One Eyed Hopeful
Posts: 16
Joined: Tue May 20, 2014 4:32 am

Re: iPhone support

Post by Player2 »

hello,
yes it is (copy-paste).

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

Re: iPhone support

Post by CyberVillain »

Hmm, looks like FreePIE needs to be running it's script before you start the sensor app. Otherwise it will miss the column order line. Have you tried this?
Player2
One Eyed Hopeful
Posts: 16
Joined: Tue May 20, 2014 4:32 am

Re: iPhone support

Post by Player2 »

You are right! Now it works (but iPhone.pitch is actually roll, and iPhone.yaw is inverted - but i think i can live with that) !
But if my memory serves me well i tried that on my win7 pc and it was throwing that "Index was outside the bounds of the array." error.

i'll check it when i'll be home and report back.

You are quite fast!!! ;)

THANKS
Player2
One Eyed Hopeful
Posts: 16
Joined: Tue May 20, 2014 4:32 am

Re: iPhone support

Post by Player2 »

here is a working script:

Code: Select all

if  starting:
   iPhone.continuousYawMode = True

yaw = -math.degrees(iPhone.yaw)
pitch = -math.degrees(iPhone.roll)

mouse.deltaX = filters.delta(yaw * 10)
mouse.deltaY = filters.delta(pitch * 10)
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: iPhone support

Post by CyberVillain »

I can fix so that FreePIE throws a error if it does not receive the first line.
Player2
One Eyed Hopeful
Posts: 16
Joined: Tue May 20, 2014 4:32 am

Re: iPhone support

Post by Player2 »

Or it could just use the received numbers. if one configures the app properly - to send only Euler angles, they'll always be 2nd 3rd and 4th values.
Or you could pass the received values as an array, and the user can figure it out which values to use. (One could have joystick control with gps data - almost a google-car :) )
Do as you think is best, i am already happy with it!
Player2
One Eyed Hopeful
Posts: 16
Joined: Tue May 20, 2014 4:32 am

Re: iPhone support

Post by Player2 »

I was happy too early.
Under Win7 (64bit), FreePIE waits till the stream starts and than gives "Input string was not in a correct format." error.
Strange - it worked on WinXP (32bit). Tried reinstall but that doesn't helped.
regards
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: iPhone support

Post by CyberVillain »

I will do some improvemnets to brantlews code and let you try
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: iPhone support

Post by CyberVillain »

How does this work?
You do not have the required permissions to view the files attached to this post.
Player2
One Eyed Hopeful
Posts: 16
Joined: Tue May 20, 2014 4:32 am

Re: iPhone support

Post by Player2 »

Now i get the same error: "Input string was not in a correct format", and also i saw a timout error while i was fiddling with the app setup (always looses the ip address).
I'll have to install Idle and run the example script on my w7 box and look at the reply.
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: iPhone support

Post by CyberVillain »

That is stange, you should now get more info in the error. It should print the actual data it tried to parse
Player2
One Eyed Hopeful
Posts: 16
Joined: Tue May 20, 2014 4:32 am

Re: iPhone support

Post by Player2 »

I copied your new build over the installed program - was it the correct procedure?
Tried again this morning - got the same error. I can try to install freePiE to my older w7 machine
which never had it before - when i get home. Thank you for your precious time and support.
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: iPhone support

Post by CyberVillain »

If you have UAC enabled It will not like that you change files in program folders. Better to use a completely separate folder
Player2
One Eyed Hopeful
Posts: 16
Joined: Tue May 20, 2014 4:32 am

Re: iPhone support

Post by Player2 »

UAC is disabled. First i unrared to a separate folder in the downloads and ran from there - same error. after i copied over the installed version - again the same error. It seems unreasonable that xp is getting different data than w7?!
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: iPhone support

Post by CyberVillain »

Is the machine not working by any chance not using EN/US culture?
There is a bug in the plugin so it have never worked on none US/EN machines. Will fix
Last edited by CyberVillain on Fri May 23, 2014 4:19 am, edited 1 time in total.
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: iPhone support

Post by CyberVillain »

Try this version please
You do not have the required permissions to view the files attached to this post.
Player2
One Eyed Hopeful
Posts: 16
Joined: Tue May 20, 2014 4:32 am

Re: iPhone support

Post by Player2 »

well, this works on my dualboot "work" laptop - now under Vista (32bit). i'll report back about w7 later...
respect.
Player2
One Eyed Hopeful
Posts: 16
Joined: Tue May 20, 2014 4:32 am

Re: iPhone support

Post by Player2 »

This works on w7 also!!!
Thanks, again and again!
i'll post some scripts later if i can make something interesting.
have a nice weekend.
SD456
One Eyed Hopeful
Posts: 2
Joined: Tue Jul 22, 2014 9:10 am

Re: iPhone support

Post by SD456 »

Hello everyone!

I would like to make my DIY #Cardboard Rift with an iPhone, but I need some kind of free software for headtracking.
Is there anything that I can use?
Player2
One Eyed Hopeful
Posts: 16
Joined: Tue May 20, 2014 4:32 am

Re: iPhone support

Post by Player2 »

SD456 wrote:Hello everyone!

I would like to make my DIY #Cardboard Rift with an iPhone, but I need some kind of free software for headtracking.
Is there anything that I can use?
Afaik, there is no free software which will send data to pc.
iBookworm
One Eyed Hopeful
Posts: 23
Joined: Sun Sep 07, 2014 3:36 pm

Re: iPhone support

Post by iBookworm »

Hey everyone,

Can anyone send me a script that will translate the iPhone's input to basic TrackIR three degrees of freedom (pitch, yaw, and roll)?

I have the Sensor Data app and have successfully run the mouse control example given here. But alas, I lack the scripting ability to figure out how to link the iPhone input to TrackIR output.

I really appreciate any help anyone could give. Even if it's just pointers or some example scripts to start me off.
Player2
One Eyed Hopeful
Posts: 16
Joined: Tue May 20, 2014 4:32 am

Re: iPhone support

Post by Player2 »

Hi

Check out the example scripts on the FreePIE webpage:
http://andersmalmgren.github.io/FreePIE/samples.html
it's pretty straightforward from there..

cheers
iBookworm
One Eyed Hopeful
Posts: 23
Joined: Sun Sep 07, 2014 3:36 pm

Re: iPhone support

Post by iBookworm »

Thanks! The Android to FreeTrack example is just what I'm looking for, except that I want to go from iPhone (iPod, really) to TrackIR.

However, plugging in iPhone doesn't seem to work . . . I get an error that says, "'iPhone PluginGlobal' object has no attribute to 'update'

Here's what I have at the moment. If I remove the line that says "iPhone.update = update" the script runs without error, but nothing happens in TrackIR when everything is running.

def update():
global yaw
yaw = iPhone[0].yaw
global pitch
pitch = -iPhone[0].roll
global roll
roll = iPhone[0].pitch

if starting:
centerYaw = 0
centerPitch = 0
centerRoll = 0

yaw = 0
pitch = 0
roll = 0
iPhone.update = update

trackIR .yaw = yaw - centerYaw
trackIR.pitch = pitch - centerPitch
trackIR.roll = roll - centerRoll

if keyboard.getKeyDown(Key.LeftControl) and keyboard.getPressed(Key.C):
centerYaw = yaw
centerPitch = pitch
centerRoll = roll
iBookworm
One Eyed Hopeful
Posts: 23
Joined: Sun Sep 07, 2014 3:36 pm

Re: iPhone support

Post by iBookworm »

I just added:

diagnostics.watch(iPhone.pitch)
diagnostics.watch(iPhone.roll)
diagnostics.watch(iPhone.yaw)

When I delete that line that says iPhone.update = update (so the script will run) and run the script I can see the values in Watch window. So the iPhone is talking to FreePIE just fine.
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: iPhone support

Post by CyberVillain »

There are two errors in your code,

first,

Code: Select all

iPhone.update = update
Should be

Code: Select all

iPhone.update += update


It means that you are appending yourself to the list of listeners to the update event

Second, the iPhone plugin is one of those plugins that do not have the update event
Post Reply

Return to “FreePIE”