View Full Version : programs and timeing.
Paul Jr.
19-02-2004, 14:04
I am writing a autonomous function and I need to know if
there is a function or command that returns the time.
elapsed time or just the current time is ok. I will call this
command from with in the fast.c program. In C there is the function clock() but it requires the <time.h> file as an include file. This file is not with our software for this robot.
Also I need a function to pause the program. In assembly I beleive the command "pause" does this but I need to do it
in C.
Thanks;
There are library timers included with the compiler. Look in the attched file to find out how to use them. (Look for the timers section)
I'm not sure of how you are thinking of doing the pause, but you'll have to make sure that get/putdata() is called at least every 26.2ms or the master processor on the RC will halt the program.
--EDIT--
Oh, yeah, since you at least konw what asembly is: to do asembly instructions in C do something like:
asm asmembly instruction;
--EDIT--
The file is too large to upload, but it can be found on the microchip website. (Don't remember where exactly)
Kevin Watson
19-02-2004, 15:23
I am writing a autonomous function and I need to know if
there is a function or command that returns the time. There is example code here (http://kevin.org/frc) that shows how to do what you want. It's written for the EDU-RC, but can be easilly ported to the FRC-RC.
-Kevin
Phil_Lutz
19-02-2004, 17:31
Why do you need to pause the program?
For testing purposes?
If so, you can code a switch, when closed allows the code to execute, when released if stops.
if ((autonomous_mode = 0) || (AUTON_SWITCH = 1))
{
execute auton code
}
Or something like that. (I don't have my code in front of me. :)
AUTO_SWITCH - is an alias to one of the O/I joystick triggers for testing only. Make sure to remove it before comp.
Phil
Astronouth7303
20-02-2004, 16:27
Why do you need to pause the program?
For testing purposes?
If so, you can code a switch, when closed allows the code to execute, when released if stops.
if ((autonomous_mode = 0) || (AUTON_SWITCH = 1))
{
execute auton code
}
Or something like that. (I don't have my code in front of me. :)
AUTO_SWITCH - is an alias to one of the O/I joystick triggers for testing only. Make sure to remove it before comp.
First of all, that's a logical OR. You want AND (&&).
How about this? In main.c:
while (1) /* This loop will repeat indefinitely. */
{
#ifdef _SIMULATOR
statusflag.NEW_SPI_DATA = 1;
#endif
if (!PAUSE_SWITCH)
{
if (statusflag.NEW_SPI_DATA) /* 26.2ms loop area */
{ /* I'm slow! I only execute every 26.2ms because */
/* that's how fast the Master uP gives me data. */
Process_Data_From_Master_uP(); /* You edit this in user_routines.c */
if (autonomous_mode) /* DO NOT CHANGE! */
{
User_Autonomous_Code(); /* You edit this in user_routines_fast.c */
}
}
Process_Data_From_Local_IO(); /* You edit this in user_routines_fast.c */
/* I'm fast! I execute during every loop.*/
}
} /* while (1) */
Basically, if you flip the switch, the robot will finish, and then go into a really fast loop: it does nothing until you turn it off. Be sure to but something similar in the auto.mode code: it has its own loop.
First of all, that's a logical OR. You want AND (&&).
if ((autonomous_mode = 0) || (AUTON_SWITCH = 1))
{
execute auton code
}
Well, I believe the idea is so that the auto code executes if the team's AUTON_SWITCH is activated OR if the IFI controller inidicates via the competition port that the robot is in autonomous mode. However, you want to be careful that you use the equivalene test, not the assignment operator--it probably was a copying error, but for those who might use it, make sure you put == not =. Also, why the 0? Do you mean 1? (Hrm, or do you mean 0, in which case you would need AND, no?) Also, see below.
How about this? In main.c:
while (1) /* This loop will repeat indefinitely. */
{
#ifdef _SIMULATOR
statusflag.NEW_SPI_DATA = 1;
#endif
if (!PAUSE_SWITCH)
{
if (statusflag.NEW_SPI_DATA) /* 26.2ms loop area */
{ /* I'm slow! I only execute every 26.2ms because */
/* that's how fast the Master uP gives me data. */
Process_Data_From_Master_uP(); /* You edit this in user_routines.c */
if (autonomous_mode) /* DO NOT CHANGE! */
{
User_Autonomous_Code(); /* You edit this in user_routines_fast.c */
}
}
Process_Data_From_Local_IO(); /* You edit this in user_routines_fast.c */
/* I'm fast! I execute during every loop.*/
}
} /* while (1) */
Basically, if you flip the switch, the robot will finish, and then go into a really fast loop: it does nothing until you turn it off. Be sure to but something similar in the auto.mode code: it has its own loop.
Well, if you're going to all the trouble of creating a disable switch, why add extra code when you can just use the competition port to create a disable button as the program is? And while you're there, you can create your auton switch too, and won't need extra code. It will simulate the competition. competition pin-out guide (http://www.innovationfirst.com/FIRSTRobotics/pdfs/Competition_Port_Pinout_Guide.PDF) [pdf file].
I'd carefully analyze why you want to pause. But there are several ways to go about it -- you have a timer interrupt, so you can program a pause function easily enough to pause for a given amount of time. A quick solution, if that's all you need it for, is just to have an empty for loop that executes some pre-determined amount. e.g.,
for (waste_time = 0; waste_time < TIME_TO_WASTE; waste_time++) ;
// remember: declare waste_time elsewhere, and define TIME_TO_WASTE
deltacoder1020
21-02-2004, 18:56
note that if you pause the robot, you should still be calling putdata every 26.2ms, otherwise the frc will shut down.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.