You are on page 1of 2

HallService State Machine

ES_Event RunHallService( ES_Event ThisEvent )


{
// set return event type to assume no errors
//if current state
//If CurrenstState is Hall_Idle, Navigate to the Stage
//if current state is Hall_Idle
//if the driving through stage timer has expired, and we have driven fully off a
stage after checking in
//we've finished driving off the stage, so reset the flag
//if we received a look for stage command while we were still driving off
the stage
//then switch to the state that looks for staging area
frequencies while driving
//enable the input capture interrupt on rising edges, to allow
for measuring of the staging area period
//reset the flag

//if we are now looking for a staging area while driving


//Transition state to Hall_CalcPeriod
//if we're not still driving off the stage after a check-in, then it's ok
to start the hall sensor to look for more staging areas
//switch to the state that looks for staging area frequencies
while driving
//enable the input capture interrupt on rising edges, to allow
for measuring of the staging area period
//else if we are still driving off the stage
//mark that we received a look for stage command

//end if

//If CurrentState is Hall_CalcPeriod


//this state searches for staging areas when we drive along the wire
//Set PeriodSummation, EdgesCounter and HallPeriodAvg to 0
//If an ES_PERIOD_SAMPLED event is received from from Hall Sensor Input Capture
Response
//If the Average Frequency Found in ISR can be fit in a bin
//try to bin the most recent frequency, and if we successfully bin it
//declare a new event
//indicate that we've found a staging area
//post the event to the game master
//initialize the debounce timer, during which the interrupt will
be disabled
//else
//enable the input capture interrupt on rising edges, to compute
the staging area period

//if the driving through stage timer has expired, and we are through a staging area
that is not the target
//enable the input capture interrupt on rising edges (disabled in ISR
after posting ES_PERIOD_SAMPLED)
//if we've found the target staging area
//switch states to the checking in state
//enable the input capture interrupt and start recording the staging area
period

//end if
//if we're currently checking in to a staging area
//if we just captured enough edges to bin
//If the average period found in ISR can be fit in a bin
//enable the input capture interrupt on rising edges, to compute the
staging area period
//if ES_STAGING_AREA_OPEN is posted from GameplaySM (i.e successful check in
completed)
//if we've opened a staging area successfully
//We want to return to the idle state and wait for another ES_FIND_STAGE
command
//return to the idle state
//disable the input capture interrupt
//initialize the after checking-in debounce timer, during which the
interrupt will be disabled
//we just checked in, so we don't want to trigger another check-in until
we've driven off the stage
//set LastHallPeriodBin = 0;
//set HallPeriodBin = 0;
//set LastBinnedCode = 0;
//set EdgesCounter = 0;
}
//if we just checked into an inactive staging area and updated our location
//We want to return to the idle state and wait for another ES_FIND_STAGE
command
//return to the idle state
//disable the input capture interrupt
//initialize the after checking-in debounce timer, during which the
interrupt will be disabled
//we just checked in, so we don't want to trigger another check-in until
we've driven off the stage
//set LastHallPeriodBin = 0;
//set HallPeriodBin = 0;
//set LastBinnedCode = 0;
//set EdgesCounter = 0;
}
//end if
}

//Return No error event


}

You might also like