View unanswered posts | View active topics It is currently Sat Aug 17, 2019 11:01 am

 Page 1 of 1 [ 7 posts ]
 Print view Previous topic | Next topic
crashing RobotC with cos and sin
Author Message
Rookie

Joined: Mon Mar 10, 2008 5:03 pm
Posts: 5
crashing RobotC with cos and sin
Hallo,
I have had some problems with RobotC lately. I tried to use some sine, cos and tangent calculations in a funktion, but every time I to download the file to the NXT RobotC closed itself. The compiler seems to work althought it gives me a "warning: Unreferenced procedure" at the beginning of the funktion. after this mistake oocured the first time, the compiler still finds no error, but the entire programm shuts down without an error every time, even when I removed the part that cuses the warning messages.

The problem is that I don't even know exacly, if I used the sine and cosine correctly, so it might be a help, if somebody could tell me.

[void Werteberechnung()
{

ual = (23 * (cos(uual)) / (sin(uual))) - 3.05;
uar = (23 * (cos(uuar)) / (sin(uuar))) + 3.05;

al = atan(ual);
ar = atan(uar);

}

al and ar are float variables and will be given to the other 2 motors

If you need more information of the code to be able to help me, you just have to ask for it. Thanks already for the effort.[/code]

Tue Mar 11, 2008 4:48 am
Guru

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030

 JPWingman wrote: [void Werteberechnung()

is this the mistake? : [void

other possible errors:

sin(uual) must always be<>0 (no devision by zero!)
you have to handle the exceptions when sin(uual)==0!

 Code:if (sin(uual)!=0){     ual = (23 * (cos(uual)) / (sin(uual))) - 3.05;    uar = (23 * (cos(uuar)) / (sin(uuar))) + 3.05;}else // else what?{...}

but cos/sin=cotangens=1/tan,
why don't you use that?
 Code:ual=(23*cot(uual))-3.05;

BTW: be aware that atan itself has undefined points (German: Unstetigkeitsstellen). see my solution:
 Code:// ArcusTangens mit Sonderfaellen// x=Ankathete y=Gegenkathete Tangens=y/xfloat atan2(float x, float y){  float phi; //phi=radians   if (x>0) {phi=atan(y/x);}   else   if ((x<0)&&(y>=0))  {phi=PI+atan(y/x);}   else   if ((x<0)&&(y<0))   {phi=-PI+atan(y/x);}   else   if ((x==0)&&(y>0))  {phi=PI/2;}   else   if ((x==0)&&(y<0))  {phi=-PI/2;}   else   if ((x==0)&&(y==0)) {phi=0;}   return phi;}float atan2Degrees(float x, float y){  float phi;  //phi=radians   if (x>0) {phi=atan(y/x);}   else   if ((x<0)&&(y>=0))  {phi=PI+atan(y/x);}   else   if ((x<0)&&(y<0))   {phi=-PI+atan(y/x);}   else   if ((x==0)&&(y>0))  {phi=PI/2;}   else   if ((x==0)&&(y<0))  {phi=-PI/2;}   else   if ((x==0)&&(y==0)) {phi=0;}   return radiansToDegrees(phi);   }

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)

Tue Mar 11, 2008 6:38 am
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 616
Re: crashing RobotC with cos and sin
 JPWingman wrote:I have had some problems with RobotC lately. I tried to use some sine, cos and tangent calculations in a funktion, but every time I to download the file to the NXT RobotC closed itself.
ROBOTC should not "close itself" even if there were compile errors. If you send me the file (and not code snippet) that causes this I will debug and fix. Use dickswan@sbcglobal.net

Wed Mar 12, 2008 5:37 am
Rookie

Joined: Mon Mar 10, 2008 5:03 pm
Posts: 5

Thank you for the reply, I really appreciate it

the first mistake you pointed out is a posting mistake (sory),
" [void Werteberechnung() " just exists as " void Werteberechnung() " so it is not the big problem.

I also tried to avoid a devision by zero. I will give you some more code to give you some more information about it and how I tried it.

What i am trying to program is kind of a motorbike with 2 front wheels, like a car. When a car drives a kurve, the inner wheel has to have asteeper angle than the outer wheel. The angles should be calculated by the funktion, which I have problems with at the moment.

motorB is used as a remote control. I'd like to give the angle via motorB. The motors A and C should take the calculated angle they need to let the entire car drive a nice circle.

if ((nMotorEncoder[motorB]/3 > -82) && (-1 < nMotorEncoder[motorB]/3))
{
Werteberechnung_rechts();
}
else
{
if ((1 < nMotorEncoder[motorB]/3) &&
(82 > nMotorEncoder[motorB]/3))
{
Werteberechnung_rechts();
}

the code above is "supposed" to avoid a devision by 0 and also than the wheels can turn more than 180°.

the funktions Werteberechnung_links() and Werteberechnung_rechts() should calculate the values for the motors A and C

{
if ( nMotorEncoder[motorB] != 0)
{
uual = (PI/180) * nMotorEncoder[motorB];
ual = (23 * cot(uual)) - 3.05;
al = (180/PI) * atan(ual);
return al;
}
}

float Werteberechnung_rechts()
{
if ( nMotorEncoder[motorB] != 0)
{
uuar = (PI/180) * nMotorEncoder[motorB];
uar = (23 * cot(uuar)) + 3.05;
ar = (180/PI) * atan(uar);
return ar;
}
}

the remaining code works perfectly, including the one which let the motors turn at the end.

My problem now is that the message "Unreferenced procedure 'Werteberechnung_links' " still remains. It is the same with the other posted funktion " Werteberechnung_rechts() " and that the program itsself doesn't know " cot() " ( could it be that I have an older version of RobotC? ).

Already lots of thanks for any replies that come.
[/code]

Thu Mar 20, 2008 8:04 am
Guru

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030

quick and dirty in German:

hast du beide Funktionen vor der aufrufenden Funktion definiert?
Falls nicht: schreib sie einfach nochmal ganz nach oben, aber ohne die {}, einfach mit Semikolon dahinter, also:
 Code:float Werteberechnung_links();float Werteberechnung_rechts(); // (...)// dann der Rest des Codes

Falls cot(x) unbekannt ist, schreib dafür einfach (1/tan(x)).
Dann darf der tan aber nicht gleich null werden (Nullstellen vorher ausschließen und als Sonderfälle definieren, wie bei meinem atan2!)

müsste doch mit dem Teufel zugehen, wenn der Compiler dann immer noch meckert

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)

Thu Mar 20, 2008 8:41 am
Rookie

Joined: Mon Mar 10, 2008 5:03 pm
Posts: 5

then a reply (dirty and quick in german as well)

Sieht so aus als Haettest du den Nagel auf den Kopf getroffen. Hab die Funktion jetzt einfach vor der Funktion definiert, in der sie dann angewendet werden.

Divisionen durch 0 gibt es nicht und das Programm wurde auch endlich auf den NXT gelanden.
(Tangens kennt er zwar nicht, aber da kann man sich ja noch mit dem sinus und Cosinus helfen)

Vielen Dank nochmal

Thu Mar 20, 2008 11:02 am
Guru

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030

prego

kennst du eigentlich "das" deutsche Mindstorms-Forum?
mit RobotC Unterforum?

http://www.mindstormsforum.de/viewforum.php?f=47&sid=232f0c0c2974030a414fee3895b36480

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)

Thu Mar 20, 2008 12:19 pm
Display posts from previous:  Sort by
 Page 1 of 1 [ 7 posts ]

Who is online

Users browsing this forum: No registered users and 2 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning