2014-06-16 01:16 AM
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... ?2014-06-16 02:00 AM
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()?2014-06-16 02:12 AM
> 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)2014-06-16 02:18 AM
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); JW2014-06-16 02:25 AM
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.4266742014-06-16 02:42 AM
Hi guys,
thanks alot, i missed that order of y and x .... i swaped y with x and now are ok