You are on page 1of 3

Obstacle State machine

***************************************************************************
MODULE VARIABLES
ObstacleState CurrentState
***************************************************************************
***************************************************************************
POSSIBLE STATES
Obstacle_ToObstacle
Obstacle_Region9
***************************************************************************
///////////////////////////////////////////////////////////////////////////
PUBLIC FUNCTION RunObstacleSM
ARGUMENT: ES_Event CurrentEvent
RETURN: ES_Event
LOCAL VAR: ObstacleState NextState
boolean MakeTransition
Set MakeTransition to false
Set NextState to CurrentState
switch CurrentState
case Obstacle_ToObstacle
call DuringToObstacleState to deal with CurrentEvent
if there is still an active event
switch CurrentEvent.EventType
case ES_InPosition
update Target (on obstacle)
Start rotation
break
endcase
case ES_RightDirection
stop rotation
start moving forward
break
endcase
case ES_InRegion9
set MakeTransition to true
set NextState to Obstacle_Region9
break
endcase
endswitch
endif
break
endcase
case Obstacle_Region9
call DuringRegion9State to deal with CurrentEvent
if there is still and active event
switch CurrentEvent.EventType
case ES_InRegion11
post an Event ES_ToRace to master machin
e
break
endcase

endswitch
endif
break
endcase
endswitch
if MakeTransition is true
call RunObstacleSM with the parameter ES_EXIT to execute the exit functi
on
set CurrentState to NextState
call RunObstacleSM with the parameter ES_ENTRY to execute the entry func
tion
endif
endcRunObstacleSM
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
PUBLIC FUNCTION StartObstacleSM
ARGUMENT: ES_Event CurrentEvent
RETURN: no return
LOCAL VAR: LocalEvent
Set LocalEvent to CurrentEvent
Set CurrentState to Obstacle_ToObstacle
Call RunObstacleSM with parameter ES_ENTRY
endStartObstacleSM
///////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
PRIVATE FUNCTION DuringToObstacleState
ARGUMENT: ES_Event CurrentEvent
RETURN: ES_EVENT
if CurrentEvent is ES_ENTRY
start moving forward
endif
else if CurrentEvent is ES_EXIT
endif
else
nothing here since there is no lower level state machine
endif
endDuringToObstacleState
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
PRIVATE FUNCTION DuringRegion9State
ARGUMENT: ES_Event CurrentEvent
RETURN: ES_EVENT
if CurrentEvent is ES_ENTRY
speed up in order to climb
endif
else if CurrentEvent is ES_EXIT
endif

else
nothing here since there is no lower level state machine
endif
//////////////////////////////////////////////////////////////////////////

You might also like