Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IMU sample in Unity #2996

Closed
mtschoen opened this issue Jan 2, 2019 · 5 comments
Closed

IMU sample in Unity #2996

mtschoen opened this issue Jan 2, 2019 · 5 comments
Assignees

Comments

@mtschoen
Copy link

mtschoen commented Jan 2, 2019

Hello there,

I'm sure this is being worked on, but is there an available sample using IMU data in Unity? I'd like to try a simple experiment where the point cloud is counter-rotated by IMU data to stabilize the horizon. I'm a little confused about where to start. I think I want to add a POSE profile to my stream reader, but I'm unsure what kind of format/dimensions this "frame" should be.

Thanks!

@MartyG-RealSense
Copy link
Collaborator

As you observed, there is not a Unity sample program for IMU data yet. A RealSense community member has contributed a non-Unity program for rotating the point cloud with the IMU though. Looking at this code may provide some useful insights.

https://github.com/GruffyPuffy/imutest

@mtschoen
Copy link
Author

mtschoen commented Jan 2, 2019

Thanks for the quick reply. I am currently looking through samples and actually encountered this one already. It seems that the Unity wrapper has a slightly different way of accessing frame data than the C++ examples, so I'm still not entirely sure how to proceed. I will keep searching, and if/when I have a solution I will post here.

@ogoshen
Copy link
Contributor

ogoshen commented Jan 3, 2019

The C# wrapper doesn't yet contain the high-level APIs to support IMU (i.e MotionFrame\Profile), but I can point you in the right direction for low-level access (not tested).

class Program
{
    struct Vector3
    {
        public float x, y, z;
    }

    static void Main(string[] args)
    {
        var pipeline = new Pipeline();
        var cfg = new Config();
        cfg.EnableAllStreams();
        pipeline.Start();

        while (true)
        {
            using (var frameset = pipeline.WaitForFrames())
            {
                var gyroFrame = frameset.FirstOrDefault<Frame>(Stream.Gyro, Format.MotionXyz32f).DisposeWith(frameset);
                var a = Marshal.PtrToStructure<Vector3>(gyroFrame.Data);
                
                var accelFrame = frameset.FirstOrDefault<Frame>(Stream.Accel, Format.MotionXyz32f).DisposeWith(frameset);
                var b = Marshal.PtrToStructure<Vector3>(accelFrame.Data);
            }
        }
    }
}

@dorodnic
Copy link
Contributor

dorodnic commented Jan 3, 2019

We are working on better IMU support across the SDK.

The plans is:
a. Motion and Pose frames support in C++ and python (Done)
b. IMU integration with existing C++ examples (Done)
c. Adding new C++ examples with IMU (WIP)
d. Adjust the .NET wrapper and add to Unity example

@mtschoen
Copy link
Author

mtschoen commented Jan 4, 2019

Thanks for the update. I probably won't have time to try @ogoshen's suggestion, but thanks for that, too! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants