View Single Post
  #9   Spotlight this post!  
Unread 10-04-2007, 11:02
jerry w's Avatar
jerry w jerry w is offline
Free Agent Mentor
no team (Team Krunch)
Team Role: Engineer
 
Join Date: Nov 2003
Rookie Year: 2002
Location: dunedin fl
Posts: 113
jerry w has much to be proud ofjerry w has much to be proud ofjerry w has much to be proud ofjerry w has much to be proud ofjerry w has much to be proud ofjerry w has much to be proud ofjerry w has much to be proud ofjerry w has much to be proud ofjerry w has much to be proud of
Re: Servo Values to Degrees... How?

Quote:
Originally Posted by #root: View Post
Hey, I've been having a problem setting the correct degrees to a variable, even though it prints to the terminal correctly.

pan_angle = (((int)PAN_SERVO - 124) * 65)/124;
tilt_angle = (((int)TILT_SERVO - 144) * 25)/50;

I have tried making these variables ints, floats, and doubles (they are global static declared in user_routines.h, set in terminal.c, and used in user_routines_fast.c). Would it help if I cast pan_angle and tilt_angle as ints or changed 124 to 124.0? Maybe if I did

(int) pan_angle = (int) (((int)PAN_SERVO - 124) * 0.5242);

Any help would be appreciated. Thanks!
Be careful when declaring variables. They should not be declared in the header file. The header is used in several places, which can cause copies of variables to occur.
In the user.c you should have;
Code:
int   pan_angle = 0 ;
In user.h you should have;
Code:
extern int   pan_angle ;
Then user_fast.c will see the external variable when the header is read.

Jerry w
__________________
Happiest when people tell the truth... However, I am blessed with many friends.