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. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
    Thanks for the feedback, and I'm glad it works now!
     
    PiMuRho likes this.
  2. darkmax

    darkmax

    Joined:
    Feb 21, 2012
    Posts:
    83
    I'm having the same issues that PiMuRho is having and deleting the file NonAndroidFallback.cs works, but if your are on android platform.

    If you switch to ios plataform it throws a lot of errors in the script SensorDeviceIPhone.cs and its about SetSensorOn and SetSensorOff, it shows this errors where is used this methods:
    Code (csharp):
    1. Assets/GyroDroid/Scripts/Devices/SensorDeviceIPhone.cs(162,33): error CS0103: The name `SetSensorOn' does not exist in the current context
    2.  
    3. Assets/GyroDroid/Scripts/Devices/SensorDeviceIPhone.cs(201,29): error CS0103: The name `SetSensorOff' does not exist in the current context
    Any idea on how resolve this?, also I'm using unity 4.5.1 and vuforia 3.0.6 just in case you need to know
     
  3. PiMuRho

    PiMuRho

    Joined:
    Jul 11, 2012
    Posts:
    17
    I had the same problem on iOS too (I'm assuming the NonAndroidFallBack script stops the iOS errors coming up) so I've unfortunately had to remove Gyrodroid from my project for the time being. I hope there's a solution soon.
     
  4. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
    Hi guys, sorry for the SetSensorOn issues, that got missed on our side.

    Quick fix: just search for "SetSensorOn" and uncomment those lines, also in "SensorEditorUnity.cs" change "base.SetSensorOn();" to "base.SetSensorOn(sensorID);".

    Not so quick fix: wait for next release (just submitted) which fixes those and the Vuforia imcompatibility (both packages tried to fix the same cross-platform problem on Unity's side, hopefully works now).
     
    talcompedia likes this.
  5. Tromokratis

    Tromokratis

    Joined:
    May 16, 2014
    Posts:
    1
    Hello

    I want my player to move forward backward left right using the accelerometer or gyroscope of a phone (one or more ) maybe stick In my legs I don’t know,
    is this possible?
    whit "
    GyroDroid 2.0" ?



    Regards
     
  6. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
    Hi Tromokratis, please see this post for a detailed explanation why it is in theory possible, but with today's cheap sensor hardware in phones not practically feasible to use linear acceleration as movement method.
     
  7. dev_peter

    dev_peter

    Joined:
    Aug 9, 2012
    Posts:
    38
    How can I set the initial viewing direction to a specific rotation e.g. when I start the app no matter in which direction I look the camera should always be at rotation (0,0,0)? And then when I start turning it should use the gyro to rotate the screen.
    iOS and Android. I've added the minimalsensorcamera script to my camera and the gyro is working, but the start rotation is not the start rotation of my camera.

    And then I want to apply an offset the the x rotation (camera should look a bit up if you hold your phone straight up)?
     
  8. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
    Hi dev_peter, please take a look at one of the other provided sample scenes – TurntableCamera. That one has an initial rotation offset exactly for the usecase you describe. You can also test that in the GyroDroid android app.
     
  9. talcompedia

    talcompedia

    Joined:
    Jul 14, 2014
    Posts:
    4
    The new version is up in the Asset Store and does indeed fix this issue. Also, deleting NonAndroidFallback.cs seems to no longer be required. (I'm still with Unity 4.3.4f).

    Thanks!
     
  10. talcompedia

    talcompedia

    Joined:
    Jul 14, 2014
    Posts:
    4
    I'm seeing problematic behavior from SensorHelper.rotation on several Android devices (including very new ones). This is most likely the devices' fault...

    Has anyone implemented sensor fusion with GyroDroid? Perhaps something along the lines of what is describe in this blog post?
     
  11. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
    @talcompedia, thanks for the feedback!
    For your second question: before blaming the device, we suggest you calibrate properly by moving your device around in an eight-like fashion for some time. This greatly improves the sensor accuracy, especially if you bought a new device that hasn't been moved around yet. Sensor fusion would indeed be very nice to have – the question is whether this can be better than the included one, as the device manufacturers (should) have better access to underlying sensor hardware properties.
     
  12. dev_peter

    dev_peter

    Joined:
    Aug 9, 2012
    Posts:
    38
    @pfc I've added the turntablesensor script but it seems that my iphone4 is not skipping the while loop (SensorHelper.gotFirstValue) so its not doing anything because gotFirstValue is always false. When I remove the gotFirstValue check in lateupdate its using the gyro correctly (SensorHelper.rotation is responding) but the orientation is not set to the main camera orientation, since its not doing initialCameraRotation *= Quaternion.Euler(0,-initialSensorRotation.eulerAngles.y,0);
     
  13. PiMuRho

    PiMuRho

    Joined:
    Jul 11, 2012
    Posts:
    17
    The new version definitely fixes the cross-platform issues I was having. Nicely done.
    However, now when I view a target, it flickers rapidly between the marker position and somewhere else in the world. I'm not sure why, I haven't changed any of the code since the last working version.
     
  14. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
    @dev_peter: will take a look at that as soon as possible. Quick fix: make a Coroutine that sets gotFirstValue some frames after you activate the rotation. Then the first value will already be seen and the offset should work.

    @PiMuRho: are you sure this is due to GyroDroid? And are you also sure you correctly hooked up GyroDroid activation/deactivation to the Vuforia events? Sounds like GyroDroid might still be on when you're looking at a target (should only be on when you don't see one)
     
  15. PiMuRho

    PiMuRho

    Joined:
    Jul 11, 2012
    Posts:
    17
    Sorry, yes. It was my issue (somewhere - I never actually tracked it down, it was easier to just rebuild the scene with new targets)

    Everything seems to be pretty much working properly now, I can switch between PC, Android and iOS builds with no issues.
     
    pfc likes this.
  16. granger35

    granger35

    Joined:
    Aug 27, 2013
    Posts:
    3
    Hi,

    I've just try GyroDroid 2.0, and that's really great. But when i build the scripts with Mono, i have the following errors (error not detected by the Unity Editor) :


    Code (CSharp):
    1. Assets\GyroDroid\Scripts\Devices\SensorDeviceAndroid.cs(130,89): error CS0241: Default parameter specifiers are not permitted
    2. Assets\GyroDroid\Scripts\Devices\SensorDeviceUnity.cs(78,89): error CS0241: Default parameter specifiers are not permitted
    3. Assets\GyroDroid\Scripts\Devices\SensorEditorUnity.cs(185,86): error CS0241: Default parameter specifiers are not permitted
    4. Assets\GyroDroid\Scripts\Sensor.cs(156,70): error CS0241: Default parameter specifiers are not permitted
    5. Assets\GyroDroid\Scripts\Sensor.cs(330,68): error CS0241: Default parameter specifiers are not permitted
    6. Assets\GyroDroid\Scripts\Sensor.cs(367,86): error CS0241: Default parameter specifiers are not permitted
    7. Build complete -- 6 errors, 0 warnings
    8.  
    Do you have any idea ?

    Great thanks.
     
  17. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
    @granger35 Well, actually, that looks like you are using an older version of GyroDroid or and older version of Unity. Are you sure you downloaded the newest version and use it with Unity 4.3.2 or newer?
     
  18. granger35

    granger35

    Joined:
    Aug 27, 2013
    Posts:
    3
    @pfc I've import yesterday the gyrodroid version 5.1 from the Unity Assets Store (for the first time), and my unity version was the 4.3.4f1 (Mono Develop version 4.0.1). I have updated Unity to the version 4.5.3, but the Mono version is always the same, and that do not change the errors in Mono.
     
  19. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
  20. granger35

    granger35

    Joined:
    Aug 27, 2013
    Posts:
    3
    @pfc Thanks a lot, no more errors. I was thinking that most of developers writing scripts for Unity were using Mono, but sure that they have configured it to allow default parameters sepcification !
     
  21. pauL___

    pauL___

    Joined:
    Nov 28, 2013
    Posts:
    14
    @pfc hi, is there a script for Shake device..
    Like for example>>
    Current Image..

    IF(shake android)
    current image will replace (image1)..

    And if shake again
    Image1 will replace (image2).... etc.

    I am thinking on purchasing gyroDroid if it has.

    (I already tried accelerometer on my android but not smooth for shaking device.)

    If it has, please let me know ASAP.thanks! Best regards!
    ### Sorry for my english :) ###
     
  22. pauL___

    pauL___

    Joined:
    Nov 28, 2013
    Posts:
    14
    and one more thing, i just installed gyroDroid on my Lenovo s820 and to my other devices, and some features on your app is not working. Specially "Linear Acceleration".. Im shaking my phone but nothing changed.
     
  23. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
    @pauL___ , well, GyroDroid does contain a virtual Linear Acceleration sensor which will work if your phone has a normal acceleration sensor. This might not be included in the Play Store demo (AssetStore package is updated more often), sorry. Every phone should have Acceleration sensor. As of now, there is no shake detection algorithm in GyroDroid, but we will think about it for the future; still, it should be no problem to roll your own (using the max magnitude over some frames is a very simple way).
     
  24. Zorah7

    Zorah7

    Joined:
    Mar 3, 2014
    Posts:
    2
    Hi there, I've just started using Gyrodroid, but I'm finding that the tracking can be quite shaky when standing still, twitching around a little. I'm guessing that's because of the sensor data, but does anyone have a tip on scripting a filter to minimise the twitch?

    Thanks in advance.
     
  25. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
    There are some filters included with GyroDroid.
    So, you can use:

    QuaternionFilter filter = new QuaternionFilter(5);
    void Update () {
    transform.rotation = filter.Update(SensorHelper.rotation);
    }

    The "5" in the above example is your filter strength. The lower, the slower the adaption. Keep in mind that more filtering equals slower response time for your users.
     
  26. chloeinspace

    chloeinspace

    Joined:
    Oct 17, 2014
    Posts:
    1
    prefrontal cortex team,

    Thank you! Your assets has worked very well for getting rotation vector data into my AR application. It helped when I was in a pinch last night.

    I am experiencing one problem with GyroDroid that I'm not sure if it's my code or a limitation from the asset. The problem I'm having is a framerate hit when using GyroDroid to get the RotationVector information. It appears to be similar to a problem that another poster named @Rainking had. I'm getting a noticeable framerate impact with GyroDroid. Is this normal or is there a recommended use model that is best for performance?

    I also loaded up the sample application and it seems to

    My Setup:
    - Unity Pro 4.3.4f1
    - Sony Xperia Z2, Z3, Z2 Tablet , Z Ultra
    - Android 4.4.2
     
  27. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
    Hi DerekR, well, @Rainking never replied whether he found the issue (maybe he will now?). I think upgrading Unity might be the easiest to see whether the issue persists, if that is an option for you. As I said regarding that old post, we never had this issue in our testing.
     
  28. Rainking

    Rainking

    Joined:
    Jun 10, 2013
    Posts:
    41
    Hi,
    unfortunately I was not able to find the root cause. I put quiet a lot time into this issue so I ended up using this following code, which is ok for me...

    Code (CSharp):
    1. Input.compass.enabled = true;
    2. transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0,Input.compass.magneticHeading, 0),Time.deltaTime*2);
     
  29. lalamax3d

    lalamax3d

    Joined:
    Aug 23, 2012
    Posts:
    17
    hi pfc,
    this is product named "GyroMote" on asset store, it kind of give same data back on a port(network) so unity app can read it. but its for IOS. you have done more work in terms of client side, would you plan to make gyromote type asset so data can be sent back from application mobile application to connected unity (on PC)
     
  30. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
    Hi lalamax3d, the newest version of GyroDroid already supports the UnityRemote4 for rotation and magnetic field. For the other sensor types we already have a prototype we're still working on. But thanks for the suggestion!
     
  31. Dev Chorus

    Dev Chorus

    Joined:
    Nov 1, 2013
    Posts:
    5
    Hi,
    I would like to ask whether the step counter can continue to detect movement/steps even when the unity app is turned off, and then be able to add those steps to the counter once the unity app is turned on again?
    Thanks!
     
  32. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
    Hi Dev Chorus, for this you need an Android service to run in the background, which involves some more programming and changing the app manifest. Some info specific for services talking to Unity can be found here, more info about step counters here.
     
  33. Stratos-K

    Stratos-K

    Joined:
    Nov 22, 2014
    Posts:
    7
    Hello pfc,

    I bought Gyrodroid and i am very impressed with how it works. Great work and very easy to apply it in my game. I am very happy with my buy. Keep up the good work!

    Right now i am using the turntablesensor script to create something similar to the physics demo you have. My question to you would be if there is any possible way for the camera to follow a specific ball. I already have a camera script that can follow a target but i don't know if it is possible to combine these two.

    What i am trying to do is have a setup similar to your physics demo but with just one ball and instead of the camera to be static,to be able the camera to follow the ball without changing the functionality of your script.

    Is this possible? Any ideas?
     
    Last edited: Nov 23, 2014
  34. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
    Hi Stratos, glad you like GyroDroid! What you want is actually ultra-simple: parent the camera with the script to that ball, done. Maybe offset the position (via script) by some value upwards (so the camera is always above the ball).
     
  35. Stratos-K

    Stratos-K

    Joined:
    Nov 22, 2014
    Posts:
    7
    Thank you for you reply.

    Because i didn't understood you correctly can you make it a bit more clear? You mean to make the camera child of the ball? When i do this the camera is following the ball the way i want,the ball seems to have physics and in the console it gives me the message "RotationVector is available".But when i try it on my smartphone the ball is not moving according to the gyroscope. It stays at the same position. Something to note is that right now the camera has both the turntable sensor script and the other script for following the target ball (which is the RTS camera pro from the store by the way).

    The only way i managed to make it work is make all objects children of the camera.This way the gyroscope is working but the camera is completely static and the ball has to stay in the FOV of the camera
     
  36. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
    Hm, you want the ball to move according to gyroscope (e.g. fall down)? Then it's probably easiest if you make a simple script that copies the camera rotation to your world root (rotation only), so the camera moves independent from the world (can follow the ball).
     
  37. Stratos-K

    Stratos-K

    Joined:
    Nov 22, 2014
    Posts:
    7
    Yes exactly.I want the ball to move according to the gyroscope and the camera to be able to follow the ball.

    Because i didn't understand exactly this new script, i have to put in the camera with the gyroscope script and the target follow script or insert it on a separate gameobject? Also does the hierarchy of the objects matter in order for your gyrodroid script to work?

    Sorry for all these questions. I am novice in Unity and i am still trying to understand how exactly your script work so i can make it work the way i want.

    Thank you for your time
     
  38. simcovr

    simcovr

    Joined:
    Jul 3, 2012
    Posts:
    43
    Hi,

    I've got a problem with your plugin working on a iPhone6Plus. All the sensor I need (gyro, linear acc) works, but the pressure does not work at all. The same application on a Samsung S3 works fine.

    Please let me know if there is a workaround on this because I need to use that sensor on the iPhone6

    Thank you very much
     
  39. bjornrun

    bjornrun

    Joined:
    Oct 29, 2013
    Posts:
    88
    What is the progress on an Unity 5 version?

     
  40. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
    @all, sorry for the late reply, will have to check why the forums are not sending us update mails anymore.

    @Stratos K.: all the GyroDroid script does is rotate the object it's on. So you can also try putting the script on your world root (to rotate that and allow the ball to roll around and such).

    @simcovr: on iOS, GyroDroid currently allows access to the same sensors as Unity does, and the Unity guys haven't yet implemented the pressure sensor (but I think they will now, since that is now available across devices). So for now, if you need a workaround, you will have to add the pressure sensor code directly in xcode.

    @bjornrun: We didn't start it yet, as Unity 5 is still in beta and API changes may occur. But we scheduled the initial tests for compatibility this February, and if Unity didn't change everything, that should not take long.
     
  41. Neeraj_UnityDev

    Neeraj_UnityDev

    Joined:
    Jan 29, 2015
    Posts:
    1
    Hi,

    I am working with GyroDroid 5.1 in unity Application. it is working fine in Android devices. But when i exported the same Application for IOS XCODE. It seems gyroroid is not compatible in xcode. i am getting errors. Please guide me if there is any solution.
    Thanks in advance.
     
  42. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
    @Neeraj_UnityDev What kind of errors? People use GyroDroid with xcode all the time, so please be more specific. Note that Unity 5 is not yet supported since it's still in beta.
     
  43. chorusgames

    chorusgames

    Joined:
    Jul 21, 2014
    Posts:
    15
    Hi,

    I am having crashes on the statistic screen on Samsung S5 and LG G3 phones when trying to access the demo application but work fine on devices that does not support step counter. I tried both apks building from your latest gyrodroid 5.1 and also from the one in PlayStore both having the same crash problems. Do you know whats causing the problem.
     
    Last edited: Feb 5, 2015
  44. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
    @chorusgames, we've indeed seen some other people report issues with the step counter and will take a look at it as soon as possible.
     
  45. chorusgames

    chorusgames

    Joined:
    Jul 21, 2014
    Posts:
    15
    thank you could you let us know when it has been checked/fixed. I have bought your package solely for the step counter feature and its a big bummer if that is not working.
     
  46. DevIb

    DevIb

    Joined:
    Feb 12, 2015
    Posts:
    5
    how to add filters to minimal sensor camera script to reduce sensitivity,
    thanks.
     
  47. pfc

    pfc

    Joined:
    Jul 28, 2011
    Posts:
    104
    @chorusgames: Sure, we will let you know.
    @Devlb: there's a bunch of Filter scripts provided with GyroDroid. Just use e.g. the QuaternionFilter class to filter that. More about that can be found in this answer already.
     
  48. DevIb

    DevIb

    Joined:
    Feb 12, 2015
    Posts:
    5
    Thanks, but it's different from the actual scene, I mean do i delete this line (transform.rotatio = SensorHelper.rotation)
    or use it with the filter.
     
  49. DevIb

    DevIb

    Joined:
    Feb 12, 2015
    Posts:
    5
    also the script is attached to ARcamera, if this information could help.
     
  50. DevIb

    DevIb

    Joined:
    Feb 12, 2015
    Posts:
    5
    sorry for my long question but i wrote the filter to the demo scene (rotation demo) there's no change of the behavior no filtering.


    public class MinimalSensorCamera : MonoBehaviour {

    // Use this for initialization
    void Start () {
    // you can use the API directly:
    //Sensor.Activate(Sensor.Type.RotationVector);

    // or you can use the SensorHelper, which has built-in fallback to less accurate but more common sensors:
    SensorHelper.ActivateRotation();



    useGUILayout = false;
    }

    // Update is called once per frame
    QuaternionFilter filter = new QuaternionFilter(2);
    void Update () {
    // direct Sensor usage:

    transform.rotation = filter.Update(SensorHelper.rotation);
    //transform.rotation = Sensor.rotationQuaternion;
    //--- is the same as Sensor.QuaternionFromRotationVector(Sensor.rotationVector);

    // Helper with fallback:


    transform.rotation = SensorHelper.rotation;


    }
    }
     
    Last edited: Feb 13, 2015