0% found this document useful (0 votes)
74 views2 pages

Pseudoturntable

This pseudo-code defines a state machine for a turn table module with 3 states: 1) InitTurnTableState - Initializes the turn table and sets it to the starting position 2) WaitingToPlay - Waits for the door to close before moving to the next state 3) Motion - Moves the turn table servo to the next position and checks for game completion or loss conditions It uses events to transition between states and handle things like resetting on button press or timing out actions.

Uploaded by

api-437846864
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views2 pages

Pseudoturntable

This pseudo-code defines a state machine for a turn table module with 3 states: 1) InitTurnTableState - Initializes the turn table and sets it to the starting position 2) WaitingToPlay - Waits for the door to close before moving to the next state 3) Motion - Moves the turn table servo to the next position and checks for game completion or loss conditions It uses events to transition between states and handle things like resetting on button press or timing out actions.

Uploaded by

api-437846864
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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

You might also like