Você está na página 1de 2

*************************************************************************************

Pseudo-code for the Turn Table module (a service that implements a state machine)

InitializeTurnTable
Takes a priority number, returns True.

Initialize the MyPriority variable with the passed in parameter.


Set CurrentState to be InitTurnTableState
Post Event ES_INIT to TurnTable queue (this service)
End of InitializeTurnTable

RunTurnTableSM
Set ReturnEvent to ES_NO_EVENT
Local Variables: NextState

Set NextState to CurrentState


Based on the state of the CurrentState variable choose one of the following blocks of code:

CurrentState is InitTurnTableState
If ThisEvent is ES_INIT
Set turntable to starting position
Close can servo
EndIf
If ThisEvent is ES_RESET_BUTTON
Set turntable to starting position
Close can servo
Stop CAN_SERVO_TIMER
EndIf
If ThisEvent is ES_LEAF_INSERTED
Set NextState to WaitingToPlay
EndIf
If ThisEvent is ES_TIMEOUT and EventParm is CAN_SERVO_TIMER
Open can servo
EndIf
End NotPlaying block

CurrentState is WaitingToPlay
If ThisEvent is ES_DOOR_CLOSED
Set MOTION_TIMER to MOTION_TIME
Set Servo to next position
Post ES_GAME_STARTED to Eve and Sound
Post ES_DOOR_CLOSED to Wheel
Set NextState to Motion
EndIf
If ThisEvent is ES_RESET_BUTTON
Set turntable to starting position
Close can servo
Stop CAN_SERVO_TIMER
Set NextState to InitTurnTableState
EndIf
If ThisEvent is ES_GAME_LOST
Set NextState to InitTurnTableState
EndIf
If ThisEvent is ES_GAME_WON
Set NextState to InitTurnTableState
EndIf
End WaitingToPlay block

CurrentState is Motion
If ThisEvent is ES_TIMEOUT and parameter is MOTION_TIMER
Set MOTION_TIMER to MOTION_TIME
If GameState is not WrongEvent and EveState is not HeartOn
Set servo to next position
If CurrentTurnTablePosition is at final position
Post ES_GAME_WON to all services
EndIf
EndIf
EndIf
If ThisEvent is ES_DOOR_OPENED
Post ES_GAME_LOST to List1
Set NextState to InitTurnTableState
EndIf
If ThisEvent is ES_GAME_LOST
Set NextState to InitTurnTableState
EndIf
If ThisEvent is ES_GAME_WON
Set NextState to InitTurnTableState
Set CAN_SERVO_TIMER to CAN_SERVO_DELAY
EndIf
If ThisEvent is ES_RESET_BUTTON
Set NextState to InitTurnTableState
EndIf
End NoMotion block
End of RunTurnTable

Você também pode gostar