cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 and double returning value divided by 10.

Bogdan
Senior
Posted on June 16, 2014 at 10:16

Hi guys, i recently started to work with orientations and quaternions.

Said to do a little math in paralel with my program with a excel spreadsheet.

I have the following q`s values

double q1=0.99551634;

double q2=-0.0699638;

double q3=-0.0396818;

double q4=-0.0497758;

char txt[10];

double qaa=2*q3*q4-2*q1*q2;

double qbb=2*q1*q1+2*q4*q4-1;

float qqq=atan2(qaa,qbb);

sprintf(pitch,''%f'',qqq );

UB_LCD_2x16_String(1,1,text);

With the given values for each q, the atan2 result is 0.144122 on my lcd display.

Doing the same math and the same values in a excel spreadsheet, the result is

1.426674134.

Tryied even with double for my qqq, but the result is the same.

I wonder why... ?
5 REPLIES 5
ivani
Associate II
Posted on June 16, 2014 at 11:00

It probably should be:

sprintf(txt,''%f'',qqq );

And one more thought: Isn't the order of arguments in the Excel reversed versus C atan2()?

Trev
Associate II
Posted on June 16, 2014 at 11:12

> double qaa=2*q3*q4-2*q1*q2;

> double qbb=2*q1*q1+2*q4*q4-1;

I'd use some brackets here to ensure it does what you expect (and allow us to know what you intended)

Posted on June 16, 2014 at 11:18

While spreadsheet calculators assume ATAN2(x, y), C has a different order of arguments, see C99 7.12.4.4

#include <math.h>

double atan2(double y, double x);

float atan2f(float y, float x);

long double atan2l(long double y, long double x);

JW
zzdz2
Associate II
Posted on June 16, 2014 at 11:25

Apparently the problem has nothing to do with STM32. 

I just compiled your function on my pc and it prints 0.144122.

You would better ask on some excel forum.

Edit: You guys solved it, different order of arguments gives 1.426674

Bogdan
Senior
Posted on June 16, 2014 at 11:42

Hi guys,

thanks alot, i missed that order of y and x ....

i swaped y with x and now are ok