|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Looping a function
For the IFI controller, it supposedly re-executes the user_routines.c file every 20 some-odd ms. I have a printf statement that prints the distance from the target using a custom function. However, when the tilt angle changes, the distance stays the same. It apparently does not keep re-evaluating the function and printing out the new value. Thanks for the help.
|
|
#2
|
|||
|
|||
|
Re: Looping a function
The code in user_routines.c is NOT executed every 26.2ms; the function Process_Data_From_Master_uP() does. Any code you want looped at that rate must be called through that function, or another function called within Process_Data_From_Master_uP(). Just because it is contained in that file does not mean it will be called at the same time as the 26.2ms "loop". They are contained there for organization.
|
|
#3
|
|||
|
|||
|
Re: Looping a function
The code is placed in the Process_Data_From_Master_uP() function.
Last edited by Tz0m : 18-02-2007 at 09:45. |
|
#4
|
||||
|
||||
|
Re: Looping a function
how do you know that the tilt angle changes? i'm assuming you mean the camera moves. Could you maybe post how you're calculating the angle?
|
|
#5
|
|||
|
|||
|
Re: Looping a function
I'm using the already defined variable TILT_SERVO to calculate distance. First I convert that number into degrees and then into radians so it can be passed to tangent. The tilt angle does change. I have it print out the servo values and degree values. The servo values have to be correct. I have also manually calculated angle values for servo values and they match up in the terminal window.
|
|
#6
|
||||
|
||||
|
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
Last edited by Bongle : 18-02-2007 at 11:54. |
|
#7
|
|||
|
|||
|
Re: Looping a function
The function is working properly. I do not have my function setup as an if statement or anything like that. The function is also being called from within a printf.
|
|
#8
|
|||||
|
|||||
|
Re: Looping a function
Could you at least show us the line of code that isn't working the way you want it to? We can't help you much if we can't see what's wrong.
|
|
#9
|
|||
|
|||
|
Re: Looping a function
The code is:
Quote:
Quote:
|
|
#10
|
|||
|
|||
|
Re: Looping a function
I coulda sworn TILT_SERVO was a byte...
|
|
#11
|
|||
|
|||
|
Re: Looping a function
Code looks alright to me. Try different things, eg.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Arcade Function | gabrielse | Programming | 1 | 08-02-2006 00:49 |
| Autocalibrate function | Validius | Programming | 2 | 29-03-2005 21:59 |
| Looping Atonomous | BobcatProgramer | Programming | 2 | 24-02-2004 14:06 |
| FreeLibrary() Function | Raven_Writer | Programming | 0 | 09-08-2003 15:39 |
| control program looping??? | ctartist236 | Programming | 1 | 08-02-2002 10:09 |