We use a timer to implement delays. Here is our bread and butter 2-ball front of key autonomous code - this is called from AutonomousPeriodic:
Code:
void XM15::AutoThree1(void)
{
//printf("3-PT 1 - Front of Key\n");
#define TH1_READYDWELL 4.0 //Dwell time to permit to move to shot position
#define TH1_SHOTDELAY 0.5 //Short pause between oktoshoot signal and feeding ball
#define TH1_SHOT1DWELL 0.4 //0.5 OK - Feed time for first ball
#define TH1_SHOT2DWELL 1.0 //Feed time for second ball
#define TH1_REGENDWELL 1.5 //Wait for shooter to regain speed = originally 2.0
switch (autonStep)
{
case 1: //Select Front Key Three Arm Position & Spin Up Shooter
{
autofrontkeythree_sw = 1;
shooterstate = ON;
if (delaytimer->Get() < delayset) //Wait until the timer times past the preset delay
{
//Waiting...
}
else
{
delaytimer->Stop();
autotimer->Reset();
autonStep = 2;
}
break;
}
case 2: //Wait for arm and shooter to be ready (or watchdog timeout), then fire a ball
{
if ( (oktoshoot == 1) || (autotimer->Get() > TH1_READYDWELL) )
{
autotimer->Reset();
autonStep = 3;
}
break;
}
case 3: //Wait for a short moment after arm in position before firing a ball
{
if (autotimer->Get() > TH1_SHOTDELAY)
{
autocagefeed_sw = 1;
autotimer->Reset();
autonStep = 4;
}
break;
}
case 4: //Stop firing after timeout
{
if (autotimer->Get() > TH1_SHOT1DWELL)
{
autocagefeed_sw = 0;
autotimer->Reset();
autonStep = 5;
//autonStep = 7; //Debug - permits tuning of initial shot timing
}
break;
}
case 5: //Wait for shooter to regain speed, then fire again
{
if (autotimer->Get() > TH1_REGENDWELL)
{
if (speedok == 1)
{
autocagefeed_sw = 1;
autotimer->Reset();
autonStep = 6;
}
}
break;
}
case 6: //Turn shooter off after 2nd ball is fired
{
if (autotimer->Get() > TH1_SHOT2DWELL)
{
autocagefeed_sw = 0;
autotimer->Reset();
autonStep = 7;
}
break;
}
case 7: //Program is done - turn off the shooter, place arm in load position
{
shooterstate = OFF;
//autofrontkeythree_sw = 0;
//autoloadball_sw = 1;
break;
}
}
}