![]() |
Trig Lookup Table
I've seen the trig lookup table function posted by Kevin Watson (this one: http://kevin.org/frc/frc_trig.zip ). I'm just wondering if anybody has an idea on how to implement an inverse cosine function?
My real problem is controlling 2 angles which have to be calculated. I have all the calculations, but they are quite involved (lots of inverse cos, sqrt, and squaring). I've ruled out a lookup table for the various combinations of these two angles. There are two independent variables that are controlled by the robot driver, and two calculated angles (Im pretty sure the lookup table for that would be way too huge). Thus I return to my original question: how to implement an inverse cosine lookup table function? Perhaps using kevin watson's code posted above? Thanks, Michael Michniewski p.s see my new post below |
Re: Trig Lookup Table
What are the two angles your looking trying to find for? I know that i had to find a few angles for our Mast on our bot. One for it at 45, one at 90, and then i had to find the two angles for where the Pnuematic ram would be placed and what distance on our mast and frame. This only took me about 15 Min in autocad... Autocad is the best mathmatical cheater. But i dont know what your looking for
|
Re: Trig Lookup Table
You can use a similar method to what Kevin uses, but replace the data with the appropriate trig function. If you know your trig identities you might be able to use his functions to get the data you need.
However, depeding on how many calculations you are doing, you should be fine with a call to arccos() from <math.h>. Consider posting the code. BTW, I don't think squaring is nearly as processor intensive as the other functions. See also: http://en.wikipedia.org/wiki/CORDIC http://en.wikipedia.org/wiki/Generat...ometric_tables |
Re: Trig Lookup Table
Quote:
Code:
/* |
Re: Trig Lookup Table
Thanks for the replies.
I'm not just looking for a given number of angles (ie set positions), but rather within a range (almost 360 degrees for at least one of two angles). I'll try the suggestion of replacing the cos function in Kevin's code with the cosine inverse. Here's the current code. I put things that are used or calculated more than once in a variable, which is called later. Basically I'm just looking for the quickest way to execute this code, my main idea being using a trig lookup table. Code:
//Thanks, Michael Edit: the arccos in the code should be (and now is) acos, right? |
Re: Trig Lookup Table
Quote:
Code:
#include <math.h>Code:
Quote:
Quote:
Also, if arm.length_upper, arm.length_lower, arm.offset_front, arm.distance are all constant consider doing the math on them ahead of time. And if all of these are floating point variables (which they need to be if you put them into functions like sqrt() and acos() then you are probably not going to get done quick enough. Consider making a lookup table for the whole operation (if possible) or just casting to floats for the <math.h> calls. Good luck, Robinson |
Re: Trig Lookup Table
1 Attachment(s)
I've been meaning to post this for about a week or so, but for some reason never seemed to have any time. This is the type of method we have used for the past couple of years for calculating sine & cosine (and arcsine & arccosine). It uses both a lookup table and linear interpolation to determine the approximate value. It utilizes signed shorts rather than floating point to keep the execution speed decent. I’ve only extracted the sine/cosine routines but the documentation shows some other examples of how you could use some of underlying routines to generate your own non-linear functions.
Mike |
| All times are GMT -5. The time now is 04:53. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi