You are on page 1of 6

Data private to the module: MyPriority, CurrentState

RunOffenseSM
{
set transition event flag to false
switch CurrentState
{
case RELOADING :
set ReturnEvent and CurrentEvent to returned event from DuringReloading function
if there is an active event
{
switch current event
{
case ES_TIMEOUT :

if Event param is HANDSHAKE_TIMER


{
increment the num of balls
next state is MOVING_BACKWARD

set transition event flag to true

}
break
}
}
break

case ROTATING_TO_SHOOT :

set ReturnEvent and CurrentEvent to returned event from DuringRotatingShoot function


if there is an active event
{
switch current event
{
case EV_ATTACK_GOAL_DETECTED :

Next State is FINDING_SHOT


mark that we are taking a transition
break
}
}
break

case FINDING_SHOT :
set ReturnEvent and CurrentEvent to returned event from DuringFindingShot function

if there is an active event


{
switch current event
{
case ES_TIMEOUT:
if event paramater is from retroreflective timer
{
Next State is SHOOTING
mark that we are taking a transition
}
break
case EV_OBJECT_DETECTED_RETRO:
set number of edges to 0
Next State is MOVING_BACKWARD
mark that we are taking a transition
break
case EV_EARLY_DEFENSE :
returned event MAKE_DEFENSE_ENTRY_STATE_ROTATING to upper level state machine
mark that we are taking a transition
break
}
}
break

case MOVING_BACKWARD :
set ReturnEvent and CurrentEvent to returned event from DuringMovingBackward function
if there is an active event
{
switch current event
{
case ES_TIMEOUT:
if event param is from DARK_HORSE_TIMER
{
Next State is ROTATING_TO_SHOOT
mark that we are taking a transition
}
break
case EV_OBJECT_DETECTED_SHARP_3 :
Next State is ROTATING_TO_DEFINITELY_SHOOT
mark that we are taking a transition
}
}
break

case ROTATING_TO_DEFINITELY_SHOOT :
set ReturnEvent and CurrentEvent to returned event from DuringRotatingToDefinitelyShoot function
if there is an active event
{
switch current event
{
case EV_ATTACK_GOAL_DETECTED :
Next State is SHOOTING
mark that we are taking a transition
break
}
}

if we are making a state transition


{
Execute exit function for current state

Modify state variable

Execute entry function for new state

}
return returned event
}

StartOffenseSM
{

if current event type is not ES_ENTRY_HISTORY


{
if faceoff flag is true
{
current state is LINE_FOLLOWING_OFFENSE
}
else if number of balls is more than 1 {
set current state of rotate-to-shoot
}
else {
make current state the normal ENTRY_STATE
}
}
run the offense SM
}

DuringReloading
{
if event is ES_ENTRY or ES_ENTRY_HISTORY
{
Start ReloadingSM
}
else if event is ES_EXIT
{
Run ReloadingSM with this event
}else
{
run lower level ReloadingSM

}
return(ReturnEvent);
}

DuringRotatingShoot
{
if event is ES_ENTRY or ES_ENTRY_HISTORY
{
Looking for goal now, set number edges = 0

Begin Rotating
}
else if event is ES_EXIT
{
Stop Motors
disable the Timer B in Wide Timer 3 interrupt in the NVIC
}
return ReturnEvent
}

DuringFindingShot
{
if event is ES_ENTRY or ES_ENTRY_HISTORY
{
set num edges to 0

Disable flywheel pwm while initializing


Set half the period
Set value at which pin changes state
Set up+down count mode, enable PWM generator, and make generate update locally
synchronized to zero count

enable local interrupt for retroref receiver

Turn on retroreflective emitter


}
else if event is ES_EXIT
{
Disable PWM for flywheel
disable the timer

}
return ReturnEvent
}

DuringShooting
{

if event is ES_ENTRY or ES_ENTRY_HISTORY


{
Turn on flywheel (enable PWM)

Start timer for flywheel turning on

}
else if event is ES_EXIT
{
Turn off flywheel (disable PWM to PD0)

Get number of balls correct (if all balls gone, extra ghost ball so that
ball wheel turns the right amount next time)
}
return ReturnEvent
}

DuringMovingBackward
{
if event is ES_ENTRY or ES_ENTRY_HISTORY
{
Start timer for flywheel turning on
drive backwards

}
else if event is ES_EXIT
{
stop motors
}
return ReturnEvent
}

DuringRotatingToDefinitelyShoot
{

if event is ES_ENTRY or ES_ENTRY_HISTORY


{
rotate right
}
else if event is ES_EXIT
{
stop motors

}
return ReturnEvent
}

Retroreflective_ISR
{

start by clearing the source of the interrupt, the input capture event

now grab the captured value and calculate the period

if period is less than max threshold and higher than min threshold
{
increment num of edges
if num of edges is more than 20
{
create object detected event
set event param to the period
post to master SM
}
}
else {
set num edges to 0
}

update LastCapture to prepare for the next edge


}

You might also like