Thread: math.h library
View Single Post
  #15   Spotlight this post!  
Unread 03-01-2004, 01:12
Joe Johnson's Avatar Unsung FIRST Hero
Joe Johnson Joe Johnson is offline
Engineer at Medrobotics
AKA: Dr. Joe
FRC #0088 (TJ2)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1996
Location: Raynham, MA
Posts: 2,633
Joe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond repute
Re: math.h library

I did a quick Excel spreadsheet to see whether a linear or parabolic interpolation was better (I expected the parabolic to be better).

I used 128 values 16 bit values in my table for a 90 degree section of the sine function (I realize this is a prettty thick mesh, but it is only .25Kbytes for my entire sine and cosine approximation which seems small enough). Anyway, I was only off at most 2 counts of a 16 bit output with a linear interpolation. Surprisingly (to me at least) the parabolic interpolation was worse! It was sometime off by 3 counts and also had a higher average error. I suppose that this could be due to the fact that sine is a x + x^3+ x^5 ... function (note no even powers) while I was adding a x^2 term to my approximation.

Bottom line: a max 2 counts out of a 16 bit number is going to be fine for me and my robot. I plan out writing a simple lookup table with linear interpolation (at least for sine and cosine -- we will see about tangent, arcsine, arccosine and the all important arctangent).

Joe J.