Quote:
Originally Posted by Sykan
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);