You are reading a single comment by @HughB and its replies. Click here to read the full conversation.
  • M value? Acceleration magnitude?

    Yes Magnitude.

    We should really be doing the same stuff in the test harness.

    Yes - need to be the same so we can do predicatble modelling that will match the real world measures when actually walking with the device etc.

    I was not sure if the accelerometer chip does the calculation for magnitude OR the firmware does it. In the test harness I can see the In32_sqrt() function. Is this the same in the Bangle firmware. Was not sure where to look in the code.

    Found this in ./libs/banglejs/jswrap_bangle.c

    JsVar *jswrap_banglejs_getAccel() {
      JsVar *o = jsvNewObject();
      if (o) {
        jsvObjectSetChildAndUnLock(o, "x", jsvNewFromFloat(acc.x/8192.0));
        jsvObjectSetChildAndUnLock(o, "y", jsvNewFromFloat(acc.y/8192.0));
        jsvObjectSetChildAndUnLock(o, "z", jsvNewFromFloat(acc.z/8192.0));
        jsvObjectSetChildAndUnLock(o, "mag", jsvNewFromFloat(sqrt(accMagSquared)/8192­.0));
        jsvObjectSetChildAndUnLock(o, "diff", jsvNewFromFloat(sqrt(accdiff)/8192.0));
      }
      return o;
    }
    

    Found this in
    ./targetlibs/nrf5x_15/external/micro-ecc­/curve-specific.inc

    static void mod_sqrt_default(uECC_word_t *a, uECC_Curve curve) {
      ...
    }
    

    Not really sure how this compares to:
    Espruino/libs/misc/stepcount.c

    
    // quick integer square root
    // https://stackoverflow.com/questions/3111­7497/fastest-integer-square-root-in-the-­least-amount-of-instructions
    unsigned short int int_sqrt32(unsigned int x) {
      unsigned short int res=0;
      unsigned short int add= 0x8000;
      int i;
      for(i=0;i<16;i++) {
        unsigned short int temp=res | add;
        unsigned int g2=temp*temp;
        if (x>=g2)
          res=temp;
        add>>=1;
      }
      return res;
    }
    

    Apologies I think * is confusing the code formatter

About

Avatar for HughB @HughB started