Go to Post At FIRST, our only colors are red or blue. And we are only those for two minutes! - tenfour [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 20-01-2007, 17:24
Sykan's Avatar
Sykan Sykan is offline
Lead Programmer
AKA: David
FRC #0540 (Team 540)
Team Role: Engineer
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Virginia
Posts: 24
Sykan is on a distinguished road
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)));
  #2   Spotlight this post!  
Unread 20-01-2007, 17:31
JamesBrown JamesBrown is offline
Back after 4 years off
FRC #5279
Team Role: Engineer
 
Join Date: Nov 2004
Rookie Year: 2005
Location: Lynchburg VA
Posts: 1,281
JamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond repute
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.)
__________________
I'm Back


5279 (2015-Present)
3594 (2011)
3280 (2010)
1665 (2009)
1350 (2008-2009)
1493 (2007-2008)
1568 (2005-2007)
  #3   Spotlight this post!  
Unread 20-01-2007, 17:52
radicalnerd radicalnerd is offline
Registered Luser
FRC #0668 (Apes of Wrath)
Team Role: Programmer
 
Join Date: Dec 2005
Location: San Jose, CA
Posts: 12
radicalnerd is an unknown quantity at this point
Send a message via AIM to radicalnerd
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)));
  #4   Spotlight this post!  
Unread 20-01-2007, 19:16
Sykan's Avatar
Sykan Sykan is offline
Lead Programmer
AKA: David
FRC #0540 (Team 540)
Team Role: Engineer
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Virginia
Posts: 24
Sykan is on a distinguished road
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
  #5   Spotlight this post!  
Unread 20-01-2007, 20:52
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
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.
  #6   Spotlight this post!  
Unread 20-01-2007, 20:55
Unsung FIRST Hero
Mike Betts Mike Betts is offline
Electrical Engineer
no team
Team Role: Engineer
 
Join Date: Dec 2001
Rookie Year: 1995
Location: Homosassa, FL
Posts: 1,442
Mike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond repute
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.
__________________
Mike Betts

Alumnus, Team 3518, Panthrobots, 2011
Alumnus, Team 177, Bobcat Robotics, 1995 - 2010
LRI, Connecticut Regional, 2007-2010
LRI, WPI Regional, 2009 - 2010
RI, South Florida Regional, 2012 - 2013

As easy as 355/113...
  #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.
  #8   Spotlight this post!  
Unread 21-01-2007, 03:04
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

This is what I was trying to say:

http://kevin.org/frc/2007_frc_range_calc.pdf
__________________
What place are we at? ... TODAI!
  #9   Spotlight this post!  
Unread 21-01-2007, 09:26
dcbrown dcbrown is offline
Registered User
AKA: Bud
no team
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Hollis,NH
Posts: 236
dcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud of
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
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
C18 v2.4 -- Syntax error where there is no syntax error Joel J Programming 7 12-01-2007 17:27
Array Syntax Error Andrew Blair Programming 7 05-02-2006 14:11
Syntax Error! Denz Programming 15 04-02-2006 23:57
Simple Syntax Error miketwalker Programming 6 06-01-2004 00:17


All times are GMT -5. The time now is 23:53.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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