Go to Post dont be afraid of new technology. embrace it and experment with it figure out the problems on the way and then tell us about it so it gets easier. - Tytus Gerrish [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 17-01-2006, 08:20
BradAMiller BradAMiller is offline
Registered User
AKA: Brad
#0190 ( Gompei and the Herd)
Team Role: Mentor
 
Join Date: Mar 2004
Location: Worcester, MA
Posts: 591
BradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant future
Re: Strange Problem, varible not subtracting?

Quote:
Originally Posted by chakorules
Here is the project file ZIP incase you want to open in easyC.
What Matt Adams said is correct.

Here's what's going on. In your "right_velocity" function the variables are all implicitly declared as auto storage class.

long enc_Right_Old_Count = 0;

What this means is that the variables are allocated as the function is entered and deleted when it exits. This is the default in C to save space - temporary variables in one function can use the space of variables in another function. And in your case you initialize them to 0, so that subtraction of 100-enc_Right_Old_Count will always be 100 since enc_Right_Old_Count is initialized to zero each time the function is entered.

Fortunately the fix is easy - you need to make "enc_Right_Old_Count" not get reinitialized each time. You can do this by declaring the variable as a global in the main function. That way it will only be initialized once when the program starts and not every time the function is declared. To do this, go to the main function, and double click on the "Globals" block and add it there.

Be sure to remove it from the right_velocity funtion otherwise the local declaration will override the global for that function and you'll still get the same results.

There might be better ways of doing this without global variables if you were hand coding in C, but this will solve the problem easily in EasyC.

Hope this helps.
__________________
Brad Miller
Robotics Resource Center
Worcester Polytechnic Institute
  #2   Spotlight this post!  
Unread 17-01-2006, 22:17
Chris_Elston's Avatar
Chris_Elston Chris_Elston is offline
Controls Engineer
AKA: chakorules
FRC #1501 (Team THRUST)
Team Role: Engineer
 
Join Date: Feb 2004
Rookie Year: 2001
Location: Huntington, Indiana
Posts: 750
Chris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond repute
Re: Strange Problem, varible not subtracting?

Quote:
Originally Posted by BradAMiller
There might be better ways of doing this without global variables if you were hand coding in C, but this will solve the problem easily in EasyC.

Hope this helps.

Thanks again guys. I dunno how we got through last year. We must have used all globals and didn't know it. I don't remember this "rule" when programming in C. But now I will never forget and neither will my programmers. BTY, it works like a champ now using globals. Looks too messy to try and do with an array in EasyC, or even doing your own structures...It doesn't look like EasyC support structures, but I did see something in the help on Arrays, we need to read up on that...


Again, thanks a bunch.
__________________
Team T.H.R.U.S.T. 1501
Download all of our past robot's source code here:Repository

Favorite CD quote:
"That can't be their 'bot. not nearly enough (if any) rivets to be a 1501 machine." ~RogerR: Team #1369
  #3   Spotlight this post!  
Unread 18-01-2006, 09:31
Kingofl337's Avatar
Kingofl337 Kingofl337 is offline
You didn't see anything....
AKA: Adam
FRC #0501 (Power Knights)
Team Role: Mentor
 
Join Date: Feb 2005
Rookie Year: 1998
Location: Manchester, NH
Posts: 861
Kingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond repute
Send a message via Yahoo to Kingofl337
Re: Strange Problem, varible not subtracting?

Arrays work fine in EasyC. The problem is the complier limits the program to 250 "char" slots total in the program. Int is limited to 120.
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
Need a realistic Statics Problem sanddrag Technical Discussion 10 05-12-2005 15:07
Strange system problem Bill Becker Control System 16 12-04-2005 17:19
Strange Multi-Turn Potentiometer Problem Yellow Eyes Electrical 10 24-02-2005 13:53
Strange Encoder Problem AIBob Electrical 3 20-02-2005 22:20
Strange Auto Problem NotQuiteFree Programming 6 20-02-2005 17:12


All times are GMT -5. The time now is 14:39.

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