Sei sulla pagina 1di 6

Logic SM

Module Variable: CurrentState


Timer: LogicTimer
StartLogicSM
Receives CurrentEvent, returns nothing
Set CurrentState to LogicWait
Call RunLogicSM with CurrentEvent
End
RunLogicSM
Receives CurrentEvent, returns ReturnEvent
Init MakeTransition, NextState, EntryEventKind, ReturnEvent
If CurrentState is LogicWait
call DuringWait4Start (returns to CurrentEvent)
if CurrentEvent is ES_GameStart
Set NextState to FindTrack
Set MakeTransition to True
If CurrentState is FindTrack
call DuringFindTrack (returns to CurrentEvent)
if CurrentEvent is ES_TrackAligned
Set NextState to FollowTrack
Set MakeTransition to True
If CurrentState is FollowTrack
call DuringFollowTrack (returns to CurrentEvent)
if CurrentEvent is ES_TrackLost
Set NextState to FindTrack
Set MakeTransition to True
if CurrentEvent is ES_StationDetected
Set NextState to TakeStation
Set MakeTransition to True
If CurrentState is TakeStation
call DuringTakeStation (returns to ReturnEvent)
If CurrentEvent is ES_StationTaken
Set NextState to FollowTrack
Set MakeTransition to True
If MakeTransition is True
Recursion with ES_Exit
Set CurrentState to NextState
Recursion with EntryEventKind
End
QueryLogicSM
Receives nothing, returns LogicState
Returns CurrentState
End
DuringWait4Start (private)
Receives event, returns ReturnEvent
If ES_Entry
Post ES_Command to request game status
Start LogicTimer for 100 ms
Else
If ES_Timeout for LogicTimer
Post ES_Command to request game status
Start LogicTimer for 100 ms
End

DuringFindTrack (private)
Receives event, returns ReturnEvent
If ES_Entry
call StartFindTrackSM
If ES_Exit
call RunFindTrackSM
Else
call RunFindTrackSM (returns to ReturnEvent)
End
DuringFollowTrack (private)
Receives event, returns ReturnEvent
If ES_Entry
call StartFollowTrackSM
If ES_Exit
call RunFollowTrackSM
Else
call RunFollowTrackSM (returns to ReturnEvent)
End
DuringTakeStation (private)
Receives event, returns ReturnEvent
If ES_Entry
call StartTakeStationSM
If ES_Exit
call RunTakeStationSM
Else
call RunTakeStationSM (returns to ReturnEvent)
End
FindTrack SM
Module Variable: LastIR, CurrentState, AlignComplete
Timer: FindRotateTimer, FindForwardTimer (maybe can just use 1?)
StartFindTrackSM
Receives CurrentEvent, returns nothing
Init LastIR to 0
Set CurrentState to FindRotate
Set AlignComplete to 0
Call RunFindTrackSM
End
RunFindTrackSM
Receives CurrentEvent, returns ReturnEvent
Init MakeTransition, NextState, EntryEventKind, ReturnEvent
If CurrentState is FindRotate
If AlignComplete is 0
Call DuringFindRotateCW (returns to CurrentEvent)
If CurrentEvent is (ES_IRDetected && param is not LastIR)
or (ES_TIMEOUT for FindRotateTimer)
MakeTransition is True
NextState is FindMoveForward
If CurrentEvent is ES_IRDetected
Set LastIR to param
If CurrentState is FindMoveForward
Call DuringFindMoveForward (returns to CurrentEvent)

If CurrentEvent is ES_TIMEOUT for FindForwardTimer


MakeTransition is True
NextState is FindRotate
If CuerrentEvent is ES_TrackFound
Post ES_Drive to stop
MakeTransition is True
NextState is FindAdjust1
If CurrentState is FindAdjust1
Call DuringFindRotateCW (returns to CurrentState)
If CurrentEvent is ES_TIMEOUT for FindRotateTimer
Post ES_Drive to stop
MakeTransition is True
NextState is FindRotate
If CurrentEvent is ES_Tape2Found
Post ES_Drive to stop
MakeTransition is True
NextState is FindAdjust2
If CurrentState is FindAdjust2
Call DuringFindRotateCW (returns to CurrentState)
If CurrentEvent is ES_TIMEOUT for FindRotateTimer
Post ES_Drive to stop
MakeTransition is True
NextState is FindRotate
If CurrentEvent is ES_Tape1Found
Post ES_Drive to Stop
MakeTransition is True
NextState is FindAdjust3
If CurrentState is FindAdjust3
Call DuringFindRotateCCW (returns to CurrentState)
If CurrentEvent is ES_TIMEOUT for FindRotateTimer
Post ES_Drive to stop
Set ReturnEvent to ES_TrackAligned
MakeTransition is True
NextState is FindRotate
Set AlignComplete to 1
If MakeTransition is True
Recursion with ES_Exit
Set CurrentState to NextState
Recursion with EntryEventKind
End
DuringFindMoveForward (Private)
Receives event, returns ReturnEvent
if ES_Entry
Post ES_Drive to drive forward
Start FindForwardTimer
Return event
End
DuringFindRotateCW (Private)
Receives event, returns ReturnEvent
If ES_Entry
Post ES_Drive to rotate CW
Start FindRotateTimer for xxx(400 deg)
Return event
End
(Rotate 400 deg to avoid posting ES_Timeout while a state
transition is happening, where next state may also use the

same timer, and take that timeout as a transition signal)


