Quote:
Originally Posted by #root:
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