Sie sind auf Seite 1von 11

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

**********
MODULE VARIABLES
RaceState CurrentState
uint8_t InOut
********************************************************************************
**********
********************************************************************************
**********
POSSIBLE STATES
Race_ToRace
Race_Region2
Race_Region3
Race_Region4
Race_Region5
Race_Region6
Race_Region7
Race_Region8
********************************************************************************
**********
////////////////////////////////////////////////////////////////////////////////
//////////
PUBLIC FUNCTION RunRaceSM
ARGUMENT: ES_Event CurrentEvent
RETURN: ES_Event
LOCAL VAR: RaceState NextState
boolean MakeTransition
ES_Event ReturnEvent
Set MakeTransition to false
Set NextState to CurrentState
switch CurrentState
case Race_ToRace
Call DuringToRace to deal with CurrentEvent
if there is still an active event
switch CurrentEvent.EventType
case ES_InRegion1
Set NextState to Race_Region1
Set MakeTransition to true since we are
making transition
break
endcase
case ES_InRegion2
Set NextState to Race_Region2
Set MakeTransition to true since we are
making transition
break
endcase
case ES_InRegion3
Set NextState to Race_Region3
Set MakeTransition to true since we are
making transition
break

endcase
case ES_InRegion4
Set NextState to Race_Region4
Set MakeTransition to true since we are
making transition
break
endcase
case ES_InRegion5
Set NextState to Race_Region5
Set MakeTransition to true since we are
making transition
break
endcase
case ES_InRegion6
Set NextState to Race_Region6
Set MakeTransition to true since we are
making transition
break
endcase
case ES_InRegion7
Set NextState to Race_Region7
Set MakeTransition to true since we are
making transition
break
endcase
case ES_InRegion8
Set NextState to Race_Region8
Set MakeTransition to true since we are
making transition
break
endcase
case ES_RightDirection
Stop rotation and start moving forward
break
endcase
case ES_TIMEOUT
if Eventparam is Timer_CheckDirection
check direction
start Timer_CheckDirection
endif
endcase
endswitch
endif
break
endcase
case Race_Region1
Call DuringRegion1 to deal with CurrentEvent
if there is still an active event
switch CurrentEvent.EventType
case ES_InRegion2
Set NextState to Race_Region2
Set MakeTransition to true since we are
making transition
break
endcase
case ES_TIMEOUT
Start rotation
break
endcase
case ES_RightDirection

Stop rotation
start moving forward
break
endcase
case ES_TIMEOUT
if Eventparam is Timer_CheckDirection
check direction
start Timer_CheckDirection
endif
endcase
endswitch
endif
break
endcase
case Race_Region2
Call DuringRegion2 to deal with CurrentEvent
if there is still an active event
switch CurrentEvent.EventType
case ES_InRegion3
Set NextState to Race_Region3
Set MakeTransition to true since we are
making transition
break
endcase
case ES_RightDirection
Stop rotation and start moving forward
break
endcase
case ES_WrongDirection
start calibrate the direction
break
endcase
case ES_TIMEOUT
if Eventparam is Timer_CheckDirection
check direction
start Timer_CheckDirection
endif
endcase
endswitch
endif
break
endcase
case Race_Region3
Call DuringRegion3 to deal with CurrentEvent
if there is still an active event
switch CurrentEvent.EventType
case ES_InRegion4
Set NextState to Race_Region4
Set MakeTransition to true since we are
making transition
break
endcase
case ES_WrongDirection
start calibrate the direction
break
endcase
case ES_RightDirection
Stop rotation
start moving forward
break

endcase
case ES_TIMEOUT
if Eventparam is Timer_CheckDirection
check direction
start Timer_CheckDirection
endif
endcase
endswitch
endif
break
endcase
case Race_Region4
Call DuringRegion4 to deal with CurrentEvent
if there is still an active event
switch CurrentEvent.EventType
case ES_InRegion5
Set NextState to Race_Region5
Set MakeTransition to true since we are
making transition
break
endcase
case ES_RightDirection
Stop rotation and start moving forward
break
endcase
case ES_WrongDirection
start calibrate the direction
break
endcase
case ES_InRegion10
set MakeTransition to true
set NextState to Race_ToShoot
break
endcase
case ES_TIMEOUT
if Eventparam is Timer_CheckDirection
check direction
start Timer_CheckDirection
endif
endcase
endswitch
endif
break
endcase
case Race_Region5
Call DuringRegion5 to deal with CurrentEvent
if there is still an active event
switch CurrentEvent.EventType
case ES_InRegion6
Set NextState to Race_Region6
Set MakeTransition to true since we are
making transition
break
endcase
case ES_TIMEOUT
Start rotation
break
endcase
case ES_RightDirection
Stop rotation

