Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Servo Values to Degrees... How? (http://www.chiefdelphi.com/forums/showthread.php?t=42327)

jerry w 10-04-2007 11:02

Re: Servo Values to Degrees... How?
 
Quote:

Originally Posted by #root: (Post 611187)
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

#root: 11-04-2007 02:03

Re: Servo Values to Degrees... How?
 
I tried to declare it as an extern, but I was having trouble using and then accessing the variable in both terminal.c and user_routines_fast.c.

Well, hopefully I can figure it out by the time the competition starts!


All times are GMT -5. The time now is 03:36.

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