I am working with Eclipse Mita and I want do create a functionality similar to the Virtual XDK Demo app for iOS/Android, where you see the orientation of the XDK in the app.

By studying the source code of the VirtualXDKDemo i found that while the app displays the XDK device and it's rotation, it is in "high priority data mode" and transmits the rotational data (instead of the raw Accelerometer/Gyro/Magnetometer data) in form of a Quaternion, which is calculated by

VirtualSensor_GetRotationData(&rotationData, ROTATION_QUATERNION);

I am unable to find the source code that does this "Sensor Fusion", creating a quaternion from the different sensors, which I would basically like to copy/recreate.

Can anyone point me to some more in depth info on how to calculate the full 360° rotation (e.g. in form of a Quaternion) from the Acclerometer and Magnetometer (probably also the Gyro?) data or if and how I can access the source/implementation of Rotation_readQuaternionValue (in BCDS_Rotation.h)

Or is it possible to use the above function in my Mita application, by including some wrapper method in native code? If so, how would I do this?

0 (0 Votes)
RE: Sensor Fusion / Get Rotation Data in Eclipse Mita
Answer
5/21/19 2:45 PM as a reply to Claus Helfenschneider.

Hello Claus,

It is possible to use C-APIs in Mita if they are declared and included as "foreign functions" http://www.eclipse.org/mita/language/foreignfunctioninterface/  

Best regards,

Francisco

0 (0 Votes)
RE: Sensor Fusion / Get Rotation Data in Eclipse Mita
Answer
5/21/19 3:58 PM as a reply to Francisco Llobet Blandino.

Hi Francesco,

thanks for the quick reply! I knew that, but was unsure if I could make it. Anyway, in the meantime, I worked it out.

In case anyone else needs this, here are some code snippets. The only thing that is missing is how to return the 4 values to the mita app. (I didn't figure this out because what I do instead is i use an unchecked function with a uint32 return value and pack the 4 floats into one uint32 with a bit of bit and byte magic):

native_funcs.h

#ifndef NATIVE_FUNCS_H_
#define NATIVE_FUNCS_H_

#include <stdio.h>
#include <stdint.h>

#include "BCDS_Retcode.h"
#include "XDK_VirtualSensor.h"

Retcode_T VirtualSensorSetup(void*);
Retcode_T VirtualSensorRotationRead(void*);

#endif /* NATIVE_FUNCS_H_ */

native-funcs.c

Retcode_T VirtualSensorSetup(void *result) {
    Retcode_T retcode = RETCODE_OK;
    VirtualSensor_Setup_T setup;
    setup.Enable = VirtualSensors;
    retcode = VirtualSensor_Setup(&setup);
    if (retcode == RETCODE_OK) {
        retcode = VirtualSensor_Enable();
    }

    return retcode;
}

Retcode_T VirtualSensorRotationRead(void *result) {
    Retcode_T retcode;
    VirtualSensor_DataType_T rotationData;

    retcode = VirtualSensor_GetRotationData(&rotationData, ROTATION_QUATERNION);
    if (RETCODE_OK == retcode) {
        printf("Rotation - Quaternion : %3.2f %3.2f %3.2f %3.2f\n\r",
                rotationData.RotationQuaternion.W,
                rotationData.RotationQuaternion.X,
                rotationData.RotationQuaternion.Y,
                rotationData.RotationQuaternion.Z);

    }

    // TODO somehow return the values here

    return retcode;
}

application.mita

native checked fn VirtualSensorSetup(): void
    header "native_funcs.h";

native checked fn VirtualSensorRotationRead(): void
    header "native_funcs.h";

var virtual_sensor_initialized : bool = false;

every 200 milliseconds {
    if (virtual_sensor_initialized == false) {
        VirtualSensorSetup();
        virtual_sensor_initialized = true;
    } else {
       VirtualSensorRotationRead();
       // TODO somehow get the values here
    }
}
0 (0 Votes)