Bug
I've added pedometer capability to my project in the previous blog post. And to add this feature I've switched IMU library to one provided by Sparkfun, which is exposing the pedometer function of IMU. Even these libraries were built for the same chip, they have a bit different APIs. So I've done migration to Sparkfun API.
#ifdef __LSM6DS3IMU_H__ buffer[ix + 1] = myIMU.readFloatAccelX(); buffer[ix] = myIMU.readFloatAccelY(); buffer[ix + 2] = myIMU.readFloatAccelZ(); #endif #ifdef _ARUDINO_LSM6DS3_H_ // if define Arduino_LSM6DS3.h IMU.readAcceleration(buffer[ix + 1], buffer[ix], buffer[ix + 2]); //IMU.readAcceleration(buffer[ix], buffer[ix + 1], buffer[ix + 2]); not adjusted to orientation #endif buffer[ix + 0] *= CONVERT_G_TO_MS2; buffer[ix + 1] *= CONVERT_G_TO_MS2; buffer[ix + 2] *= -CONVERT_G_TO_MS2;
But than I discovered that behavior of my posture tracker become quite different. It basically didn't like any of my postures and classified them as a bad posture. As the code was quite trivial, I've start thinking why the results so different. May be API enumerates axis differently? Or may be it is converting values?
I've compared values and realized that Sparkfun provides converted values. So I move conversion code in a section specific to Arduino library.
Fix #1
#ifdef __LSM6DS3IMU_H__ buffer[ix + 1] = myIMU.readFloatAccelX(); buffer[ix] = myIMU.readFloatAccelY(); buffer[ix + 2] = myIMU.readFloatAccelZ(); #endif #ifdef _ARUDINO_LSM6DS3_H_ // if define Arduino_LSM6DS3.h IMU.readAcceleration(buffer[ix + 1], buffer[ix], buffer[ix + 2]); //IMU.readAcceleration(buffer[ix], buffer[ix + 1], buffer[ix + 2]); not adjusted to orientation buffer[ix + 0] *= CONVERT_G_TO_MS2; buffer[ix + 1] *= CONVERT_G_TO_MS2; buffer[ix + 2] *= -CONVERT_G_TO_MS2; #endif
But it didn't help. So I've start thinking about rebuilding the model. I was not really like this idea as the model built from a phone sensor was working fine with the Arduino library and should still work well with another library for the same chip. As result I've switched to other activities like reading Cryptonomicon by Neal Stephenson, which is more than 900 pages long.
Fix #2
After a week of procrastination and after finishing the book I decided to look at my code again. And I was able to fix it relatively fast. I've realized that I've missed one transformation. on line 4. Just by adding a minuart working as expected. And i realized that this bug was a side effect of my fix #1.
#ifdef __LSM6DS3IMU_H__ buffer[ix + 1] = myIMU.readFloatAccelX(); buffer[ix] = myIMU.readFloatAccelY(); buffer[ix + 2] = -myIMU.readFloatAccelZ(); #endif #ifdef _ARUDINO_LSM6DS3_H_ // if define Arduino_LSM6DS3.h IMU.readAcceleration(buffer[ix + 1], buffer[ix], buffer[ix + 2]); //IMU.readAcceleration(buffer[ix], buffer[ix + 1], buffer[ix + 2]); not adjusted to orientation buffer[ix + 0] *= CONVERT_G_TO_MS2; buffer[ix + 1] *= CONVERT_G_TO_MS2; buffer[ix + 2] *= -CONVERT_G_TO_MS2; #endif
Demo
Now I can use it again. So I was able to capture a short demo of my wearable device. On the video initially I have a bad posture. It can be observed by looking at light from a yellow LED on MCU, some vibration and a red message on the phone. Than I change my posture (at 7th second) and the LED gets switched off (at 9th second) and the red alert disappears on the phone at the same time.