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 票)
RE: Sensor Fusion / Get Rotation Data in Eclipse Mita
19-5-21 下午2:45 回复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,


0 (0 票)
RE: Sensor Fusion / Get Rotation Data in Eclipse Mita
19-5-21 下午3:58 回复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):



#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_ */


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",


    // TODO somehow return the values here

    return retcode;


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) {
        virtual_sensor_initialized = true;
    } else {
       // TODO somehow get the values here
0 (0 票)