NXC sin/cos compilation's problem

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
guillaume-b
Posts: 9
Joined: 19 Mar 2013, 08:31

NXC sin/cos compilation's problem

Post 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 !
aswin0
Posts: 201
Joined: 29 Sep 2010, 06:58

Re: NXC sin/cos compilation's problem

Post by aswin0 »

Hi,

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

Aswin
My blog: nxttime.wordpress.com
h-g-t
Posts: 552
Joined: 07 Jan 2011, 08:59
Location: Albania

Re: NXC sin/cos compilation's problem

Post 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);
A sophistical rhetorician, inebriated with the exuberance of his own verbosity, and gifted with an egotistical imagination that can at all times command an interminable and inconsistent series of arguments to malign an opponent and to glorify himself.
bmancan
Posts: 9
Joined: 14 Oct 2012, 01:52

Re: NXC sin/cos compilation's problem

Post 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.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC sin/cos compilation's problem

Post 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
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC sin/cos compilation's problem

Post 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
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
guillaume-b
Posts: 9
Joined: 19 Mar 2013, 08:31

Re: NXC sin/cos compilation's problem

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

Who is online

Users browsing this forum: No registered users and 1 guest