Go to Post In engineering, it's important to use the appropriate tools and not more resources than are required. - AdamHeard [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 11-01-2006, 21:25
kaszeta's Avatar
kaszeta kaszeta is offline
Registered User
FRC #0095 (Grasshoppers)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Lebanon, NH
Posts: 334
kaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of light
Trig functions and type conversion

I'm trying to use the CORDIC function to do some basic trig (calculating an angle given an x and y coordinate from a joystick), and I'm getting some odd results.

In short, if I calculate the angle using the atan() function, the results work when y>0, but give incorrect and discontinous results if y<0.

Here's the simplest code that I came up with the recreates the problem:

#include "cordic-math.h" // renamed so that I know it's not the Microchip one

short long joyx,joyy;
short long theta;

joyx=(255-p1_x)-127;
joyy=p1_y-127;

theta=atan(joyy,joyx);

printf("theta: %d ",(int)(theta>>16));

Anyone have some thoughts? I at first thought it was a problem with negative numbers and the >> operator, but theta/65536 gives the same
numbers.
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Auton + Functions ten3brousone Programming 0 27-02-2005 20:11
Overloaded functions jgannon Programming 5 31-12-2004 11:04


All times are GMT -5. The time now is 16:19.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi