Page 1 of 1

NXC sin/cos compilation's problem

Posted: 19 Mar 2013, 09:11
by guillaume-b
Hi guys,
I'm working on NXT with a differential mobile robot structure. For the moment I'm trying to get a good localisation of the robot. So firstly I try the odometer and the why not implement a Kalman with the odometer, compass and accelerometer sensors later.
I meet some problem with the sin and cos functions the compilation return an error : Undefined Identifier sin, and the same for the cos function.
So my first question, Is anybody know what is the problem ? And How can I resolve this problem? (the Firmware version is 1.31)

So I tried the Cos and Sin functions, that take a degree angle and return a number between -100 and 100, they works but my localisation is very bad.
I made a test where I save the odometer datas and then I implement the algorithme on Matlab. The result is fine so I suppose that the Cos and Sin approximation is the problem.

I don't find the library source code of all the math functions (NXC), where are they saved ?

Sorry if my english is not clear or is not gramaticaly correct ! (stupid french speaker !)
Thanks for help me !

Re: NXC sin/cos compilation's problem

Posted: 20 Mar 2013, 00:01
by aswin0
Hi,

Could it be that Cos ad Sin use radians instead of degrees?

Aswin

Re: NXC sin/cos compilation's problem

Posted: 20 Mar 2013, 02:41
by h-g-t
Sin(degrees) Value
Return the sine of the specified degrees value. The result is 100 times the sine value (-100..100).
x = Sin(theta);

Cos(degrees) Value
Return the cosine of the specified degrees value. The result is 100 times the cosine
value (-100..100).
x = Cos(y);

Re: NXC sin/cos compilation's problem

Posted: 20 Mar 2013, 02:43
by bmancan
Are you using the standard 1.31 firmware or the enhanced 1.31 NBC/NXC firmware?

Here is the info from the NXC API documentation.

float sin (float x)
Compute sine.

Computes the sine of an angle of x radians.

Parameters
x Floating point value representing an angle expressed in radians.
Returns
Sine of x.
Warning
This function requires the enhanced NBC/NXC firmware.

Re: NXC sin/cos compilation's problem

Posted: 20 Mar 2013, 08:43
by HaWe
Sin and Cos (upper case) are not the correct C functions (IMO, they should be erased out of the API).
The correct C (NXC) functions are:

Code: Select all

sin // radians, one full turn=2*PI
cos //  radians, one full turn=2*PI
sind // degrees, one full turn=360°
cosd // degrees, one full turn=360°
NXC requrires the latest NXC/NBC compiler and the latest enhanced firmware! See different thread!
https://sourceforge.net/apps/phpbb/mind ... p?f=3&t=49

Re: NXC sin/cos compilation's problem

Posted: 21 Mar 2013, 02:48
by afanofosc
sin and cos will not compile if you do not tell the compiler to target the enhanced NBC/NXC firmware. If you do not have the enhanced NBC/NXC firmware on your brick then you will have to use Sin and Cos which do work with degrees and do scale the output by 100. I do not think these functions would cause any serious trouble with your localization so long as you divide the scaled result by 100 before you try to use it - and use a float variable to store the result rather than an int.

John Hansen

Re: NXC sin/cos compilation's problem

Posted: 21 Mar 2013, 09:19
by guillaume-b
OK. Thanks all.
I finally follow the information on the very good link (https://sourceforge.net/apps/phpbb/mind ... p?f=3&t=49).

My firmware was the standart and I now I have the enhanced , I never paid intension on the difference of these two Firmwares.
So now my sin and cos works correctly. I knew the difference between the both sin/Sin and cos/Cos but I think the Sin and Cos function are not very accurate, after divided by 100 we always have two decimal. And the uses of sin/cos (in radian) is more conventional.

It was my first post on this forum, and very happy of the result !
Thanks guys !

If I meet any other trouble I will ask you.