Go to Post Winning the robot part of the competition is not about learning or doing unneccesary work. It works just like "winning" in industry. - Max Lobovsky [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, 00:22
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 Matt Adams
You need to set your variable enc_Right_Count_Old = 50 before you want to use math involving it, or it will just use zero (it doesn't know any better!). Move it to the line above the subtraction, it should work as expected.Matt

Hi Matt,

Thanks for the time in checking this out.

We don't want to set that varible first, or before the math. It is true that the first loop through the CPU it will be ZERO. But then it gets a value (50) at the bottom on the first loop. Shouldn't the CPU remember this value, so in loop pass #2, now that varible is set to 50 and it should correctly excute the subtract math?

We only want to update this varible at the end because we are doing a velocity measurement sampling the encoder counts.

I posted Screen 1 through 4 to show you what we are trying to do our testing, basiclly to eliminate "Have you tried this? Have you tried that?" Sort of thing....

Screen shot #5 is what we want, but we found out the problem in screen shot 3 and 4. By the varible updating but not being able to get subtracted above it.
__________________
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

Last edited by Chris_Elston : 17-01-2006 at 00:24.
  #2   Spotlight this post!  
Unread 17-01-2006, 01:03
Matt Adams's Avatar
Matt Adams Matt Adams is offline
b(o_o)d
FRC #1525 (Warbots)
Team Role: Engineer
 
Join Date: Dec 2003
Rookie Year: 2000
Location: Arlington Hts. IL
Posts: 375
Matt Adams has a reputation beyond reputeMatt Adams has a reputation beyond reputeMatt Adams has a reputation beyond reputeMatt Adams has a reputation beyond reputeMatt Adams has a reputation beyond reputeMatt Adams has a reputation beyond reputeMatt Adams has a reputation beyond reputeMatt Adams has a reputation beyond reputeMatt Adams has a reputation beyond reputeMatt Adams has a reputation beyond reputeMatt Adams has a reputation beyond repute
Send a message via AIM to Matt Adams
Re: Strange Problem, varible not subtracting?

Quote:
Originally Posted by chakorules
Hi Matt,

Thanks for the time in checking this out.

We don't want to set that varible first, or before the math. It is true that the first loop through the CPU it will be ZERO. But then it gets a value (50) at the bottom on the first loop. Shouldn't the CPU remember this value, so in loop pass #2, now that varible is set to 50 and it should correctly excute the subtract math?

We only want to update this varible at the end because we are doing a velocity measurement sampling the encoder counts.
This is a special case, because its a seperate function. Each time you call this function, everything starts from scratch, assuming you are not sending the value of enc_Right_Old_Count to this function each time (which is appears you aren't). I notice that you are only returning the value of enc_Right_Distance, so the primary loop that is calling this function has no recollection of what might have been previously use internally with this function (read: it doesn't know what the value of enc_Right_Old_Count might have been).

If you want to reuse the value of enc_Right_Old_Count, one way is to return this value from your function and then send it back as an arguement each time its called in your main loop.

This is where... my syntax experience with C gets foggy. If you want to return and reuse both parameters, I think you'll actually need to return them as an array, since you can't return more than 1 variable from a function. You'll need to make a 2 element array, return them and if you wish for cosmetic reasons, split them up.

Some brief example code inside the function right_velocity would be:

Code:
long velocity_right(enc_Right_Old_Count)
{
long distance_and_old_count[2]; // declares this array
 
** MATH **
 
distance_and_old_count[0] = enc_Right_Difference;
distance_and_old_count[1] = enc_Right_Old_Count;
 
return distance_and_old_count;
}
The [2] specifies the size, but the array actually starts at element [0]. That's what makes C a little different than some other languages.


In the main outter loop, you would use something like the following to send the en_Right_Old_Count value to the function:
Code:
distance_and_old_count = right_velocity(enc_Right_Old_Count);
enc_Right_Difference = distance_and_old_count[0];
enc_Right_Old_Count = distance_and_old_count[1];
Matt

Last edited by Matt Adams : 17-01-2006 at 01:15.
  #3   Spotlight this post!  
Unread 17-01-2006, 07:55
Gdeaver Gdeaver is offline
Registered User
FRC #1640
Team Role: Mentor
 
Join Date: Mar 2004
Rookie Year: 2001
Location: West Chester, Pa.
Posts: 1,367
Gdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond repute
Re: Strange Problem, varible not subtracting?

Use global variables if you want variables to be persistent through many function calls.

Last edited by Gdeaver : 17-01-2006 at 07:57.
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