Beruflich Dokumente
Kultur Dokumente
RunReloadingSM(CurrentEvent)
Declare/Set MakeTransition to false
Declare/Set NextState to CurrentState
Declare/Set EntryEventKind to ES_ENTRY
Declare/Set ReturnEvent to CurrentEvent
Switch CurrentState
Case ROTATING_TO_BEACON:
Set ReturnEvent, CurrentEvent to return value of DuringRotatinToBeacon function with
parameter CurrentEvent
If CurrentEvent type is not ES_NO_EVENT:
Switch CurrentEvent
Case EV_RELOADER_DETECTED:
Start RELOADING_ROTATE_TIMER timer
Enable Beacon IR interrupt
Set ReturnEvent type to ES_NO_EVENT
Break
Case ES_TIMEOUT:
If CurrentEvent parameter is RELOADING_ROTATE_TIMER:
Set NextState to LINE_FOLLOWING_RELOADING
Set MakeTransition to true
Set ReturnEvent type to ES_NO_EVENT
End if
Break
Break
Case LINE_FOLLOWING_RELOADING:
Set ReturnEvent,CurrentEvent to return value of DuringLineFollowingReloader function
with parameter CurrentEvent
If CurrentEvent type is not ES_NO_EVENT:
Switch Current Event
Case EV_SWITCH_HIT:
Set NextState to READING
Set MakeTransition to True
Set ReturnEvent type to ES_NO_EVENT
Break
End Switch
End if
Break
Break
Case READING:
Set ReturnEvent, CurrentEvent to return value of DuringReading with parameter
CurrentEvent
If CurrentEvent type is not ES_NO_EVENT:
Switch CurrentEvent type
Case EV_STATE_CHANGE:
If CurrentEvent parameter is OFFENSE:
Set NextState to WAITING_FOR_BALL
Set MakeTransition to true
Set ReturnEvent type to ES_NO_EVENT
End if
Break
End switch
End if
Break
Case WAITING_FOR_BALL:
Set ReturnEvent, CurrentEvent to return value of DuringWaitingForBall function with
parameter CurrentEvent
If CurrentEvent type is not ES_NO_EVENT:
Switch CurrentEvent type:
Case ES_TIMEOUT:
If Current Event parameter is HANDSHAKE_TIMER:
Declare ThisEvent
Set ThisEvent type to EV_STATE_CHANGE
Set ThisEvent parameter to OFFENSE
Call PostMasterSM function with parameter ThisEvent
End if
Break
End switch
End if
If MakeTransition is true:
Set CurrentEvent type to ES_EXIT
Call RunRelaodingSM function with parameter CurrentEvent
Set CurrentState to NextState
Call RunReloadingSM with parameter EntryEventKind
End if
Return ReturnEvent
End of function
StartReloadingSm(CurrentEvent)
If CurrentEvent type is not ES_ENTRY_HISTORY:
If CurrentEvent param is OVERTIME_FLAG:
Enable interrupt for handshake IR
Enable PWM for handshake emitter
Set NumEdges to 0
End if
If Reloading is true:
Set CurrentState to LINE_FOLLOWING_RELOADING
Set Reloading to false
Else:
Set CurrentState to ENTRY_STATE
End if
End if
Call RunReloadingSM function with parameter CurrentEvent
End of function
QueryReloadingSM(void):
Return CurrentState
End of function
Check4LimitSwitches(void):
Set RightLimitSwitch to value of pin B2
Set LeftLimitSwitch to value of pin B3
Declare SwitchEvent
Set SwitchEvent type to EV_SWITCH_HIT
If RightSwitch and not RightSwitchHit:
Set SwitchEvent parameter to 1
Call PostMasterSM function with parameter SwitchEvent
Set LeftSwitchHit to LeftSwitch
Return true
Else if LeftSwitch and not LeftSwitchHit:
Set SwitchEvent parameter to 0
Call PostMasterSM function with parameter SwitchEvent
Set LeftSwitchHit to LeftSwitch
Return true
End if
Set RightSwitchHit to RightSwitch
Set LeftSwitchHit to LeftSwitch
End of function
HandShake_ISR(void)
Declare ThisCapture
Clear source of interrupt
Set ThisCapture to interrupt value
Set Period to difference between ThisCapture and LastCapture
Increment NumEdges
If NumEdges mod 10 equals 0 and the change between this period and last period has changed
by less than 1 percent:
Disable PWM signal
Set half the period (load = period/4/32) adjusting for differences in clock to PWM and
timers
Set value at which pin changes state (50% duty cycle)
Set up+down count mode and enable PWM generator
Set LastPeriod to Period
End if
Set LastCapture to ThisCapture
End of function
DuringRotatingBeacon(Event)
Declare/Set ReturnEvent to Event
If Event type is ES_ENTRY:
Call RotateLeft function with parameter 65
Enable Beacon interrupt
Call ResetReloadEdges function
Else if Event type is ES_EXIT:
Disable beacon interrupt
Call StopMotors function
Else:
Do nothing
End if
Return ReturnEvent
End of function
DuringLineFollowingReloader(Event)
Declare/Set ReturnEvent to Event
If Event type is ES_ENTRY:
Call StartLineFollowingSM function with parameter Event
Else if Event type is ES_EXIT:
Call RunLineFollowingSM function with paramenter Event
Else:
Set ReturnEvent to return value of RunLineFollowingSM with parameter Event
End if
Return ReturnEvent
End of function
DuringReading(Event)
Declare/Set ReturnEvent to Event
If Event type is ES_ENTRY:
Enable handshake interrupt
Set NumEdges to 0
Start HANDSHAKE_TIMER timer
Else if Event type is ES_EXIT:
Disable handshake interrupt
Disable PWM
Else:
Do nothing
End if
Return ReturnEvent
End of function
DuringWaitingBall(Event)
Declare/Set ReturnEvent to Event
If Event type is ES_ENTRY:
Do nothing
Else if Event type is ES_EXIT:
Do nothing
Else:
Do nothing
End if
Return ReturnEvent
End of function
GetNumBalls(void)
Return NumBalls
End of function
SetNumBalls(Num)
Set NumBalls to Num
End of function
ResetFlag(void)
Set Reloading to true
End of function