start moving forward


break
endcase
case ES_TIMEOUT
if Eventparam is Timer_CheckDirection
check direction
start Timer_CheckDirection
endif
endcase
endswitch
endif
break
endcase
case Race_Region6
Call DuringRegion6 to deal with CurrentEvent
if there is still an active event
switch CurrentEvent.EventType
case ES_InRegion7
Set NextState to Race_Region7
Set MakeTransition to true since we are
making transition
break
endcase
case ES_RightDirection
Stop rotation and start moving forward
break
endcase
case ES_WrongDirection
start calibrate the direction
break
endcase
case ES_TIMEOUT
if Eventparam is Timer_CheckDirection
check direction
start Timer_CheckDirection
endif
endcase
endswitch
endif
break
endcase
case Race_Region7
Call DuringRegion7 to deal with CurrentEvent
if there is still an active event
switch CurrentEvent.EventType
case ES_InRegion8
Set NextState to Race_Region8
Set MakeTransition to true since we are
making transition
break
endcase
case ES_TIMEOUT
Start rotation
break
endcase
case ES_RightDirection
Stop rotation
start moving forward
break
endcase

case ES_TIMEOUT
if Eventparam is Timer_CheckDirection
check direction
start Timer_CheckDirection
endif
endcase
endswitch
endif
break
endcase
case Race_Region8
Call DuringRegion8 to deal with CurrentEvent
if there is still an active event
switch CurrentEvent.EventType
case ES_InRegion1
Set NextState to Race_Region1
Set MakeTransition to true since we are
making transition
break
endcase
case ES_RightDirection
Stop rotation and start moving forward
break
endcase
case ES_WrongDirection
start calibrate the direction
break
endcase
case ES_TIMEOUT
if Eventparam is Timer_CheckDirection
check direction
start Timer_CheckDirection
endif
endcase
endswitch
endif
break
endcase
case Race_Toshoot
Call DuringToShoot to deal with CurrentEvent
if there is still an active event
if CurrentEvent.EventType is ES_InPosition
stop the motor
post an event ES_ToShoot to master machi
ne
endif
endif
endcase
case Race_ToObstacle
Call DuringToObstacle to deal with CurrentEvent
if there is still an active event
switch CurrentEvent.EventType
case ES_RightDirection
stop the motor
post an event ES_ToObstacle to master ma
chine
break
endcase
case ES_WrongDirection
stop the motor

start calibrate the direction


break
endcase
case ES_TIMEOUT
if eventparam is Timer_CheckDirection
check direction
start Timer_CheckDirection
endif
break
endcase
endswitch
endif
endcase
endswitch
if MakeTransition is true
Call RunRaceSM with the parameter of ES_EXIT to execute exit function fo
r current state
set CurrentState to NextState
Call RunRaceSM with the parameter of ES_ENTRY to execute entry function
for next state
endif
return ReturnEvent
////////////////////////////////////////////////////////////////////////////////
//////////
////////////////////////////////////////////////////////////////////////////////
//////////
PUBLIC FUNCTION StartRaceSM
ARGUMENT: ES_Event CurrentEvent
RETURN: no return
LOCAL VAR: ES_Event LocalEvent
set LocalEvent to CurrentEvent
set CurrentState to Race_ToRace
endStartRaceSM
////////////////////////////////////////////////////////////////////////////////
//////////
////////////////////////////////////////////////////////////////////////////////
//////////
PUBLIC FUNCTION QueryRaceState
ARGUMENT: no argument
RETURN: RaceState
return CurrentState
endQueryRaceState
////////////////////////////////////////////////////////////////////////////////
//////////
////////////////////////////////////////////////////////////////////////////////
//////////
PRIVATE FUNCTION DuringToRace
ARGUMENT: ES_Event Event
RETURN: ES_Event