DuringFindRotateCCW (Private)
Receives event, returns ReturnEvent
If ES_Entry
Post ES_Drive to rotate CCW
Start FindRotateTimer for xxx(theta/2)
Return event
End
-------------------------------------------------------------------FollowTrack SM
Problem !!: if drive CCW/CW, the radius of driving must be smaller than
the smallest trail radius !!!
Module Variable:CurrentState, FollowEnd
Timer: none
StartFollowTrackSM
Receives CurrentEvent, returns nothing
Set CurrentState to FollowForward
Set FollowEnd to 0 (must set it here)
Call RunFollowTrackSM
End
RunFollowTrackSM
Receives CurrentEvent, returns ReturnEvent
Init MakeTransition, NextState, EntryEventKind, ReturnEvent
If CurrentState is FollowForward,
If FollowEnd is 0
Call DuringFollowForward
If CurrentEvent is ES_Tape1Found
MakeTransition is True
NextState is FollowDriveCCW
If CurrentEvent is ES_Tape2Found
MakeTransition is True
NextState is FollowDriveCW
If CurrentEvent is ES_TrackLost or ES_StationDetected
Post ES_Drive to Stop
Set FollowEnd to 1
If CurrentState is FollowDriveCCW
Call DuringFollowDriveCCW
If CurrentEvent is ES_Tape1Lost
MakeTrasition is True
NextState is FollowForward
If CurrentState is FollowDriveCW
Call DuringFollowDriveCW
If CurrentEvent is ES_Tape2Lost
MakeTransition is True
NextState is FollowForward
If MakeTransition is True
Recursion with ES_Exit
Set CurrentState to NextState
Recursion with EntryEventKind
End
DuringFollowForward (Private)

Receives event, returns ReturnEvent


If ES_Entry
Post ES_Drive to move forward
End
DuringFollowDriveCCW (Private)
Receives event, returns ReturnEvent
If ES_Entry
Post ES_Drive to move forward CCW
End
DuringFollowDriveCW (Private)
Receives event, returns ReturnEvent
If ES_Entry
Post ES_Drive to move forward CW
End
---------------------------------------------------------------------TakeStation SM
Problem: after shooting, the vehicle is dis-oriented, might drive out of
the trail
Module Variable: CurrentState, Mycolor, TakeCount, PACresponse, NumShooting=5
Timer: TakeQueryTimer, ShootTimer
StartTakeStationSM
Receives CurrentEvent, returns nothing
Init Mycolor by reading the corresponding pin
Set TakeCount to 0
Set CurrentState to TakeRequest
Call RunStartTakeStationSM
End
RunTakeStationSM
Receives CurrentEvent, returns ReturnEvent
Init MakeTransition, NextState, EntryEventKind, ReturnEvent
If CurrentState is TakeRequest
If TakeCount < 2
Call DuringTakeRequest
MakeTransition is True
NextState is TakeQuery
If CurrentState is TakeQuery
Call DuringTakeQuery
If CurrentEvent is ES_TIMEOUT for TakeQueryTimer
Get PAC response bytes
If response ready and ACK
MakeTransition is True
If TakeCount < 2
NextState is TakeRequest
Else
NextState is TakeShooting
If CurrentState is TakeShooting
If station number in PACresponse is desired position &&
NumShooting > 0
Call DuringTakeShooting
If ES_TIMEOUT for ShootTimer
MakeTransition is True
NextState is TakeRequest
Set ReturnEvent to ES_StationTaken

If MakeTransition is True
Recursion with ES_Exit
Set CurrentState to NextState
Recursion with EntryEventKind
End
DuringTakeRequest (Private)
Receives event, returns ReturnEvent
If ES_Entry
Get station frequency, construct request param
Post ES_Command w/param
Increase TakeCount by 1
Returns event
End
DuringTakeQuery (Private)
If ES_Entry
Post ES_Command w/query param
Start TakeQueryTimer for 50 ms
Else
If ES_TIMEOUT for TakeQueryTimer
Post ES_Command w/query param
Start TakeQueryTimer for 50 ms
Returns event
End
DuringTakeShooting (Private)
If ES_Entry
Post ES_Shoot w/param
Start ShootTimer for xxx (~shooting time)
Decrease NumShooting by 1
Returns event
End

Potrebbero piacerti anche