This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Thingy 52: Motion sensor (accelerometer) raw data in IOS is giving unit vector, I was expecting more of a m/s2 values. Is my assumption wrong?

Hi, 

I am using Thingy 52 to measure the acceleration from accelerometer. I was expecting values like m/s2 but I am seeing values in unit vector, ie, values between (0 - 1.0), I can't see negative values as well. How do I get actual values, ie, > 1? Please hep if my understanding is wrong.

Parents
  • peripheral.beginRawDataUpdates(withCompletoinHandler: { (success) -> (Void) in

                    NSLog("Raw data update")

                }) { (arr1, arr2, arr3) -> (Void) in

                   NSLog("Raw values  \(arr1)")

              }

    Using the above method when I am printing out the accelerometer values if It is giving me unit vector values. The sample output at console

    2020-08-26 16:27:43.657397+0530 TestThingy[3278:594688] Raw values [1.999939, 1.9993896, 0.030792236]

    2020-08-26 16:27:43.773514+0530 TestThingy[3278:594688] Raw values [1.9995422, 1.9995422, 0.030883789]

    2020-08-26 16:27:43.863515+0530 TestThingy[3278:594688] Raw values [1.9999084, 1.9994812, 0.029724121]

    2020-08-26 16:27:43.953406+0530 TestThingy[3278:594688] Raw values [1.9997864, 1.9995117, 0.031066895]

    2020-08-26 16:27:44.073561+0530 TestThingy[3278:594688] Raw values [3.0517578e-05, 1.9992981, 0.030792236]

    2020-08-26 16:27:44.163526+0530 TestThingy[3278:594688] Raw values [1.9998474, 1.9996643, 0.031036377]

    2020-08-26 16:27:44.255128+0530 TestThingy[3278:594688] Raw values [1.9997559, 1.9992981, 0.030822754]

    2020-08-26 16:27:44.373524+0530 TestThingy[3278:594688] Raw values [1.9996643, 1.9992981, 0.030670166]

    2020-08-26 16:27:44.463550+0530 TestThingy[3278:594688] Raw values [1.9997253, 1.9994202, 0.03112793]

    2020-08-26 16:27:44.553452+0530 TestThingy[3278:594688] Raw values [1.9997864, 1.9995117, 0.03125]

    2020-08-26 16:27:44.673466+0530 TestThingy[3278:594688] Raw values [1.9998474, 1.9996338, 0.031280518]

    2020-08-26 16:27:44.763441+0530 TestThingy[3278:594688] Raw values [1.9997253, 1.9994507, 0.030883789]

    2020-08-26 16:27:44.853481+0530 TestThingy[3278:594688] Raw values [1.9997253, 1.999939, 0.028198242]

    2020-08-26 16:27:44.973456+0530 TestThingy[3278:594688] Raw values [1.9999695, 1.9994507, 0.031097412]

    2020-08-26 16:27:45.063600+0530 TestThingy[3278:594688] Raw values [1.9997253, 1.9996033, 0.030975342]

    2020-08-26 16:27:45.153845+0530 TestThingy[3278:594688] Raw values [1.9996338, 1.9993896, 0.030883789]

    2020-08-26 16:27:45.273472+0530 TestThingy[3278:594688] Raw values [1.9998169, 1.9997864, 0.030883789]

    2020-08-26 16:27:45.363565+0530 TestThingy[3278:594688] Raw values [1.9999695, 1.9994812, 0.031188965]

    2020-08-26 16:27:45.483496+0530 TestThingy[3278:594688] Raw values [1.9998779, 1.9995728, 0.031433105]

    2020-08-26 16:27:45.573569+0530 TestThingy[3278:594688] Raw values [1.9996643, 1.9993591, 0.031951904]

    2020-08-26 16:27:45.664374+0530 TestThingy[3278:594688] Raw values [9.1552734e-05, 1.9993286, 0.0317688]

    2020-08-26 16:27:45.753466+0530 TestThingy[3278:594688] Raw values [0.0, 1.9996338, 0.030700684]

    2020-08-26 16:27:45.873450+0530 TestThingy[3278:594688] Raw values [0.00024414062, 1.9993286, 0.030639648]

    2020-08-26 16:27:45.963469+0530 TestThingy[3278:594688] Raw values [1.9994812, 1.9995117, 0.030914307]

    2020-08-26 16:27:46.083952+0530 TestThingy[3278:594688] Raw values [1.9997253, 1.9992981, 0.030975342]

    2020-08-26 16:27:46.173524+0530 TestThingy[3278:594688] Raw values [1.9998169, 1.9991455, 0.03112793]

  • Hi,

    The raw data from the motion characteristic must sampled and converted correctly to obtain the m/s2 accelerometer data. The reason for this is that the measurements from all three motion sensors(accelerometer, gyroscope and compass) are sent as one. The link I previously posted points to how this is done in the app and I recommend following it as an example. Could you try that? Here is the link again.

    Best regards,
    Carl Richard

  • Thanks for clearing up. 

    Firstly. The documentation states that the raw data from the accelerometer is in Gs, just do make that clear. Hence, if you want m/s2 the raw data must be divided by 9.8. 

    However, the values you posted earlier does seem weird. Could you try to subtract 2 from every value and divide by 1G. It seems like the values are offset by 2G :) 

    Best regards,
    Carl Richard

  • Hi Carl,

    I have implemented as you suggested. Below is my code 

    peripheral.beginRawDataUpdates(withCompletoinHandler: { (success) -> (Void) in

                    NSLog("Raw Data Update")

                }) { (acc, gyro, compose) -> (Void) in

                    var trimmedX = (acc[0] - 2.0)/9.8

                    var trimmedY = (acc[1] - 2.0)/9.8

                    var trimmedZ = (acc[2] - 2.0)/9.8

                    if abs(trimmedX) < 0.05 {

                        trimmedX = 0.0

                    }

                    if abs(trimmedY) < 0.05 {

                        trimmedY = 0.0

                    }

                    if abs(trimmedZ) < 0.05 {

                        trimmedZ = 0.0

                    }

                    NSLog("trimmed X: \(trimmedX), Y: \(trimmedY), Z:\(trimmedZ)")

                }

    But I didn't see the output I was expecting. Please find the log below while I was shaking the device.

    2020-08-28 12:12:25.971478+0530 TestThingy[706:49448] trimmed X: -0.2040754, Y: 0.0, Z:-0.20095825

    2020-08-28 12:12:26.061594+0530 TestThingy[706:49448] trimmed X: -0.20329377, Y: -0.20396952, Z:-0.20080255

    2020-08-28 12:12:26.181168+0530 TestThingy[706:49448] trimmed X: -0.20334049, Y: -0.20303842, Z:-0.19916767

    2020-08-28 12:12:26.271155+0530 TestThingy[706:49448] trimmed X: 0.0, Y: 0.0, Z:-0.2011451

    2020-08-28 12:12:26.361205+0530 TestThingy[706:49448] trimmed X: -0.20364878, Y: 0.0, Z:-0.20216027

    2020-08-28 12:12:26.481102+0530 TestThingy[706:49448] trimmed X: -0.19780372, Y: -0.20232843, Z:-0.20008631

    2020-08-28 12:12:26.571227+0530 TestThingy[706:49448] trimmed X: -0.19770408, Y: -0.19878154, Z:-0.20184264

    2020-08-28 12:12:26.661201+0530 TestThingy[706:49448] trimmed X: -0.19885628, Y: -0.20355847, Z:-0.19991817

    2020-08-28 12:12:26.781093+0530 TestThingy[706:49448] trimmed X: -0.20280176, Y: 0.0, Z:-0.20059702

    2020-08-28 12:12:26.871109+0530 TestThingy[706:49448] trimmed X: 0.0, Y: 0.0, Z:-0.20178658

    2020-08-28 12:12:26.991072+0530 TestThingy[706:49448] trimmed X: -0.20233466, Y: 0.0, Z:-0.19944483

    2020-08-28 12:12:27.081696+0530 TestThingy[706:49448] trimmed X: -0.19770408, Y: -0.20360518, Z:-0.19858535

    2020-08-28 12:12:27.171119+0530 TestThingy[706:49448] trimmed X: -0.19770408, Y: -0.19770408, Z:-0.19949153

    2020-08-28 12:12:27.261592+0530 TestThingy[706:49448] trimmed X: -0.1988656, Y: 0.0, Z:-0.20040706

    2020-08-28 12:12:27.381122+0530 TestThingy[706:49448] trimmed X: 0.0, Y: 0.0, Z:-0.20167136

    2020-08-28 12:12:27.471149+0530 TestThingy[706:49448] trimmed X: 0.0, Y: 0.0, Z:-0.20258689

    2020-08-28 12:12:27.561099+0530 TestThingy[706:49448] trimmed X: -0.19964412, Y: -0.19770408, Z:-0.19770408

    2020-08-28 12:12:27.681090+0530 TestThingy[706:49448] trimmed X: -0.2024561, Y: -0.20305088, Z:-0.20010188

    2020-08-28 12:12:27.771100+0530 TestThingy[706:49448] trimmed X: 0.0, Y: 0.0, Z:-0.20204194

    2020-08-28 12:12:27.980452+0530 TestThingy[706:49448] trimmed X: 0.0, Y: 0.0, Z:-0.20107658

    2020-08-28 12:12:27.981793+0530 TestThingy[706:49448] trimmed X: 0.0, Y: 0.0, Z:-0.20020154

    2020-08-28 12:12:28.071640+0530 TestThingy[706:49448] trimmed X: 0.0, Y: 0.0, Z:-0.20079944

    2020-08-28 12:12:28.161182+0530 TestThingy[706:49448] trimmed X: 0.0, Y: 0.0, Z:-0.20103921

  • Hi Carl,

    Solving this problem is important to me. Request you to help.

    Thanks & Regards,

    K.Prabhakar

  • Hello again!

    My apologies. I mixed up my unit conversion. You should multiply by 9.8. Hopefully that will result in correct values.

    Best regards,
    Carl Richard

  • Hi Carl,

    Thanks for the update.

    I have seen below code for Android

    final float mAccelerometerX = (float) (characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_SINT16, 0)) / (1 << 10);

    final float mAccelerometerY = (float) (characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_SINT16, 2)) / (1 << 10);

    final float mAccelerometerZ = (float) (characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_SINT16, 4)) / (1 << 10);

    And for IOS below is the code

    accelerometerData.append(Float(rawData.asValue(offset: 0) as UInt16) / Float(2 << 14))

    accelerometerData.append(Float(rawData.asValue(offset: 2) as UInt16) / Float(2 << 14))

    accelerometerData.append(Float(rawData.asValue(offset: 4) as UInt16) / Float(2 << 14))

    For android signed int is considered and for IOS it is unsignedINT. Please help me in understanding this part because I have to build the app for both IOS and Android. And if you notice the bit shifting is also different for both of the platforms.

    Regards,

    K.Prabhakar

Reply
  • Hi Carl,

    Thanks for the update.

    I have seen below code for Android

    final float mAccelerometerX = (float) (characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_SINT16, 0)) / (1 << 10);

    final float mAccelerometerY = (float) (characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_SINT16, 2)) / (1 << 10);

    final float mAccelerometerZ = (float) (characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_SINT16, 4)) / (1 << 10);

    And for IOS below is the code

    accelerometerData.append(Float(rawData.asValue(offset: 0) as UInt16) / Float(2 << 14))

    accelerometerData.append(Float(rawData.asValue(offset: 2) as UInt16) / Float(2 << 14))

    accelerometerData.append(Float(rawData.asValue(offset: 4) as UInt16) / Float(2 << 14))

    For android signed int is considered and for IOS it is unsignedINT. Please help me in understanding this part because I have to build the app for both IOS and Android. And if you notice the bit shifting is also different for both of the platforms.

    Regards,

    K.Prabhakar

Children
Related