if Event.EventType is ES_ENTRY
switch Event.EventParam
case SHOOT
set Target
break
case OBSTACLE
set Target
break
case MASTER
reset flags for shoot and obstacle
set Target
break
endswitch
start rotation to align with the target
endif
else if Event.EventType is ES_EXIT
endif
else
endif
////////////////////////////////////////////////////////////////////////////////
//////////
////////////////////////////////////////////////////////////////////////////////
//////////
PRIVATE FUNCTION DuringRegion1
ARGUMENT: ES_Event Event
RETURN: ES_Event
if Event.EventType is ES_ENTRY
Set Target
start rotation to align with the target
start direction check timer
endif
else if Event.EventType is ES_EXIT
endif
else
endif
////////////////////////////////////////////////////////////////////////////////
//////////
////////////////////////////////////////////////////////////////////////////////
//////////
PRIVATE FUNCTION DuringRegion2
ARGUMENT: ES_Event Event
RETURN: ES_Event
if Event.EventType is ES_ENTRY
Set Target
start rotation to align with the target
start direction check timer
endif
else if Event.EventType is ES_EXIT
endif
else
endif
////////////////////////////////////////////////////////////////////////////////
//////////

////////////////////////////////////////////////////////////////////////////////
//////////
PRIVATE FUNCTION DuringRegion3
ARGUMENT: ES_Event Event
RETURN: ES_Event
if Event.EventType is ES_ENTRY
Start moving forward
start direction check timer
endif
else if Event.EventType is ES_EXIT
endif
else
endif
////////////////////////////////////////////////////////////////////////////////
//////////
////////////////////////////////////////////////////////////////////////////////
//////////
PRIVATE FUNCTION DuringRegion4
ARGUMENT: ES_Event Event
RETURN: ES_Event
if Event.EventType is ES_ENTRY
Set Target
start moving forward
start direction check timer
endif
else if Event.EventType is ES_EXIT
endif
else
endif
////////////////////////////////////////////////////////////////////////////////
//////////
////////////////////////////////////////////////////////////////////////////////
//////////
PRIVATE FUNCTION DuringRegion5
ARGUMENT: ES_Event Event
RETURN: ES_Event
if Event.EventType is ES_ENTRY
Start moving forward
start direction check timer
endif
else if Event.EventType is ES_EXIT
endif
else
endif
////////////////////////////////////////////////////////////////////////////////
//////////
////////////////////////////////////////////////////////////////////////////////
//////////
PRIVATE FUNCTION DuringRegion6
ARGUMENT: ES_Event Event
RETURN: ES_Event

if Event.EventType is ES_ENTRY
Set Target
start moving forward
start direction check timer
endif
else if Event.EventType is ES_EXIT
endif
else
endif
////////////////////////////////////////////////////////////////////////////////
//////////
////////////////////////////////////////////////////////////////////////////////
//////////
PRIVATE FUNCTION DuringRegion7
ARGUMENT: ES_Event Event
RETURN: ES_Event
if Event.EventType is ES_ENTRY
Start moving forward
start direction check timer
endif
else if Event.EventType is ES_EXIT
endif
else
endif
////////////////////////////////////////////////////////////////////////////////
//////////
////////////////////////////////////////////////////////////////////////////////
//////////
PRIVATE FUNCTION DuringRegion8
ARGUMENT: ES_Event Event
RETURN: ES_Event
if Event.EventType is ES_ENTRY
Set Target
start moving forward
start direction check timer
endif
else if Event.EventType is ES_EXIT
endif
else
endif
////////////////////////////////////////////////////////////////////////////////
//////////
////////////////////////////////////////////////////////////////////////////////
//////////
PRIVATE FUNCTION DuringToShoot
ARGUMENT: ES_Event Event
RETURN: ES_Event
if Event.EventType is ES_ENTRY
Set Target
start moving forward
start direction check timer

endif
else if Event.EventType is ES_EXIT
endif
else
endif
////////////////////////////////////////////////////////////////////////////////
//////////
////////////////////////////////////////////////////////////////////////////////
//////////
PRIVATE FUNCTION DuringToObstacle
ARGUMENT: ES_Event Event
RETURN: ES_Event
if Event.EventType is ES_ENTRY
Set Target
start moving forward
start direction check timer
endif
else if Event.EventType is ES_EXIT
endif
else
endif
////////////////////////////////////////////////////////////////////////////////
//////////

Das könnte Ihnen auch gefallen