![]() |
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. |
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. |
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. |
Re: the main code
Quote:
Code:
do { |
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.
|
Re: the main code
Only if they don't terminate properly. :D
If you write them carefully, you shouldn't have too much trouble. |
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! :o
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. |
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!! |
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. |
Re: the main code
Quote:
|
| All times are GMT -5. The time now is 23:10. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi