Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

GyroDroid - Access each and every sensor on Android devices [RELEASED]

Discussion in 'Assets and Asset Store' started by pfc, Aug 19, 2011.

  1. harleycw

    harleycw

    Joined:
    Apr 1, 2009
    Posts:
    22
    This is great! I was just thinking about cleaning things up to also get my webplayer working. This simple file did the trick. Thanks!!
     
  2. android_dev

    android_dev

    Joined:
    Jul 9, 2011
    Posts:
    19
    Thanks for the script! Working fine. The iOS gyro is giving quite good results using the normal unity api. So we are just using it for android anyway.
     
  3. harleycw

    harleycw

    Joined:
    Apr 1, 2009
    Posts:
    22
    The values from the sensors when the phone (Motorola Droid RAZR - Android 2.3.6) is completely stationary keep changing so much that in the scene the camera also seems to be slightly bouncing around which is quite annoying. Are other people having this problem?
     
  4. harleycw

    harleycw

    Joined:
    Apr 1, 2009
    Posts:
    22
  5. exoszajzbuk

    exoszajzbuk

    Joined:
    Apr 11, 2012
    Posts:
    10
    Hey!

    We've just bought your plugin, because it seemed awesome, and it really is.

    But I've got some problems with the Eclipse integration of the plugin. I followed the tutorial to create an Eclipse project from Unity Android app (I've done it several times before, so I'm familiar with the process of making a working app in Eclipse).

    The problem is, that GyroDroid seems to not using the gyroscope at all. I tried with a Galaxy Tab, and your demo app on Google Play works just fine. It also works fine, if I import GyroDroid, create the basic MinimalSensorCamera, and choose "Build and Run" (so if I'm deploying directly to the device).

    If I export the project to Eclipse, it starts too, but it uses only the accelerometers (far worse movement than the gyroscope). The following warnings occurs in the logs, hope it helps:

    I'd really appreciate, if somebody could help me with this.

    Regards:
    Balazs
     
  6. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
    Hey Balazs,

    since i never needed to export to Eclipse (we do everything the other way around, creating java plugins) I'm not quite sure with this.
    But the error suggests that the Gyrodroid Java plugin is missing for you (it falls back to Unity's default orientation if not found). I think you may have to reference the SensorClass.jar directly inside Eclipse instead of exporting it only. Unity does that internally when building for Android, so you may have to do it by hand in your exported project. So, add it as a reference, build, and lets see whether that works.

    Best regards
    pfc

    Edit: Another even more possible error would be if you made your own UnityPlayer in Java (thats it, I think, why else should you export to Eclipse?) . GyroDroid relies on the player being class "com.unity3d.player.UnityPlayer" and inside that a static field "currentActivity", like in the default code. You can change that class name at about line 623 in Sensor.cs to match your custom Activity.
     
    Last edited: Jul 4, 2012
  7. exoszajzbuk

    exoszajzbuk

    Joined:
    Apr 11, 2012
    Posts:
    10
    Hey pfc!

    Thanks for your answer, but meanwhile I've figured it out. In older versions of ADT for Eclipse plugin you'd need to reference the SensorClass.jar directly in your classpath, or from ADT 17.0 or above you have to place your libraries in the /libs folder to be automatically referenced. This is what I've forgot.

    Exactly what you've assumed in your answer. :) Thanks for the quick response, and keep up the good work!

    Regards:
    Balazs
     
  8. Goldrake

    Goldrake

    Joined:
    Feb 6, 2010
    Posts:
    148
    Hi pfc,
    i have a problem that probably i'll solve using your plugin.
    You should confirm me if the way i think i can utilize it it's right and will work.

    I need to get accelerometer, magno, gyro values from a thread (so not from the main unity thread).
    Form a thread i can't access to Input and Gyroscope classes of Unity.
    It's because the main thread of Unity it's frame dependent while i need a frame indipendent computation.

    Will your classes be accessible from thread?

    for example if i do:

    Thread newThread = new Thread(Work.DoWork);
    newThread.Start();



    public static void DoWork(object data)
    {
    gyrodroid.getAccelerometer() // or what will be the function of your plugin
    }





    Thank you
     
    Last edited: Jul 16, 2012
  9. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
    Hi, that should be possible since GyroDroid des not access UnityAPI methods. Its values get updated on the regular main thread, so they should be accessible inside other threads. But it was not designed with thread-safety in mind, so there may be problems if you access the values while they get updated. A better way is probably to make some new variables with the volatile keyword which you update every frame in the main thread (in an Update method).
    Hope that helps!
     
  10. Goldrake

    Goldrake

    Joined:
    Feb 6, 2010
    Posts:
    148
    I need to access it directly from the thread because a need a costant sampling. The main unity thread update function it's framerate dependent. For our filter it's needed a costant timerate. So i should know the sampling rate of gyrodroid and if it full works in a separate thread before i buy it. Or i'll have to write my own.

    Thank you very much
     
  11. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
    Sampling works with a constant sampling rate. That's how the GyroDroid Java plugin does ist in the background. Unity only gets the values in its Update; no actual sampling happens there. And GyroDroid samples with the "Game" speed, which is described as "rate suitable for games". It is the second-fastest and should be about 60fps, but the sensors could be slower. You can't force the sensors to deliver values with Android, you only get callbacks if it happens.

    By the way, if you want a constant framerate, use FixedUpdate instead of Update. It gets executed at fixed time intervals, and you can even change that interval. I would not recommend using a second thread. What do you want to achieve?

    I hope that helps.
     
  12. Goldrake

    Goldrake

    Joined:
    Feb 6, 2010
    Posts:
    148
    We are implementing a kalman filter to achive the current position (in world) in the space of the utilizer of the phone.
    It's calculable using kalman on the gyro and accelerometer and adding gps. It should give more precision while the person is moving in the space (the gps is 5m accuracy, with this we want to achive 50cm).
    To use kalman we need a fixed framerate and not dependent by the graphic engine. Because we need the values at a constant T in time.

    ps.: The sampling rate of the gyro and accelerometer can be set in iOS. I think it's possible also in Android
     
    Last edited: Jul 21, 2012
  13. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
    What I told you still applies - the sampling rate is framerate independent on Android. It is completely happening in the background. There are 4 sampling speeds to choose from, "game" is used in GyroDroid and is second-fastest. The actual sampling speed may vary between devices.

    Google made a video of a talk about sensor fusion (using kalman filters and multiple sensors) and why even that isn't good enough to determine position in space anywhere near usable. But, nonetheless - I find it very interesting and wish you best luck! Maybe sensors are good enough by now.

    (http://developer.android.com/reference/android/hardware/SensorManager.html#SENSOR_DELAY_FASTEST)
     
  14. Goldrake

    Goldrake

    Joined:
    Feb 6, 2010
    Posts:
    148
    can you link me that video? :)
     
  15. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
    Of course:

    Sensor Fusion on Android Devices: A Revolution in Motion Processing GoogleTechTalk on Youtube, explanation for "not usable" is at 23:20
    Indoor Positioning System based on Gyroscope and Accelerometer on Stackoverflow

    Some additional infos: linear acceleration is derived from acceleration and gravity, and then you have essentially a double integral (speed from acceleration, position from speed) to get position values. And because the sensors itself have errors, the results are barely usable. For his demos, the speaker got around 5-10 meters of drift in one second without moving the device.

    Some of the Sensors provided by Android (for example RotationVector) aren't physical sensors but are based on sensor fusion (you see that on the statistics page of the GyroDroid sample app). The implementation differs between vendors; we found that on some devices, the results are near-perfect rotation values, while on others the fused values are far worse than simply using the physical orientation sensor.
     
    Last edited: Jul 23, 2012
  16. spire8989

    spire8989

    Joined:
    Aug 18, 2010
    Posts:
    94
    If you could make a psuedo pedometer using the accelerometer I'd buy this in a heartbeat. Still, good job.
     
  17. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,548
    Why isn't this part of Unity?! A question before purchase, if I run on a device without gryoscope, is there an emulation for the values? Also, is the interface consistent for IOS build?
     
    Last edited: Aug 14, 2012
  18. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
    Well, it partly is - but due to Unity's mission to support the common denominator between iOS and Android, GyroDroid is far more powerful nd provides deeper control (and, of course, a lot more sensors).

    You can change the values used by GyroDroid in the editor to simulate running on a device. Simply put the Sensor script somewhere in your scene - it exposes both sensor availability and sensor values while running in the editor. And you can use the demo app to determine rest values and so fort and experiment from there. In the far future, there may be a way to stream the values directly from a device, but not right now :)

    GyroDroid is a pure Android solution. We recommend using device checking or compile directives for other platforms.
    Rgarding Gyro emulation: GyroDroid has several fallbacks for different sensor configurations on different devices. Thus, it should work everywhere - with very direct feedback on "good" devices with good sensors, and less direct feedback on devices without good sensors.
     
    Last edited: Aug 14, 2012
  19. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,548
    So you are saying for IOS, just Unity Input and use conditonal complie to use Gyrodriod for Andriod? That is annoying for a cross platform solution, why don't use provide a interface, and fallback to Unity Input if you don't support it.

    But I noticed 3GS don't have gyroscope, so we have to write the approximation with accelermometer ourselves?
     
  20. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
    GyroDroid is designed to enable sensor access for Android devices. Android supports a wide variety of sensors (linear acceleration, compass, light, proximity, ... 11 in total). There is no fallback solution for all of this sensors on iOS devices. Of course, falling back to Unitys built in method would be not too hard, but until now, noone asked for it. You did now, so if time allows it, it will be included in the next update.

    You cannot derive gyroscope (full three-axis rotation values) from accelerometer (2-axis) alone, you need at least an additional compass (1-axis). We will consider adding this as an additional fallback method, too, as it is already supported by us for Android (if no Gyro sensor is found).

    GyroDroid is, like I said, designed to allow access to many different sensors on Android devices. Of course, the main use seems to be 360 rotation support with fallbacks, so you are totally right that for a cross-platform solution falling back to Unity's defaults is the way to go.
     
  21. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,548
    Thank you, bought it.
     
  22. alvaro-em

    alvaro-em

    Joined:
    Feb 23, 2012
    Posts:
    77
    Hello, pfc. I have been working with Gyrodroid and I have to say that it is impressive. It works amazingly fine and it abstracts the device capabilities in an absolute transparent way. Currently I am working in an application for both platforms: Android and IPhone. It is already working for Android, but I tried to use Unity Input class to allow Gyrodroid to be used in IPhone.

    It is proving to be much more difficult than I tough (my maths knowledge is not as high as I would like). I only find strange behaviour in IPhone, specially with the compass. I have read in a previous post that the next vesion of Gyrodroid will be IPhone compatible by using the same method I am.Do you know when will it be available?

    Thank you very much in advance and congrats again.
     
  23. fadzuli

    fadzuli

    Joined:
    Sep 22, 2010
    Posts:
    15
    Falling back to Unity's built in method would be a great time saver for working on Android and iOS. When will this update be out?
     
  24. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,548
    No update?
     
  25. hgtunc

    hgtunc

    Joined:
    Sep 30, 2012
    Posts:
    1
    Hello,
    I have a problem about my application. I am using Unity3.5.6f4(yesterday upgraded from Unity3.5.5 - prolems are same) and I have some 3d models from blender. First I am compiling TurntableDemo scene without any change and It works. After that removing TurntableDemo's plane,android model and light. Then adding directional light,my models and terrain.(GameCenter and Camera stay same) In this process I am compiling scene at each change. Finally some apk works one or two apk do not work on my Galaxy S2. Application compiled for Android 2.3.3. please help on this irregularity. I tried many way but have no solution. Is there anyboy who faced with this situation?

    Thanks.
     
  26. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
    Sorry for the long delay, everybody. Unfortunately, lots of other things got in the way and weren't able to finish the changes yet. An update will definitely come, as we regard "not breaking cross-platform projects" as really important, but we can't promise a date as of now.

    @hgtunc: That sounds strange. Does the original scene work when you compile it? On which point in the process does it stop working? Do other Unity-generated apks work? What if you delete the old app from the device before compiling? We've seen devices which weren't able to override old apks, maybe that's the same for you. On the other hand, we definitely tested the S2 and it worked as expected, so it isn't a general device error. And it should be no problem that the files come from Blender, as Unity converts everything into its own mesh format.
     
  27. Skribble

    Skribble

    Joined:
    Oct 29, 2012
    Posts:
    16
    i've been testing this on my Galaxy S2 and works awesome!
    i would love to make some tests on a tablet, im thinking on buy one, a 7 inches tablet.

    can you please recommend me a tablet ( a 7 inch cheap one, just to make it work ) im interested in the Camera as a Window demo on GyroDroid.

    if the tablet is cheaper than $100 would be awesome!

    thank you!
     
  28. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
    Hey Skribble, great to see that you like GyroDroid!

    we would not recommend to use a cheap tablet, especially not below the $100 price tag. In our tests, lower-end devices usually also had lower-end sensors which means you won't get the great feeling from a Galaxy S2 on such a tablet. It is really probable that such devices do not support rotation vector functionality, but only magnetic field and accelerometer (they have to to have an Android branding). That would mean: jittery or very smoothed movement.

    That said, I think that current devices like Google Nexus 7 and Amazon Kindle Fire should work great and cost about $200.

    Edit: If you (or someone else) manages to test some lower-end devices, feel free to post your results here! If there is a tablet with a really low pricetag which has nice sensors this would certainly be interesting for other developers as well.
     
  29. psrussell

    psrussell

    Joined:
    Feb 4, 2012
    Posts:
    8
    I just purchased and imported GyroDroid into a new Unity 3.5.6f4 project on a WinXP SP3 machine. I have the latest version of java installed. When I try to build the project for Android, I get the the following error:

    Failed to compile Java code to DEX:
    C:\UnityDevelopment\GyroDroid\Temp/StagingArea> java -Xmx1024M -Djava.ext.dirs="C:/Program Files/Android/android-sdk-windows\platform-tools/lib/" -jar "C:/Program Files/Android/android-sdk-windows\platform-tools/lib/dx.jar" --dex --verbose --output=bin/classes.dex bin/classes.jar plugins
    Error occurred during initialization of VM
    Could not reserve enough space for object heap
    Could not create the Java virtual machine.

    When I try the fix listed in this thread:

    http://forum.unity3d.com/threads/88119-Could-not-reserve-enough-space-for-object-heap-RESOLVED

    by creating a _JAVA_OPTIONS env var using a value of -Xmx512m the compile appears to work, but then errors when trying to sign the package, even though the correct passwords are in the publishing settings. Error below

    jarsigner: unable to read password: The handle is invalid Enter Passphrase for keystore: Picked up _JAVA_OPTIONS: -Xmx512m

    UnityEngine.Debug:LogError(Object) PostProcessAndroidPlayer:SignAndroidPackage(String ) (at C:/BuildAgent/work/14194e8ce88cdf47/Editor/Mono/BuildPipeline/PostProcessAndroidPlayer.cs:949) PostProcessAndroidPlayer:postProcess(BuildTarget, String, String, String, String, String, String, BuildOptions) (at C:/BuildAgent/work/14194e8ce88cdf47/Editor/Mono/BuildPipeline/PostProcessAndroidPlayer.cs:460) UnityEditor.HostView:OnGUI()

    I'm not seeing any other solutions for this, and am hoping someone here at pfc may have another idea, or solution.

    Thanks
    Patrick
     
  30. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
    Hey,

    I you say "the latest Java version", do you mean JDK 7? I would suggest you to try the latest JDK 6, as we had issues with 7 and Unity/Android. I'm not quite sure about that, but the Android SDK worked only with JDK 6 some time ago. So another option would be to also upgrade the Android SDK.

    This is related to Unitys signing behaviour for Android in general and not an error in GyroDroid.
     
  31. psrussell

    psrussell

    Joined:
    Feb 4, 2012
    Posts:
    8
    JDK 6 update 37. I also made sure my Android SDK is also updated to the latest version. I agree I think the signing error is due to Unity. It only occurs when I try to use the _JAVA_OPTIONS fix and set a smaller heap size (Xmx512m). Im just not sure what to do here. I can't use the plugin in any projects. Would you have any other suggestions.
     
  32. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
    Ok, so version is not the issue. Actually, I don't know that Java options fix and as far as I know, nobody had to use it to get GyroDroid working so far.

    Another thing I noticed is that your android SDK is at "Program Files". That's another thing we had various issues with - spaces in the full path. Try moving android SDK to C:/android-sdk/ (and disable the options fix again).

    Hope that helps!
     
  33. psrussell

    psrussell

    Joined:
    Feb 4, 2012
    Posts:
    8
    The fix was to create an Environment variable called _JAVA_OPTIONS, and change the max heap size by setting the value -Xmx512m. When I did that it appeared to work, but then errored with the jarsigner. I'll try moving the android sdk out of the Program Files dir. I'll let you know. Thanks
     
  34. psrussell

    psrussell

    Joined:
    Feb 4, 2012
    Posts:
    8
    Ok well moving the android sdk to c:\android\android-sdk-windows did not solve the issue. I also moved my jdk6 installation to a new location (no spaces) also to see if that wouuld solve the issue.

    I posted in the Unity Support forum also to see if the Unity team could add some insight to this issue, but I haven't seen any replies. Any other suggestions. I'm at a total loss here.

    Thanks
     
  35. pasoftdev

    pasoftdev

    Joined:
    Jul 30, 2012
    Posts:
    3
    Hello,

    I'm about to buy this from the asset store, however I see that it is not written anywhere whether this requires unity pro or not.
    will it work with unity indie + android license ?
    thank you
     
  36. nilton_felicio

    nilton_felicio

    Joined:
    May 17, 2012
    Posts:
    66
    I asked the same question.
    will it work with unity indie + android license?
    And with all versions indie Unity?
     
  37. psrussell

    psrussell

    Joined:
    Feb 4, 2012
    Posts:
    8
    Is this why it is not able to compile, because I am not using the Pro version. I am using the Free version + Android license. If this is the case I will need a refund as the asset store does not secify this.
     
  38. pasoftdev

    pasoftdev

    Joined:
    Jul 30, 2012
    Posts:
    3
    hey psrussell can you confirm whether this works for you?
    or anyone with unity free + android license?
     
  39. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
    Hi all,
    as the license comparison page tells, it should work (Java plugins are supported for Android Basic). I have sent a mail to Unity support to confirm whether this might be a bug.

    In the meantime - have you tried an earlier Unity 3.5.x release? Maybe a bug got introduced with the newest version. I'm sorry, but I'm unable to test this specific setup (Unity Free + Android Basic) for myself.
    @psrussell: do you have another machine to test with (maybe Win 7 instead of XP SP3) whether its machine/OS specific?
    And, what comes to my mind right now: does it work with debug signing (or are you using that all the time)?
     
  40. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
    @psrussell:
    Are the signing issues solved? If not, please try the latest Unity release (3.5.7 as of Dec 14). The change log mentions "Fixed a lot of key store related problems" and other things that could potentially hinder compilation of plugins.
     
  41. gdeng

    gdeng

    Joined:
    Jan 6, 2013
    Posts:
    3
    I only have unity3d 3.4.1, can I use gyrodroid 3.1 package?
     
  42. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
    Should be no problem, yes.
     
  43. gdeng

    gdeng

    Joined:
    Jan 6, 2013
    Posts:
    3
    Nice, I gotta buy it for my study.
     
  44. gdeng

    gdeng

    Joined:
    Jan 6, 2013
    Posts:
    3
    How to buy the 3.1 version instead of 3.2? Cause' the 3.2 version need Unity 3.4.2 or above but I only have 3.4.1 (cannot update to 3.4.2 now).
     
  45. mocaponeuk

    mocaponeuk

    Joined:
    Oct 17, 2012
    Posts:
    20
    Silly question, when will this be ported to ios?
     
  46. Le-Lag

    Le-Lag

    Joined:
    Jan 22, 2013
    Posts:
    8
    Maybe a silly question, but I'm using GyroDroid on several devices, and i have many different behaviours :

    i use SensorHelper.rotation to have a kind of head camera (FPS style)

    - on my Sony Xperia T it's awesome
    - on Samsung Ace 2 i have a lot of jittering, and even when phone is not moving, values passed to unity are sometimes consequent. This cause camera to move all alone...
    - on xperia miro too
    - on galaxy S2 i have very S***ty results
    - on S3 it's quite fine
    - ...

    Then i guess it's dependent on sensors hardware, but I wanted to know if you have a solution to have normalized behaviour on most of the phones...
     
  47. KareemErgawy

    KareemErgawy

    Joined:
    Jan 11, 2013
    Posts:
    8
  48. mrdaniel

    mrdaniel

    Joined:
    Mar 21, 2012
    Posts:
    13
    is there examples on how to use sensor-fusion with your scripts ?

    thanks
     
  49. mrdaniel

    mrdaniel

    Joined:
    Mar 21, 2012
    Posts:
    13
    can i have a direct email support ?
    thanks.
     
  50. TiMus

    TiMus

    Joined:
    Oct 27, 2012
    Posts:
    1
    Hi ,

    I have ZTE-blade android-2.2. Your App at google play is incompatible to my device.
    I am interested in buying your plug-in. Will there be any issues if I try the unity App on ZTE-blade.