Go to Post The real key to drive team coaching is to tie your jacket around your waist. Got a couple championship rings that way. - TravusCubington [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 03-02-2006, 15:24
Denz's Avatar
Denz Denz is offline
Registered User
FRC #0772 (Sabre Bytes Robotics)
Team Role: Programmer
 
Join Date: Jan 2006
Location: LaSalle, Ont, Canada
Posts: 66
Denz is on a distinguished road
Send a message via MSN to Denz
Syntax Error!

I'm getting a syntax error on this line:

int Distance_Function(float tilt_angle_rad)
{
if (tracking_initialized == 1)
{
distance_from_wall = (int)(3.162 / tan(tilt_angle_rad));
return(distance_from_wall);
}
}

I'm not really sure I declaired everything right, but can someone help me out? I added math.h and included it in the tracking.c(where this code is from).


float tilt_angle_rad;

tilt_angle_rad = (0.01745) * (((TILT_SERVO - 144) * 25)/50);
Distance_Function(tilt_angle_rad);

I also have that somewhere else in the code. And I declaired my function aswell. Help? Thanks in advance!
__________________
www.sabrerobotics.com
  #2   Spotlight this post!  
Unread 03-02-2006, 15:30
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: Syntax Error!

Where and how is distance_from_wall declared?
__________________
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...
  #3   Spotlight this post!  
Unread 03-02-2006, 15:34
Denz's Avatar
Denz Denz is offline
Registered User
FRC #0772 (Sabre Bytes Robotics)
Team Role: Programmer
 
Join Date: Jan 2006
Location: LaSalle, Ont, Canada
Posts: 66
Denz is on a distinguished road
Send a message via MSN to Denz
Re: Syntax Error!

Declaired in tracking.h


// The distance from the robot to the wall. Initial value is not actually zero; calculated when camera is turned on.
#define distance_from_wall 0


and also prototyped the Distance_Function in tracking.h

// function prototypes
void Servo_Track(void);
void Initialize_Tracking(void);
unsigned char Get_Tracking_Configuration(unsigned int, unsigned char);
int Distance_Function(float);
__________________
www.sabrerobotics.com
  #4   Spotlight this post!  
Unread 03-02-2006, 15:36
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,078
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: Syntax Error!

#define is for CONSTANTS - you want to use a variable such as int or float.

Constants get their value once - you cannot assign them a new one.

Since you seem to be using this data in multiple C files, here is what you need to do:

in tracking.h:

extern int distance_from_wall;

in tracking.c, in the global space (top of file, not inside a function):

int distance_from_wall = 0;

Now your code will work the way you expect.

Last edited by Jared Russell : 03-02-2006 at 15:38.
  #5   Spotlight this post!  
Unread 03-02-2006, 15:45
Denz's Avatar
Denz Denz is offline
Registered User
FRC #0772 (Sabre Bytes Robotics)
Team Role: Programmer
 
Join Date: Jan 2006
Location: LaSalle, Ont, Canada
Posts: 66
Denz is on a distinguished road
Send a message via MSN to Denz
Re: Syntax Error!

Abwehr, you rock, it compiled, we're testing now!

Goten, I don't know what you are saying...
__________________
www.sabrerobotics.com

Last edited by Josh Hambright : 03-02-2006 at 16:08.
  #6   Spotlight this post!  
Unread 03-02-2006, 16:41
Denz's Avatar
Denz Denz is offline
Registered User
FRC #0772 (Sabre Bytes Robotics)
Team Role: Programmer
 
Join Date: Jan 2006
Location: LaSalle, Ont, Canada
Posts: 66
Denz is on a distinguished road
Send a message via MSN to Denz
Re: Syntax Error!

Anyone know why it's giving me a really wrong number for distance? I made sure the angle is given in radiens. And the height is correct aswell (it is in meters). Thanks guys!
__________________
www.sabrerobotics.com
  #7   Spotlight this post!  
Unread 03-02-2006, 16:59
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: Syntax Error!

Quote:
Originally Posted by Denz
Anyone know why it's giving me a really wrong number for distance? I made sure the angle is given in radiens. And the height is correct aswell (it is in meters). Thanks guys!
Look at your trig... Why would pi/tan(theta) give you distance?

Assume the angle is pi/4 (45 degrees)... tan(theta) = 1 and your "answer" is pi rather than the expected value of 8.5 feet...
__________________
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...
  #8   Spotlight this post!  
Unread 03-02-2006, 21:49
Denz's Avatar
Denz Denz is offline
Registered User
FRC #0772 (Sabre Bytes Robotics)
Team Role: Programmer
 
Join Date: Jan 2006
Location: LaSalle, Ont, Canada
Posts: 66
Denz is on a distinguished road
Send a message via MSN to Denz
Re: Syntax Error!

lol, no that is the difference between the camera height and green light height in meters, not pi.

Distance = (Green Light Height - Camera Height) / tan theta


just one question, do I have to do my angle in radians? because I believe I converted it corectly .01745 radians = 1 degree.
__________________
www.sabrerobotics.com
  #9   Spotlight this post!  
Unread 04-02-2006, 02:00
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,078
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: Syntax Error!

The math.h trig functions only take radians.

If you want, you can do a macro to do degrees, i.e.:

#define PI 3.14159265f
#define dtan(x) tan(x*PI/180.0f)

Then, put this in your code where appropriate:

dtan(tilt_angle_rad);

The only thing that I can think of that would make your equation give bogus results is if the servo angle conversion function is off. Make sure that whatever Kevin's code defines as the servo's zero corresponds with 0 degrees of tilt - you may have to either rotate the servo horn or redefine the zero point (in tracking.h) to find a good zero.
  #10   Spotlight this post!  
Unread 04-02-2006, 02:22
Denz's Avatar
Denz Denz is offline
Registered User
FRC #0772 (Sabre Bytes Robotics)
Team Role: Programmer
 
Join Date: Jan 2006
Location: LaSalle, Ont, Canada
Posts: 66
Denz is on a distinguished road
Send a message via MSN to Denz
Re: Syntax Error!

The conversion factor is roughly 0.01745 I'll use that instead of defining it, it works, it's easier, unless there's some reason that I shouldn't. I'm pretty new to programming, and I'm always glad to learn.

tilt_angle_rad = (0.01745) * (((TILT_SERVO - 144) * 25)/50);

but anyways, we already checked and the angle is correct. Yet I'm getting like -166.25 meters for the light that is like 2.5 meters away.... My friend said it maybe that it may be overflow, so I changed everything from floating points to integers, I'll test, see how it goes. Thanks alot of the help!

What does the f after the 180.0 and the pi mean?
__________________
www.sabrerobotics.com

Last edited by Denz : 04-02-2006 at 02:26.
  #11   Spotlight this post!  
Unread 04-02-2006, 14:42
CronosPrime1 CronosPrime1 is offline
Registered User
FRC #0321
 
Join Date: Jan 2006
Location: Hyperspace
Posts: 53
CronosPrime1 is an unknown quantity at this point
Re: Syntax Error!

That indicates that the numbers are floats.

I suppose the reason why it's needed is that the computer always needs to know what data type everything is. So in a normal variable declaration, you say something like

float distance;

This tells the computer or FRC controller that you are declaring a variable of type float, and the processor allocates a specific number of bytes to that variable. It's usually 4 bytes to a float. Since the memory allocation must be done before doing anything with the variable, variables must be declared before they are used, and they need to be declared as being a specific type because different types are allocated different amounts of memory.

In a macro, there is no keyword float. Thus, you need some sort of indicator showing of what type the constant or whatever is. Whoever made C decided that in a macro "f" would suffice for this purpose.

#define PI 3.14159265f
__________________

Last edited by CronosPrime1 : 04-02-2006 at 14:52.
  #12   Spotlight this post!  
Unread 04-02-2006, 18:34
Denz's Avatar
Denz Denz is offline
Registered User
FRC #0772 (Sabre Bytes Robotics)
Team Role: Programmer
 
Join Date: Jan 2006
Location: LaSalle, Ont, Canada
Posts: 66
Denz is on a distinguished road
Send a message via MSN to Denz
Re: Syntax Error!

So, I guess that might be my problem. I never declared those numbers as floats. It's probably rounding them to integers or something. I will try it out! Thanks!
__________________
www.sabrerobotics.com
  #13   Spotlight this post!  
Unread 04-02-2006, 19:31
CronosPrime1 CronosPrime1 is offline
Registered User
FRC #0321
 
Join Date: Jan 2006
Location: Hyperspace
Posts: 53
CronosPrime1 is an unknown quantity at this point
Re: Syntax Error!

Yes, it is always very important to make sure you declare things with the right type. However, when you write something like 3.142, the computer knows you want a float. In fact, the computer even treats 15.0 as a float. Why else would you have put the decimal point if not to mean that you want a float?
__________________
  #14   Spotlight this post!  
Unread 04-02-2006, 19:45
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,078
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: Syntax Error!

I would start by checking your angle measurement. See if that number makes sense, then worry about your distance formula (which looks right to me).
  #15   Spotlight this post!  
Unread 04-02-2006, 19:47
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,078
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: Syntax Error!

Quote:
Originally Posted by CronosPrime1
Yes, it is always very important to make sure you declare things with the right type. However, when you write something like 3.142, the computer knows you want a float. In fact, the computer even treats 15.0 as a float. Why else would you have put the decimal point if not to mean that you want a float?
Most C languages treat constants with decimal points as double by default - hence the "X.XXf", to specify only a 32 bit FP is needed. I think PIC C uses float by default, but it's habit from my desktop C background. Doesn't hurt.
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
Syntax Error: externs, structs, and macros Astronouth7303 Programming 3 16-02-2005 15:39
syntax error using enum{} gnormhurst Programming 8 07-02-2005 14:25
MPLink Error cloudago Programming 2 01-02-2005 23:00
Routine declaration syntax error (Or: Where's wlado?) Astronouth7303 Programming 15 24-03-2004 05:51


All times are GMT -5. The time now is 01:37.

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