Electronics > Microcontrollers

Trig Approximations

(1/3) > >>

Tony R:
Hello, for my current project i am working on a car that will be guided by a compass and GPS. for this i need to guide the car based on the heading and position. the formulas that can do this for me are very heavy on the trig functions.

My question is are the trig functions that are included in the standard math.h file efficient? or should i write my own approximations for trig functions? or should I use a table?

I would like up to 1 +/ .5 degree of accuracy so about 0.0175 rad of resolution or so. What is the best way of doing this? will the standard math.h work, or should i create my own functions?

The math.h functions are going to be designed for correctness before speed.  I think they should be accurate to a couple of LSBs.

A table with linear interpolation will be super-fast and relatively compact.  If you have the ROM space available that is probably the best option.  If you need or want better accuracy the table size will start getting too big, in that case you want a more sophisticated approximation -- a quadratic approximation will probably be enough for all intents and purposes.

Are you doing fixed or floating point math?


--- Quote from: Tony R on November 21, 2011, 02:54:47 pm ---...guided by a compass and GPS
--- End quote ---
i dont see the need for heavy trig there.

I guess I should also suggest: use the default math.h methods unless you see a problem with performance.  If performance is a problem, add drop-in replacements that can be changed with a #define to call the originals in case you ever suspect that a bug in the approximations is causing trouble.

Tony R:

--- Quote from: Mechatrommer on November 21, 2011, 03:23:20 pm ---i dont see the need for heavy trig there.

--- End quote ---


Just the first 2 topics distance and heading, I have defiantly done more trig, but I am worried about the speed.


[0] Message Index

[#] Next page

There was an error while thanking
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod