To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.nqcOpen lugnet.robotics.rcx.nqc in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / NQC / 1275
1274  |  1276
Subject: 
Re: Trigonometry and NQC
Newsgroups: 
lugnet.robotics.rcx.nqc
Date: 
Fri, 14 Dec 2001 14:35:00 GMT
Viewed: 
3392 times
  
Thank you for these posts!  This idea of creating a table of arctangents is
just what I need.  I'll let everyone know how it works after I redesign the
racer.  (The prototype, designed for speed, experienced a significant
mechanical shock when it smashed into the first wall.  The sensor response
time was not sufficient to allow the robot to stop.  : )

Rich

In lugnet.robotics.rcx.nqc, Rainer Balzerowski writes:
In lugnet.robotics.rcx.nqc, Richard Jenkins writes:
Hi!

I'm working on a project where a robot needs to travel a right triangle with
unkown side lengths.  Basically, the robot starts at a point in a room,
travels perpendicularly toward a wall, turns 90 degrees left when it hits,
and when it gets to the corner needs to return to the starting point in the
room (somewhere).  No marks or other guides are provided to help the robot
find the starting point, but it can obviously measure the distance (or the
time) of the two perpendicular legs.  I could complete the course making a
square instead of a triangle, but that's not very elegant.

I prefer NQC as my Mindstorms programming tool, but it isn't apparent to me
that it supports trig functions.

Can anyone offer any suggestions?

Thanks,

Rich

Hi Rich,

there are no trig functions, because there's no float.
I had the same problem and was able to approximate these values.

I created two tables with the necessary values.
The first table includes the values of the tangens of a angle. This values
are times 100, because there's no float available.
What you need in fact is the arcustangens. But it's not avbailable. So i
check the values i want to calculate the arcustanges for with my table and
can see the resulting angle +/- 5 degree. (It's not easy to explain in
english, i'm from germany)

So, if the result of the following equation
degree_to_goal = (abs(delta_y)*100)/abs(delta_x);
is 74 (0.74*100) , then the resulting angle is between 35° and 40°

The second table is a table of squares. It's the same priciple as before.
You need a square-root for Pythagoras. But there is no square-root in NQC.
So look in the table to get an approximation of the square-root.

Pay attention, that the values for sqr(x-direction) + sqr(y-direction) do
not exceed 32.767 (because all values in NQC are signed integer (-32768 ->
32767) and you will get wrong results)

It works well. Try it and let me know what you think.

Rainer

**************************************************************************

#define degree5       9  // -> tan(5°)  =  0.0875 // *100 because no float
#define degree10     18  // -> tan(10°) =  0.1763 // *100 because no float
#define degree15     27  // -> tan(15°) =  0.2679 // *100 because no float
#define degree20     36  // -> tan(20°) =  0.364  // *100 because no float
#define degree25     47  // -> tan(25°) =  0.4663 // *100 because no float
#define degree30     58  // -> tan(30°) =  0.5774 // *100 because no float
#define degree35     70  // -> tan(35°) =  0.7002 // *100 because no float
#define degree40     84  // -> tan(40°) =  0.8391 // *100 because no float
#define degree45    100  // -> tan(45°) =  1      // *100 because no float
#define degree50    119  // -> tan(50°) =  1.1918 // *100 because no float
#define degree55    143  // -> tan(55°) =  1.4281 // *100 because no float
#define degree60    173  // -> tan(60°) =  1.7321 // *100 because no float
#define degree65    214  // -> tan(65°) =  2.1445 // *100 because no float
#define degree70    275  // -> tan(70°) =  2.7475 // *100 because no float
#define degree75    373  // -> tan(75°) =  3.7321 // *100 because no float
#define degree80    567  // -> tan(80°) =  5.6713 // *100 because no float
#define degree85   1143  // -> tan(85°) = 11.4301 // *100 because no float

#define Square10      100      // square-root 100   = 10
#define Square20      400      // square-root 400   = 20
#define Square30      900      // square-root 900   = 30
#define Square40     1600      // square-root 1600  = 40
#define Square50     2500      // square-root 2500  = 50
#define Square60     3600      // square-root 3600  = 60
#define Square70     4900      // square-root 4900  = 70
#define Square80     6400      // square-root 6400  = 80
#define Square90     8100      // square-root 8100  = 90
#define Square100   10000      // square-root 10000 = 100
#define Square110   12100      // square-root 12100 = 110
#define Square120   14400      // square-root 14400 = 120
#define Square130   16900      // square-root 16900 = 130
#define Square140   19600      // square-root 19600 = 140
#define Square150   22500      // square-root 22500 = 150
#define Square160   25600      // square-root 25600 = 160
#define Square170   28900      // square-root 28900 = 170
#define Square180   32400      // square-root 32400 = 180


// Approximate angle to destination !

degree_to_goal = (abs(delta_y)*100)/abs(delta_x); // times 100,
                                                 //because no float
if (degree_to_goal < degree5){
degree_to_goal = 5;
}
else if (degree_to_goal < degree10){
degree_to_goal = 10;
}else if (degree_to_goal < degree15){
degree_to_goal = 15;
}else if (degree_to_goal < degree20){
degree_to_goal = 20;
}else if (degree_to_goal < degree25){
degree_to_goal = 25;
}else if (degree_to_goal < degree30){
degree_to_goal = 30;
}else if (degree_to_goal < degree35){
degree_to_goal = 35;
}else if (degree_to_goal < degree40){
degree_to_goal = 40;
}else if (degree_to_goal < degree45){
degree_to_goal = 45;
}else if (degree_to_goal < degree50){
degree_to_goal = 50;
}else if (degree_to_goal < degree55){
degree_to_goal = 55;
}else if (degree_to_goal < degree60){
degree_to_goal = 60;
}else if (degree_to_goal < degree65){
degree_to_goal = 65;
}else if (degree_to_goal < degree70){
degree_to_goal = 70;
}else if (degree_to_goal < degree75){
degree_to_goal = 75;
}else if (degree_to_goal < degree80){
degree_to_goal = 80;
}else if (degree_to_goal < degree85){
degree_to_goal = 85;
}else{
degree_to_goal = 90;
}

// Approximate distance to destination !

distance = (delta_x*delta_x)+(delta_y*delta_y); // nearly Pythagoras,
                                               // except of the square-root
if (distance >= Square180){
distance = 180;
} else if (distance >= Square170){
distance = 170;
} else if (distance >= Square160){
distance = 160;
} else if (distance >= Square150){
distance = 150;
} else if (distance >= Square140){
distance = 140;
} else if (distance >= Square130){
distance = 130;
} else if (distance >= Square120){
distance = 120;
} else if (distance >= Square110){
distance = 110;
} else if (distance >= Square100){
distance = 100;
} else if (distance >= Square90){
distance = 90;
} else if (distance >= Square80){
distance = 80;
} else if (distance >= Square70){
distance = 70;
} else if (distance >= Square60){
distance = 60;
} else if (distance >= Square50){
distance = 50;
} else if (distance >= Square40){
distance = 40;
} else if (distance >= Square30){
distance = 30;
} else if (distance >= Square20){
distance = 20;
} else if (distance >= Square10){
distance = 10;
} else {
distance = 0;
}
*******************************************************************



Message is in Reply To:
  Re: Trigonometry and NQC
 
(...) Hi Rich, there are no trig functions, because there's no float. I had the same problem and was able to approximate these values. I created two tables with the necessary values. The first table includes the values of the tangens of a angle. (...) (23 years ago, 13-Dec-01, to lugnet.robotics.rcx.nqc)

5 Messages in This Thread:



Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR