Go to Post Instead of giving us some wood and nails and saying "build us a box", they're handing us power tools and saying "now make us something cool" - galewind [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 09-01-2008, 13:49
Roni2230 Roni2230 is offline
Registered User
FRC #2230
 
Join Date: Jan 2007
Location: Israel
Posts: 3
Roni2230 is an unknown quantity at this point
the main code

Hey,
I have some questions about the main code(ifi_frc.c).
what is the meaning of the loop: "while(true)"?--the main loop I think, and how much times does it run until it ends?
and how many times the program runs per sec?
Is it the main code?

thank you very much,
Team 2230.
  #2   Spotlight this post!  
Unread 09-01-2008, 14:18
Roger Roger is offline
Registered User
FRC #1153
 
Join Date: Jan 2006
Rookie Year: 1900
Location: Walpole MA
Posts: 688
Roger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond repute
Re: the main code

The while loop continues to loop while the condition in the () remains true. It is checked at the beginning of the loop. (There is another kind of while loop that checks at the end of the loop.)

So a while(true) -- or a while(1) -- or a while (1==1) -- continues forever until an outside condition stops it, such as the field gets turned off at the end of a match, or something inside the loop jumps out of the loop (not likely). It's a simple way of letting your code run forever until you turn it off.
  #3   Spotlight this post!  
Unread 09-01-2008, 15:40
gnormhurst's Avatar
gnormhurst gnormhurst is offline
Norm Hurst
AKA: gnorm
#0381 (The Tornadoes)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Trenton, NJ
Posts: 138
gnormhurst will become famous soon enoughgnormhurst will become famous soon enough
Re: the main code

A movie is made up of a series of still images that give the appearance of continuous motion. The robot controller works like that: each pass through the loop (that statusflag.NEW_SPI_DATA == 1) is like a new movie frame. A snapshot is taken of the input data and processed by your code, then the controller takes a snapshot of your output values and sends them to the robot.

If the loop stops it would be like stopping a movie. You'd get a frozen frame, or a robot with a frozen set of output values. That while( TRUE ) loop is the crank that keeps the movie going.
__________________
Trenton Tornadoes 381
2004 Philadelphia Regional Winners
2006 Xerox Creativity Award
---
My corner of the USPTO.
My favorite error message from gcc: main is usually a function
My favorite error message from Windows: There is not enough disk space available to delete this file.
  #4   Spotlight this post!  
Unread 09-01-2008, 19:08
MARS-CJ's Avatar
MARS-CJ MARS-CJ is offline
Registered User
AKA: Carl Jalm
FRC #1523 (M.A.R.S.)
Team Role: Scout
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Jupiter, FL
Posts: 32
MARS-CJ is on a distinguished road
Send a message via AIM to MARS-CJ
Re: the main code

Quote:
Originally Posted by Roger View Post
The while loop continues to loop while the condition in the () remains true. It is checked at the beginning of the loop. (There is another kind of while loop that checks at the end of the loop.)
That'd be a do-while loop.

Code:
do {
    printf("Looping...\n");
} while(x == 2);
  #5   Spotlight this post!  
Unread 09-01-2008, 19:28
tseres's Avatar
tseres tseres is offline
obsessed with FIRST...
FRC #1565 (Think Tank Tech)
Team Role: Leadership
 
Join Date: Apr 2007
Rookie Year: 2007
Location: Cambridge, ON
Posts: 305
tseres is a glorious beacon of lighttseres is a glorious beacon of lighttseres is a glorious beacon of lighttseres is a glorious beacon of lighttseres is a glorious beacon of lighttseres is a glorious beacon of light
Re: the main code

as a side note, try to avoid loops in your custom code, as they tend to cause the processor to crash.
__________________


  #6   Spotlight this post!  
Unread 09-01-2008, 21:31
slavik262's Avatar
slavik262 slavik262 is offline
We do what we must because we can.
AKA: Matt Kline
FRC #0537 (Charger Robotics)
Team Role: Alumni
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Sussex, WI
Posts: 310
slavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to behold
Send a message via AIM to slavik262
Re: the main code

Only if they don't terminate properly.

If you write them carefully, you shouldn't have too much trouble.
__________________
  #7   Spotlight this post!  
Unread 10-01-2008, 06:44
Roger Roger is offline
Registered User
FRC #1153
 
Join Date: Jan 2006
Rookie Year: 1900
Location: Walpole MA
Posts: 688
Roger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond repute
Re: the main code

Yeah, I get the different loops syntax mixed up. Be thankful I remember that I know they are there, and I know where to look them up!

I'm curious how far can you stretch the loop until you really ought to break out. I had a loop that took (I forget) 16-20 sonar readings in one pass of the code, then the next pass start printf'ing them out. The printf is much slower and I didn't try doing it in one pass, and as it turns out, the sonar readings take more time than one pass apiece.
  #8   Spotlight this post!  
Unread 10-01-2008, 08:26
Roni2230 Roni2230 is offline
Registered User
FRC #2230
 
Join Date: Jan 2007
Location: Israel
Posts: 3
Roni2230 is an unknown quantity at this point
Re: the main code

Thank YOU every one.
But what is the spin per sec?
I think its 62...
I am not sure...

Thank YOU from Israel!!
  #9   Spotlight this post!  
Unread 10-01-2008, 10:44
dcbrown dcbrown is offline
Registered User
AKA: Bud
no team
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Hollis,NH
Posts: 236
dcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud of
Re: the main code

The main while(1){} in the default code without any user changes is executed about 830,000 times a second. Once you start adding your own code then it will get slower.[1]

The inner loop via the new spi data check is executed at most ~38 times per second (new data from the operator interface is available every 26.2ms).

The best thing to do would be to read some of the documentation at the ifirobotics site on the structure of the main loop.

And while it is true you can get the red light of death if you make your program execution path too long -- there is an easy way to avoid this ala EasyC/WPILIB. Namely you move the getdata/putdata into an event routine that is run during the system clock interrupt. Then it doesn't matter how long your program execution path is unless you really do something nasty to hang the processor so it won't service interrupts.

[1] the default code path is roughly 12 instruction cycles long but this doesn't account for the background global interrupt routine that is handling the SPI bus transfers of data between the master and user processors, nor the Process_Data_From_Master_uP routine that is executed 38 times per second, so maybe it has an average code path length of 20 instruction cycles in the default code and it only runs 500,000 times per second.
  #10   Spotlight this post!  
Unread 10-01-2008, 12:14
ay2b's Avatar
ay2b ay2b is offline
Registered User
AKA: Andy
FRC #2928
Team Role: Mentor
 
Join Date: Mar 2004
Rookie Year: 1994
Location: Seattle, WA
Posts: 211
ay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant future
Re: the main code

Quote:
Originally Posted by Roni2230 View Post
Thank YOU every one.
But what is the spin per sec?
I think its 62...
I am not sure...
This depends on how much code you have. If the spin() loop is empty, it will get called thousands of times. If it does a lot of calculations, it might only get called tens of times. If you are processing lots of interrupts, that will also slow down the spin() loop.
__________________

2011 - SD Quarterfinalists (980), LA Quarterfinalists (980)
2010 - LA (2404) Finalists (980), AZ Motorola Quality (980)
2009 - LA Semifinalists (980); Las Vegas Quarterfinalists (980); SD (2404); IRI #1 Seed, Finalist (980)
2008 - SD Quarterfinalists (980), LA Champions (980), LA Rookie Inspiration Award (2404); CalGames Finalists
2007 - So.Cal Finalists (980), SD Quarterfinalists (980); CalGames Finalists
2006 - So.Cal Regional Champion (4), Toronto Judge's Award Day 1 (4)
2005 - SVR Champions, Delphi "Driving Tomorrow's Technology" (980); AZ Xerox Creativity (980); So.Cal Finalists, RadioShack Innovation in Control (980); Championship Archimedes Division Semifinalists; IRI Finalists (980)
2004 - So.Cal Regional Champions, Leadership in Controls (980); AZ GM Industrial Design (980); Championship Galileo Division #2 Seed; IRI Champions
2003 - PNW Semi-finalists (488)
2002 - PNW Finalists (488)
2000 - X-bot / 488 - Mentor / Founder
1994 - Sunny Delight - Driver - champion
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
changing main.c 3dude_2231 Programming 15 21-02-2007 01:54
main.c 6600gt Programming 3 29-08-2006 02:19
Editing Main.c Astronouth7303 Programming 22 20-02-2004 16:45
Main Stage archiver 2001 3 24-06-2002 03:06
main driver Kaitlin Palmer Off-Season Events 0 09-04-2002 21:26


All times are GMT -5. The time now is 18:33.

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