Link to home
Start Free TrialLog in
Avatar of mjhnational
mjhnational

asked on

Cosine/Sine of 16 bit processors

I am programming a robot on a 16 bit HCS12 processor and I am trying to measure the changle in x/y. The problem that I am having is that I cannot use floating point math. I am given a delta-angle and a delta-distance where:

x=delta-dis*cos(angle)
y=delta-dis*sin(angle)

the angle has a precision of .5 degrees and delta-distance is not in terms of real units.

Does anyone have a algorithm that does not require floating point math? X and Y don't have to be in terms of real units, they just need to be proportional to each other.
Avatar of Kent Olsen
Kent Olsen
Flag of United States of America image

Hi mjhnational,

I'm a bit confused here.  You've got a delta distance and delta angle, and can't use floating point math, but show us equations using sin() and cos().  Hmm....



Sin and Cosine are simply ratios.  Given a right triangle, the sine of an angle is the length of the opposite leg of the triangle over the length of the hypotenuse.  The cosine is the length of the adjacent leg over the length of the hypotenuse.


         + A
        /|
       / |
      /  |
     /   |
    /    |
   /     |
  /      |
 +-------+
 C        B


Sin(C) = length(AB) / length(AC);
Cos(C) = length(BC) / length(AC);



Given that you know the starting location, you should be able to determine the new position with a bit of key information.

You say that you're given a delta-angle and delta-distance.  How are they measured?  (Describe the deltas.  The delta-angle is a change in what angle?  The delta difference describes the change in what length?)



Kent
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mjhnational
mjhnational

ASKER

delta-angle is the global rotation with respect of the initial coordinates. This is measured at a rate of 64 Hz. Assume that it is in half degree increments.

delta-distance is also measured a 64 Hz. It does not have a unit value.

As of right now, I am making a scaled (int) cos/sin lookup table. I was hoping that there might be some standard in the robotics industry for measuring x and y in a similar but more precise way than the way that I am doing it. The lookup table is not precise enough.
>>I am making a scaled (int) cos/sin lookup table

Check out the above link (http://scipy.net/cgi-bin/viewcvsx.cgi/scipy1/special/cephes/sincos.c?rev=1.2), it'll save you that task :o)
A llokup table can be quite accurate.  Just note:

(1)  You only need to store one quadrant, zero to ninety degrees.  All otehrs are just reflections of this.

(2)  If you need better resolution than the table gives you, just do some linear interpolation between the points.  i.e.
if you need the sin of 9.1 degrees, lookup 9 degrees  and 10 degrees, take the difference, add one tenth and you'll be mighty close.

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial