Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Looking for help with creating a timer. (http://www.chiefdelphi.com/forums/showthread.php?t=64095)

stuffssguy 14-02-2008 18:22

Looking for help with creating a timer.
 
We want to use a timer for executing commands. (if x button is pushed than p happens and after a certain amount of time q happens) This would most likely be for controlling the solenoids on our robot so that with one button push a piston would extend before the other. We would also use it for driving functions.

seanl 14-02-2008 20:06

Re: Looking for help with creating a timer.
 
you need to add a global variable at the top and if you put a counter in the while loop for autonomous you can count the iterations. this is the only way you can do it. if you put a delay in you will get the red light of death.

Mark McLeod 14-02-2008 22:48

Re: Looking for help with creating a timer.
 
For MPLAB IFI/Watson based programming...

To use a real timer take a look at the IFI explanation in this white paper: http://www.ifirobotics.com/docs/time...004-jan-14.pdf

Kevin Watson has some examples here: http://www.kevin.org/frc/2005/

taggartbg 15-02-2008 00:11

Re: Looking for help with creating a timer.
 
use a "wait" function in the code

if(button){
do thing one;
Wait(3000);
do thing two;
}

The value inside the "wait" function is in milliseconds, so the above code would pause for 3 seconds between thing one and thing two.

Mark McLeod 15-02-2008 00:17

Re: Looking for help with creating a timer.
 
For Easy C or WPILIB based programming ...

Quote:

Originally Posted by taggartbg (Post 699249)
use a "wait" function in the code

if(button){
do thing one;
Wait(3000);
do thing two;
}

The value inside the "wait" function is in milliseconds, so the above code would pause for 3 seconds between thing one and thing two.


Kevin Watson 15-02-2008 00:54

Re: Looking for help with creating a timer.
 
Quote:

Originally Posted by stuffssguy (Post 699032)
We want to use a timer for executing commands. (if x button is pushed than p happens and after a certain amount of time q happens) This would most likely be for controlling the solenoids on our robot so that with one button push a piston would extend before the other. We would also use it for driving functions.

If you're using my 2008 robot controller code, I've created drop-in replacement code for timer.c and timer.h that implements a millisecond system clock using timer 2. The code is available here: http://kevin.org/frc/ifi_clock.zip.

-Kevin

xrabohrok 15-02-2008 15:51

Re: Looking for help with creating a timer.
 
the program loops at 36 times a second. With this knowledge, you could create something that would measure this. I wouldn't advise letting a counter variable get into the thousands, because then the program starts running slower. something like this worked nicely for me:

Code:

//global variables
int count = 0;
int second = 0;


//somewhere in code
if (count >= 37)
{
      count = 0;
}
count++;

//you could compare things like this
switch second
{
        case 0: //what happens right off the back
                  break;
        case 1: //what happens in the first second
                  break;
        case 2: //what happens in second second (ha!)
                  break;
        default: //what should happen when out of time

}


stuffssguy 16-02-2008 22:09

Re: Looking for help with creating a timer.
 
The code says we are missing IFI_FRC.h


All times are GMT -5. The time now is 00:56.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi