View Single Post
  #6   Spotlight this post!  
Unread 18-02-2007, 11:50
Bongle's Avatar
Bongle Bongle is offline
Registered User
FRC #2702 (REBotics)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Waterloo
Posts: 1,069
Bongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond repute
Send a message via MSN to Bongle
Re: Looping a function

Are you absolutely sure that the function is working properly? If it was executed once from Process_Data_From_Master_uP, and isn't in an if statement or other structure, it is probably getting executed again (especially if you are printing results from it).

Check the function to make sure that it is using the right inputs, and that it is definetely USING them. I've had this problem before, and without fail it is because I used the wrong variable, or in one of the lines of the function, I didn't use the result from the previous line. You could also post the code and let us look at it. I wouldn't worry about people stealing it. After all, it is broken

Another possibility is that you have scope problems. Code like this could cause issues like you are seeing:
Code:
// Bongle's error in scoping example
int degrees = 5;
printf("%d,%d,%d",servo,tilt,other) // verifies all the inputs are changing
if(someCondition)
{
   int degrees; // creates a variable that shares name with another variable in the code
   degrees = myCustomFunction(); // calls the function, assigns it to the most-local variable (the one we just declared)
}                   // at this closing brace, the degrees variable that stored our result is destroyed
printf("%d",degrees) // always prints out a constant value, despite inputs always changing
Your output will never change (it will always print 5) because the assignment statement in the if statement assigns the return value to a variable that shortly afterwards is destroyed at the end of the if statement.

Last edited by Bongle : 18-02-2007 at 11:54.