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 !
NXC sin/cos compilation's problem
Re: NXC sin/cos compilation's problem
Hi,
Could it be that Cos ad Sin use radians instead of degrees?
Aswin
Could it be that Cos ad Sin use radians instead of degrees?
Aswin
My blog: nxttime.wordpress.com
Re: NXC sin/cos compilation's problem
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);
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.
Re: NXC sin/cos compilation's problem
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.
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
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:
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
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°
https://sourceforge.net/apps/phpbb/mind ... p?f=3&t=49
Re: NXC sin/cos compilation's problem
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
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
-
- Posts: 9
- Joined: 19 Mar 2013, 08:31
Re: NXC sin/cos compilation's problem
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.
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.
Who is online
Users browsing this forum: No registered users and 3 guests