shiffman / libfreenect

Just working on Processing library here
http://www.shiffman.net
122 stars 55 forks source link

Accelerometer access #19

Closed orgicus closed 10 years ago

orgicus commented 12 years ago

Hello Daniel,

Thanks for sharing the source. I've noticed that there is an interface to the accelerometer already, but no access to it, so I've tried to change the Kinect class to fix that.

I've created a PVector instance to store x,y,z values into, implemented the Acceleration interface, and made a getter for the PVector instance. Couldn't use the .jar in eclipse:

Exception in thread "Animation Thread" java.lang.UnsatisfiedLinkError: /Users/george/Documents/eclipse/KinectTest/lib/user/openkinect/libKinect.jnilib:  no suitable image found.  Did find:  /Users/george/Documents/eclipse/KinectTest/lib/user/openkinect/libKinect.jnilib: mach-o, but wrong architecture
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1827)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1742)
    at java.lang.Runtime.loadLibrary0(Runtime.java:823)
    at java.lang.System.loadLibrary(System.java:1045)
    at org.openkinect.Context.<clinit>(Context.java:43)
    at org.openkinect.processing.Kinect.start(Kinect.java:43)
    at kinecttest.KinectTest.setup(KinectTest.java:26)
    at processing.core.PApplet.handleDraw(PApplet.java:1866)
    at processing.core.PApplet.run(PApplet.java:1788)
    at java.lang.Thread.run(Thread.java:680)
quitting
java.lang.NullPointerException
    at org.openkinect.processing.Kinect.quit(Kinect.java:152)
    at kinecttest.KinectTest.stop(KinectTest.java:81)
    at sun.applet.AppletPanel.run(AppletPanel.java:525)
    at java.lang.Thread.run(Thread.java:680)

but it did run in Processing though. I've was printing the PVector values via the getAcceleration() method I added, but it was always [0.0,0.0,0.0]. I've added a trace in the direction() method itself(from Acceleration interface) to check, and it wasn't called. I thought I did the implementation wrong and did this basic test:

device.acceleration(new Acceleration()
        {
            public void direction(float x, float y, float z)
            {
                System.out.printf("Acceleration: %f %f %f\n", x ,y ,z);
            }
        });

Still no joy. The think that puzzles me is why doesn't the onAcceleration() method get called, because I've added print statements there too:

void onAcceleration(float x, float y, float z)
    {
        System.out.printf("Device onAcceleration: %f %f %f\n", x ,y ,z);
        if (acceleration != null)
        {
            acceleration.direction(x, y, z);
        }
    }

Any tips/clues would be very helpful. Thank you for your time !

Have a brilliant day, George

shiffman commented 12 years ago

To get it to work in eclipse you need to run with -d32, it has to be 32-bit. The library really needs to be freshened up, but I haven't had the time. I will try to take a look soon!

orgicus commented 12 years ago

Thank you for the reply Daniel. I've got your library compiling nicely in eclipse. I've also managed to compile and run Example.java that comes with the OpenKinect java wrapper and there's something not quite right. I've added println statements to check if I get anything from the Device class. I get a trace when the Accelerometer listener is set, but no callbacks are fired. I'll try to dig deeper and see if I can work out what the issue is. As far as I can see, OpenKinect uses JNI to make calls to the freenect driver. I've got jit.freenect running in MaxMSP and I can get accelerometer data, but clueless to why I can't do the same with OpenKinect/java.

shiffman commented 12 years ago

it might be b/c i haven't rebuilt the JNILIB in a long time, maybe it needs an update. The xcode project is in there too if you want to try updating the source and rebuilding.

orgicus commented 12 years ago

Unfortunately I don't know c/c++/jni yet to able to do the fix(https://github.com/shiffman/libfreenect/blob/master/wrappers/java/processing/KinectJNI_v0002/src/native/org_openkinect_Context.cpp#L149), so I've got two options at the moment: try the OpenKinect JNA wrapper or learn how to fix this.

shiffman commented 10 years ago

This repo has moved to: https://github.com/shiffman/OpenKinect-for-Processing

Closing this issue and will track again anew there.