Go to Post One of those things I learned in kindergarten - never introduce myself to an “enraged” woman wielding a clipboard. - Mark McLeod [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-02-2007, 16:49
Tz0m Tz0m is offline
Registered User
FRC #0333
Team Role: Programmer
 
Join Date: Feb 2006
Rookie Year: 2006
Location: New York
Posts: 17
Tz0m is an unknown quantity at this point
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   Spotlight this post!  
Unread 17-02-2007, 17:39
Shinigami2057 Shinigami2057 is offline
Slackware Is Your New God (Mentor)
AKA: Harry Bock
FRC #1350 (Rambots)
Team Role: Programmer
 
Join Date: Oct 2006
Rookie Year: 2006
Location: Johnston, RI
Posts: 106
Shinigami2057 is just really niceShinigami2057 is just really niceShinigami2057 is just really niceShinigami2057 is just really niceShinigami2057 is just really nice
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.
__________________
One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs.
  #3   Spotlight this post!  
Unread 17-02-2007, 21:23
Tz0m Tz0m is offline
Registered User
FRC #0333
Team Role: Programmer
 
Join Date: Feb 2006
Rookie Year: 2006
Location: New York
Posts: 17
Tz0m is an unknown quantity at this point
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   Spotlight this post!  
Unread 17-02-2007, 21:31
paulcd2000's Avatar
paulcd2000 paulcd2000 is offline
Accidentally speaks in C
AKA: Paul Dagnelie
FRC #1719 (The Umbrella Corp.)
Team Role: Programmer
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Baltimore
Posts: 368
paulcd2000 is a jewel in the roughpaulcd2000 is a jewel in the roughpaulcd2000 is a jewel in the rough
Send a message via AIM to paulcd2000
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?
__________________
"People don't say 'It's just a game' when their team is winning!" -- Scott Adams

5.5 students (on average)* $7/h *210 hours/student= $8085 of labor, all volunteered (not counting mentors', who are each that much)

We have blades on our robot?! ***sweeeeeet***

There are 11 types of people in the world. Those who can read binary, those who can't, and those who say this joke is supposed to be, "There are 10 types of people in the world. Those who can read binary and those who have a life."
  #5   Spotlight this post!  
Unread 18-02-2007, 09:31
Tz0m Tz0m is offline
Registered User
FRC #0333
Team Role: Programmer
 
Join Date: Feb 2006
Rookie Year: 2006
Location: New York
Posts: 17
Tz0m is an unknown quantity at this point
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   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.
  #7   Spotlight this post!  
Unread 19-02-2007, 00:32
Tz0m Tz0m is offline
Registered User
FRC #0333
Team Role: Programmer
 
Join Date: Feb 2006
Rookie Year: 2006
Location: New York
Posts: 17
Tz0m is an unknown quantity at this point
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   Spotlight this post!  
Unread 19-02-2007, 06:41
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
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   Spotlight this post!  
Unread 19-02-2007, 12:37
Tz0m Tz0m is offline
Registered User
FRC #0333
Team Role: Programmer
 
Join Date: Feb 2006
Rookie Year: 2006
Location: New York
Posts: 17
Tz0m is an unknown quantity at this point
Re: Looping a function

The code is:
Quote:
printf("Distance = %d", DistanceCalc(TILT_SERVO));
The code for the DistanceCalc function is:
Quote:
int DistanceCalc(int tiltS)
{
int tiltD, tiltR, dist;
tiltD = ((tiltS - 124) * 65) / 124;
tiltR = (tiltD * 3.14159265) / 180.0;
dist = 80.0 / tan(tiltR);
return dist;
}
  #10   Spotlight this post!  
Unread 19-02-2007, 13:40
robind robind is offline
Registered User
FRC #0675
 
Join Date: Dec 2006
Location: Rohnert Park
Posts: 31
robind is an unknown quantity at this point
Re: Looping a function

I coulda sworn TILT_SERVO was a byte...
  #11   Spotlight this post!  
Unread 19-02-2007, 14:43
jdejoannis jdejoannis is offline
Registered User
FRC #1845
 
Join Date: Feb 2006
Location: Atlanta,GA
Posts: 48
jdejoannis will become famous soon enoughjdejoannis will become famous soon enough
Re: Looping a function

Code looks alright to me. Try different things, eg.
  • Print TILT_SERVO itself - does it change?
  • Create a new variable to hold the distance and then print it
  • Use the (int) mask on the function and its argument
  • Make sure you are downloading the newly compiled hex and not some old version
  • Be nice to your eyes and include a \r\n in your print statement
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
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


All times are GMT -5. The time now is 17:31.

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