View Single Post
  #7   Spotlight this post!  
Unread 20-01-2007, 22:28
JohnC's Avatar
JohnC JohnC is offline
my other name is nigel
FRC #0360 (360 Revolution)
Team Role: Programmer
 
Join Date: Mar 2005
Rookie Year: 2005
Location: user_routines.c
Posts: 100
JohnC is a jewel in the roughJohnC is a jewel in the roughJohnC is a jewel in the roughJohnC is a jewel in the rough
Send a message via AIM to JohnC
Re: Math.h sin syntax error

Quote:
Originally Posted by Sykan View Post
Im trying to use the math.h sin function but i keep getting a syntax error. Im trying to use trig to figure out how far away our bot is from the target light. Heres what's not working:


int targheight;
float dist;
targheight = 3;
dist = ((int)targheight * float sin(((3.14159 / 2) - ((((((int)TILT_SERVO - 190) * (65 / 124)) * (3.14159 / 180)))))) / float sin(float((((((int)TILT_SERVO - 190) * (65 / 124)) * (3.14159 / 180)));
If you're trying to get the horizontal distance between you and the rack, and you have the angle measure from the camera, and you have the height of the light, wouldn't you use tan to find the distance?

I would suggest dividing those numbers and rounding at whatever number of digits you feel comfortable at. That will eliminate 5 pairs of parentheses. Also, you could do some of that math in earlier steps and use a final, easy to read line for the distance.

Assuming you want the horizontal distance to the rack from your robot, maybe...this (I'm assuming TILT_SERVO is an angle measure):
Code:
int targheight;
float dist;
targheight = 3;

dist = targheight / tan(TILT_SERVO);
__________________
What place are we at? ... TODAI!

Last edited by JohnC : 20-01-2007 at 22:32.