View Full Version : Inverse Trig

K. Skontrianos

02-28-2002, 04:46 PM

Now that the main robot is done, some of my friends and I have begun to work on a side project involving GPS tracking. We would like to use a PBASIC controller, since we have experience programming it, but we are unsure as to how to program inverse trig functions. Through some internet research we have found some equations that can be used to calculate inverse tangent, but we fear that PBASIC may round the angle measures. Since our robot will drive itself, we feel that we need to be accurate to at least 2-3 decimal places. If anyone has experience with programming inverse trig functions, most importanly inverse tangent, please contact me.

Thanks,

Kostas Skontrianos

scottoulli5@netzero.net

Go Gearheads!!! 102!!!!

Skabana159

03-01-2002, 05:32 PM

I predict that you may have some trouble accomplishing this.

First, the two trig functions available for use in the BASIC stamp, SIN and COS, are tricky in and of themselves. Due to the fact that the BASIC stamp functions on relatively rudimentary binary, it uses completely different units than what you may be used to. Let us draw comparisons between the Stamp's trig and normal trig. While, in most situations, we divide a circle into 2*pi radians, or 360 degrees, neither of these units are of much use in binary. So, the stamp uses a unit call the binary radian (brad). This unit is defined in two ways: there are 255 brads in a circle, and one brad is about 1.406 degrees. In addition, we are used to sin giving us the y component of a point on the unit circle (where the radius of a circle is 1). In PBASIC, however, you will find that sin gives the y component of a point on the 127-unit circle.

Second, you may have trouble interpreting the values returned by trig functions. All unary operators (those that have 1 argument, like square root, sine, absolute value) on the BASIC stamp are performed in the space of a word. This means 16 bits, 2 bytes, or in base-10, 0 to 65535. But this is not nesecarily the value you will find. You have to make sure that the variable you are storing it in is a word.

Third, that word is an unsigned integer. It is in a format that I do not completely understand called the two's complement. Someone else will have to tell you what this means because I really have no idea. It will be a positive integer, but there is some way to tell if it is a negative value.

Hope I have been of some help. You can read about all of this in the PBASIC Programming Manual available from Parallax, Inc. (http://www.parallaxinc.com) In short, it is possible, but it will be a terribly difficult task.

-Jesse, Team 159

Brandon Martus

03-01-2002, 05:38 PM

check out this thread (http://www.chiefdelphi.com/forums/showthread.php?s=&threadid=2004&highlight=trig)

Ameya

03-02-2002, 04:34 PM

Originally posted by Skabana159

Third, that word is an unsigned integer. It is in a format that I do not completely understand called the two's complement. Someone else will have to tell you what this means because I really have no idea. It will be a positive integer, but there is some way to tell if it is a negative value.

In two's complement, the first bit of a number represents the opposite of what it normally would. So, in a two's complement byte, 10000000 would represent -128 instead of +128. All of the other bits count as positive values.

Another example:

10000001 in two's complement is 1 + -128 = -127, while as an unsigned integer it would be 1 + 128 = 129.

Matt Reiland

03-04-2002, 07:09 PM

Here is a succesful implementation of the inverse function that was posted earlier by LeoM for this years robot

The function is in the Sidestep program it is taking the joystick and finding the angle for our 4 wheel steering

Thanks again LEO!!!

Leo M

03-13-2002, 02:33 PM

Matt -

You actually USED it! Great!

How is it working?

I am so glad someone picked up on this - it was just "intellectual exercise" to get me in shape for competition during the fall - but to see someone actually put it in their code! WOW! I'm impressed.

You just never know who will be able to make something useful from your "idle doodling".

Leave it to the FIRST addicts.......

K. Skontrianos

03-13-2002, 10:27 PM

Using inverse trig is one of the possible ways we plan to guide our GPS bot. If we do decide to use it, it will be a very good implementation of the inverse algorithm. When its all done, I'll make sure to post clips of the bot in action and some of the methods we used to get it to work. Thanks for the inverse suggestions so far.

vBulletin® v3.6.4, Copyright ©2000-2014, Jelsoft Enterprises Ltd.