cancel
Showing results for 
Search instead for 
Did you mean: 

how to use atan2(x,y)

thorsten2
Associate II
Posted on December 02, 2009 at 07:56

how to use atan2(x,y)

6 REPLIES 6
thorsten2
Associate II
Posted on May 17, 2011 at 13:32

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,

Thorsten

thorsten2
Associate II
Posted on May 17, 2011 at 13:32

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 ]

hbliek
Associate II
Posted on May 17, 2011 at 13:32

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...

thorsten2
Associate II
Posted on May 17, 2011 at 13:32

Hi,

yes, but it doesn't work.

I think it is this problem

http://www.st.com/mcu/forums-cat-9094-23.html

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,

Thorsten

thorsten2
Associate II
Posted on May 17, 2011 at 13:32

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,

Thorsten

thorsten2
Associate II
Posted on May 17, 2011 at 13:32

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