2009-12-01 10:56 PM
how to use atan2(x,y)
2011-05-17 04:32 AM
Hi,
I try to use atan2(x,y) but I have a problem in some cases. If I try this one: double x = 1; double y = 1; double z = atan2(x,y); I can compile the code with the CodeSourcery Toolchain. If I try the same with s16 or u16 instead of double it works also. But if I try to use my variables it does not work. vu16 ADCSensorValue[7]; double z = atan2(ADCSensorValue[ACC_X],ADCSensorValue[ACC_X]); I get: sensor.c:(.text+0xaa): undefined reference to `atan2' I tried also u16, s16 and copied the values befor atan2() but the same error. Please help me - thanks! Regards, Thorsten2011-05-17 04:32 AM
More Info, if I try this:
u16 x[2]; x[0] = 12; double z; z = 12; double y = atan2 (z, x); It works. - If I use volatile vu16 x[2]; x[0] = 12; double z; z = 12; double y = atan2 (z, x[0]); I get an error. Also if I try this: vu16 x[2]; x[0] = 12; double zz = x[0]; double z; z = 12; double y = atan2 (z, zz); I get the error :-[ sensor.c:(.text+0x8e): undefined reference to `atan2' collect2: ld returned 1 exit status cs-make.exe: *** [main.elf] Error 1 I think the volatile is the problem - but I don't know how I can solve it. Regards, Thorsten [ This message was edited by: thorsten.raab on 30-11-2009 08:01 ]2011-05-17 04:32 AM
Have you tried to cast the volatiles to normal?
double z = atan2((u16)ADCSensorValue[ACC_X],(u16)ADCSensorValue[ACC_X]); or double z = atan2((double)ADCSensorValue[ACC_X],(double)ADCSensorValue[ACC_X]); The step with double variable in between probably doesn't work because the optimizer throws it away...2011-05-17 04:32 AM
Hi,
yes, but it doesn't work. I think it is this problem But I don't know how I can solve it. Can anyone help me what I have to change in the codesourcery toolchain with the enviroment from lanchon (http://www.st.com/mcu/forums-cat-6304-23.html) Thanks Regards, Thorsten2011-05-17 04:32 AM
If I use atan(x) instead of atan2(x,y) it works
????? I don't know why ... What is the difference to atan2(x,y)? Both functions are in the math.h. Regards, Thorsten2011-05-17 04:32 AM
I think I found the problem.
If I change the line 22 in file lanchon-stm32.ld it works :D from:Code:
GROUP(libgcc.a libc.a libcs3.a libcs3unhosted.a libcs3-lanchon-stm32.a)
to:Code:
GROUP(libgcc.a libc.a libm.a libcs3.a libcs3unhosted.a libcs3-lanchon-stm32.a)
maybe there is a better solution - if yes please let me know. Regards, Thorsten