OCCRA
Go to Post Also, after 3 years of FRC I finally hugged that Platypi! - That 281 Guy [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Events   CD-Media   CD-Spy   FRC-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 02-04-2004, 01:55 PM
sear_yoda sear_yoda is offline
Kid With The Credit Card
None #1189 (Breaking Pointe)
Team Role: Alumni
 
Join Date: Jan 2003
Rookie Year: 2002
Location: Grosse Pointe, MI
Posts: 19
sear_yoda will become famous soon enoughsear_yoda will become famous soon enough
Send a message via ICQ to sear_yoda Send a message via AIM to sear_yoda Send a message via Yahoo to sear_yoda
Simple problem with variables

I'm trying not to be a total idiot here by checking all over the forums first, and reading all of the documentation, but I CANNOT figure out how to initilize a simple integer variable 'pressure' that equals the value from the pressure reader on analog input 1.

static unsigned int pressure = Get_Analog_Value(rc_ana_in01);

No matter where I put that, I can't get it to compile. It will compile fine in a few certain places in user_routines.c if it's just pressure = 0, but not this line. EVen if I split it up, it still doesn't work. All I get is syntax errors.

Does anyone else wish this compiler was a tiny bit more descriptive in its error debugging? I've been learning Java this year using the NetBeans IDE, and this MPLAB IDE makes me want to hurl my laptop across the room.

All of my coding depends on being able to initialize variables (well, duh) so this is really a stopping point for me. My entire team is getting sort of pissed off, becuase I just sit there looking angry every meeting trying to get the code to work.

Thanks in advance for any replies I recieve...I must be doing some simple thing wrong.


-Chris
__________________
throw away your microwave and eat cold food.
  #2   Spotlight this post!  
Unread 02-04-2004, 02:00 PM
Ryan M. Ryan M. is offline
Programming User
FRC #1317 (Digital Fusion)
Team Role: Programmer
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Ohio
Posts: 1,508
Ryan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud of
Re: Simple problem with variables

Quote:
Originally Posted by sear_yoda
static unsigned int pressure = Get_Analog_Value(rc_ana_in01);
If this is a global variable, you can't use a function to initialize it at its declaration. To initialize it with a function, put something like this:
Code:
 pressure = Get_Analog_Value(rc_ana_in01);
in user_initialazation(). (in the file user_routines.c)

Hope that helps.
__________________

  #3   Spotlight this post!  
Unread 02-04-2004, 04:07 PM
Random Dude Random Dude is offline
Oregon State Head FTA
AKA: Chris
no team (Oregon Robotics Tournament & Outreach Program)
 
Join Date: Aug 2002
Rookie Year: 1998
Location: Oregon
Posts: 142
Random Dude will become famous soon enoughRandom Dude will become famous soon enough
Re: Simple problem with variables

Quote:
Originally Posted by sear_yoda
I'm trying not to be a total idiot here by checking all over the forums first, and reading all of the documentation, but I CANNOT figure out how to initilize a simple integer variable 'pressure' that equals the value from the pressure reader on analog input 1.

static unsigned int pressure = Get_Analog_Value(rc_ana_in01);

No matter where I put that, I can't get it to compile. It will compile fine in a few certain places in user_routines.c if it's just pressure = 0, but not this line. EVen if I split it up, it still doesn't work. All I get is syntax errors.

Does anyone else wish this compiler was a tiny bit more descriptive in its error debugging? I've been learning Java this year using the NetBeans IDE, and this MPLAB IDE makes me want to hurl my laptop across the room.

All of my coding depends on being able to initialize variables (well, duh) so this is really a stopping point for me. My entire team is getting sort of pissed off, becuase I just sit there looking angry every meeting trying to get the code to work.

Thanks in advance for any replies I recieve...I must be doing some simple thing wrong.


-Chris
What I supect your problem might be is that C, unlike Java or C++ is requires that all variable initializations be done at the very top of the function. You cannot have any code except for other variable initializtion before it. So, I would suggest sticking

static unsigned int pressure;

at the top of the function and then

pressure = Get_Analog_Value(rc_ana_in01);

where ever it is more appropiate.

If this isn't the problem, could you post the message and some code snippets?
  #4   Spotlight this post!  
Unread 02-05-2004, 07:47 AM
sear_yoda sear_yoda is offline
Kid With The Credit Card
None #1189 (Breaking Pointe)
Team Role: Alumni
 
Join Date: Jan 2003
Rookie Year: 2002
Location: Grosse Pointe, MI
Posts: 19
sear_yoda will become famous soon enoughsear_yoda will become famous soon enough
Send a message via ICQ to sear_yoda Send a message via AIM to sear_yoda Send a message via Yahoo to sear_yoda
Re: Simple problem with variables

Well either one, or the combination of both, fixed the problem. I'm not quite sure what I ended up doing, so I'll grab some code samples when I get home and explain how I fixed it.

Thanks for the help, now I can finally get started on my code!
__________________
throw away your microwave and eat cold food.
  #5   Spotlight this post!  
Unread 02-05-2004, 08:12 AM
KenWittlief KenWittlief is offline
.
no team
Team Role: Engineer
 
Join Date: Mar 2003
Location: Rochester, NY
Posts: 4,213
KenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond repute
Re: Simple problem with variables

Initializing a variable is something you normally do with a predetermined value at powerup - like setting it to zero, or 127, or 255

I dont think that going out and reading an input register would technically be considered initializing it - because to get that analog input register value, the code has to be running

maybe you are confused a little between initializing it (at powerup) and reading the input for the first time when your code runs?

If you want to read the initial value of the pressure sensor when the robot is first turned on, you should have a separate variable for that, and some way to make sure you only read the sensor input once after the code first turns on.

for example, initialize the variable to a value that it could not possible get from the sensor at power on, like maybe 254

then somewhere in your code have something like

if initial_pressure = 254 then initial_presssure = pressure_sensor

Last edited by KenWittlief : 02-05-2004 at 08:15 AM.
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
Help On Coding 2K1 Controller GregTheGreat Programming 9 12-05-2003 05:35 PM
Ok one problem cantwell03 Programming 3 02-13-2003 06:28 AM
The problem with scouting... archiver 2001 10 06-23-2002 10:49 PM
Major problem with chipphua motors aka Scott White Motors 18 03-19-2002 06:44 PM
VB Program to monitor robot variables DanL Programming 7 02-15-2002 09:35 PM


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

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


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