Inverse Tangent

I need to know how to do this on the RC. We need to find the angle of the joystick from the X and Y variables only. Normally arctangent is what would be used. But the RC doesn’t provide this function. Options?

You could do a Talyor approximation or something. There’s been discussion on this already.

Return of the Inverse Trig Functions explains arcsine and arccos.

We (team 159) have just finished coding our tranlational drive routine. This does just what you want, figuring an angle from joystick values. Although it uses two joysticks, it can easily be adapted to one. The source will be posted later tonight, in the white papers section

Damian,

Just a suggestion. If you place your subroutine outside of your main loop then you can get rid of the GOTOs.

Tim Tedrow

My team is using the inverse tangent function for a different reason… We’ve settled on an approximation formula (at most 1/2 of a % error). We may or may not decide to run this in the custom circuit. If you PM me, I’ll get the approximation. It’s a 3-part piecemeal function. Only uses the four basic operations :wink:

sin x = 16x (p - x)/[5p2- 4x (p - x)]

x = 0 formula = 0.00000 sin x = 0.00000 error = 0.00000

x = p/20 formula = 0.15800 sin x = 0.15643 error = 0.00157

x = p/10 formula = 0.31034 sin x = 0.30903 error = 0.00131

x = 3p/20 formula = 0.45434 sin x = 0.45399 error = 0.00035

x = p/5 formula = 0.58716 sin x = 0.58778 error = -0.00062

x = p/4 formula = 0.70588 sin x = 0.70710 error = -0.00122

x = p/10 formula = 0.80769 sin x = 0.80903 error = -0.00134

x = 7p/20 formula = 0.88998 sin x = 0.89103 error = -0.00105

x = 2p/5 formula = 0.95050 sin x = 0.95105 error = -0.00055

x = 9p/20 formula = 0.98753 sin x = 0.98769 error = -0.00016

x = p/2 formula = 1.00000 sin x = 1.00000 error = 0.00000

If found that on the internet and it is pretty accurate… there are some stuff with approximation series but i couldnt get it to work right, but this seems to work very well. The formula which is amazingly accurate and use of the formula leads to a maximum error of less than one percent

And PS this formula was first discovered by this indian guy named Bhaskara I in 629 AD.

Now all u got to do is find a formula for Cos and ur set lol

Cipher X

btw the last post has nothign to do with arctan well it might but not a useful on but i thought someone might use it for somehting so…

I did some searching and found this http://www.mcs.surrey.ac.uk/Personal/R.Knott/Fibonacci/fibpi.html#arctan

arctan( t ) = t – (t^3)/3 + (t^5)/5 - (t^7)/7 + (t^9)/9 - (t^11)/11 …

-1< t < 1

I tried it out its pretty close to what the real value is

x = tan (.5)
arctan(x) should equal .5

x – (x^3)/3 + (x^5)/5 - (x^7)/7 + (x^9)/9 - (x^11)/11 = 0.4999763883

But Surprisingle enough

x – (x^3)/3 + (x^5)/5 - (x^7)/7 + (x^9)/9 = 5.000939788

The More terms you do the more accurate your answer is

!The only problem you might run into in pbasic is memory and speed!

Cipher X

Haha. Inverse Trig - all too familiar to me. We thought about using it for our robot project (check link below), but after searching through the ChiefDelphi forums, we opted against it. Its way too complicated and difficult for BASIC, and it just wasn’t worth the effort for our project. Remember that if your program takes too long to run, your robot cuts out, so that may be a slight concern. See if there’s some simpler solution. Inverse Trig, BASIC, & Binary Radians don’t mix very well.

I would do a lookup table (in EEPROM) with whatever function you need.

Reading from the EEPROM is much faster then doing a bunch of complicated (or even not so complicated equations)

There SHOULD, theoretically, be a very easy way to do inverse tan in PBASIC… I’ll post more if my code actually works. :wink: