-->
Page 1 of 3

math.h sqrt

PostPosted: Thu Sep 22, 2016 2:34 pm
by dwindey1
Hi,
I am building a quadcopter with an ESP8266 as a flight controller. In theory is could work. For the 'transmitter' Blynk over wifi is used (via a Raspberry Pi Blynk server). An MPU6050 sensor is used for balancing.
But it seems the ESP8266 math.h library (from Arduino IDE) is missing the sqrt() function necessary to calculate angles.
Anyone knows where to find a math.h library with the sqrt function, or knows a way to calculate angles (from an accellerometer G value) without need of a square root, or has a suggestion of any other way to get there.
I am looking into this problem for a few weeks now and I'm getting a bit frustrated :-). And it would be a pitty not being able to use our favorite controller.

thanks

Re: math.h sqrt

PostPosted: Thu Sep 22, 2016 2:52 pm
by RichardS
A really fast sqrt() function I wrote once....

Just a thought.... you might want a float one....

RichardS

Code: Select allconst uint16_t sqrt_integer_guess_table[33] = {
55109,
38968,
27555,
19484,
13778,
 9742,
 6889,
 4871,
 3445,
 2436,
 1723,
 1218,
  862,
  609,
  431,
  305,
  216,
  153,
  108,
   77,
   54,
   39,
   27,
   20,
   14,
   10,
    7,
    5,
    4,
    3,
    2,
    1,
    0
};

__INLINE uint32_t sqrt_uint32(uint32_t in)
{
   uint32_t n = sqrt_integer_guess_table[__builtin_clz(in)];
   n = ((in / n) + n) / 2;
   n = ((in / n) + n) / 2;
   n = ((in / n) + n) / 2;
   return n;
}

Re: math.h sqrt

PostPosted: Thu Sep 22, 2016 2:58 pm
by RichardS
How about pow(x,0.5)??

RichardS

Re: math.h sqrt

PostPosted: Thu Sep 22, 2016 3:04 pm
by RichardS
OK I just tested:

pow(4.3,0.5);

and

sqrt(4.3);

and they both work for me...

Arduino board support for ESP8266 2.3.0

RichardS