Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Math.h sin syntax error (http://www.chiefdelphi.com/forums/showthread.php?t=52383)

Sykan 20-01-2007 17:24

Math.h sin syntax error
 
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)));

JamesBrown 20-01-2007 17:31

Re: Math.h sin syntax error
 
What line is geting the syntax error, and what is the error(if your compiler gives you some knid of error report.)

radicalnerd 20-01-2007 17:52

Re: Math.h sin syntax error
 
You seem to be missing some closing parentheses for those bolded open parentheses. Try using a text editor that has parentheses highlighting like notepad2. Also it might be easier to read if you split it up over multiple lines (it's not really more efficient code if you write it all on one line.)

Code:

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)));

Sykan 20-01-2007 19:16

Re: Math.h sin syntax error
 
The line with the error is:
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)));

The error is:

C:\frc_camera_2\frc_camera\user_routines.c:360:Err or: syntax error
Halting build on first failure as requested.
BUILD FAILED: Sat Jan 20 19:11:20 2007

Alan Anderson 20-01-2007 20:52

Re: Math.h sin syntax error
 
The parentheses don't match, that's for sure. I'm no expert in C syntax, but the "float sin" part looks wrong too.

I'd create a lookup table in advance and use it instead of doing all that complicated and time-consuming calculation on the fly.

Mike Betts 20-01-2007 20:55

Re: Math.h sin syntax error
 
Radicalnerd told you at least part of your problem. You have a different number of open parenthesis than you have close parenthesis. You also seem to be attempting a type cast of float without the required parenthesis.

JohnC 20-01-2007 22:28

Re: Math.h sin syntax error
 
Quote:

Originally Posted by Sykan (Post 561312)
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);


JohnC 21-01-2007 03:04

Re: Math.h sin syntax error
 
This is what I was trying to say:

http://kevin.org/frc/2007_frc_range_calc.pdf

dcbrown 21-01-2007 09:26

Re: Math.h sin syntax error
 
Code:

dist = ((int)targheight * float sin(((3.14159 / 2) ...
should be

Code:

dist = ((int)targheight * (float) sin(((3.14159 / 2) ...
                            ^^^^

to recap:
1. make sure parenthesis are properly matched up
2. type casts such as int and float need to be in their own parenthesis
like you did with (int) already


All times are GMT -5. The time now is 04:13.

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