You are on page 1of 2

LaserCharging Module (a service that implements a state machine)

Data private to the module: MyPriority, CurrentState


InitializeLaserCharging
Takes a priority number, returns true.
Initialize the MyPriority variable with the passed in parameter.
Set CurrentState to be InitLaserCharging
Post ES_INIT to LaserCharging
End of InitializeLaserCharging (return True)
RunLaserCharging (implements the state machine for Laser Charging)
The EventType field of ThisEvent will be one of: ES_INIT, WheelRotationStarted, WheelRotationStopped,
DBButtonDown, DBButtonDown or ES_TIMEOUT
Returns 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 InitLaserCharging
If ThisEvent is ES_INIT
Set NextState to NoPowerLaserCharging
End if
End InitLaserCharging block
CurrentState is NoPowerLaserCharging
If ThisEvent is WheelRotationStarted and DDM state is neither Dead not Disarmed
Set NextState to NotCharging
End if
End NoPowerLaserCharging block
CurrentState is NotCharging
If ThisEvent is DBButtonDown
Start laser charging timer, which expires in 3s
Set NextState to Charging
End if
If ThisEvent is WheelRotationStopped
Set NextState to NoPowerLaserCharging
End if
End NotCharging block
CurrentState is Charging
If ThisEvent is DBButtonUp
Set NextState to NotCharging
End if
If ThisEvent is ES_TIMEOUT and parameter is laser charging timer number
Post ChargeCompleted to LaserFire queue
Turn on LaserCharged LED

Set NextState to FullyCharged


End if
If EventType is WheelRotationStopped
Set NextState to NoPowerLaserCharging
End if
End Charging block
CurrentState is FullyCharged
If ThisEvent is RisingEdge
Set NextState to NotCharging
Switch off LaserCharged LED
End if
If EventType is WheelRotationStopped
Set NextState to NoPowerLaserCharging
End if
End FullyCharged block
Set CurrentState to NextState
Return ES_NO_EVENT
End of RunLaserCharging

You might also like