Você está na página 1de 3

Data private to the module: CurrentState, LastCount, LastCountMovingBackwardSharp

RunDefenseSM(CurrentEvent)
Declare/Set MakeTransition to false
Declare/Set NextState to CurrentState
Declare/Set EntryEventKind to ES_ENTRY
Declare/Set ReturnEvent to CurrentEvent
Switch CurrentState
Case ROTATING_CW:
Set ReturnEvent, CurrentEvent to the return value of DuringRotatingCW with parameter
CurrentEvent
If CurrentEvent type is not ES_NO_EVENT:
Switch CurrentEvent type
Case EV_DEFEND_GOAL_DETECTED:
Start DEF_TIMER timer
Disable goal interrupts
Break
Case ES_TIMEOUT:
If CurrentEvent parameter is DEF_TIMER:
Set NextState to DRIVING_STRAIGHT
Set MakeTransition to true
End if
Break
End if
Break
Case DRIVING_STRAIGHT:
Set ReturnEvent, CurrentEvent to the return value of DuringDrivingStraight with
parameter CurrentEvent
If CurrentEvent type is not ES_NO_EVENT:
Switch CurrentEvent type:
Case EV_OBJECT_SHARP_DETECTED:
Set NextState to WAITING_AT_OPPONENT_GOAL
Set MakeTransition to true
Break
End if
Break
Case WAITING_AT_OPPONENT_GOAL:
Set ReturnEvent, CurrentEvent to return value of DuringWaitingAtOpponentGoal with
parameter CurrentEvent
Break
End switch

If MakeTransition is true:
Set CurrentEvent type to ES_EXIT
Call RunDefenseSM function with parameter CurrentState
Set CurrentState to NextState
Call RunDefenseSM function with parameter EntryEventKind
End if
Return ReturnEvent
End of function

StartDefenseSM(CurrentEvent)
If CurrentEvent type is not ES_ENTRY_HISTORY:
Set CurrentState to ENTRY_STATE
End if
Call SetFaceOffFalse function
Call RunDefenseSM function with parameter CurrentEvent
End of function
DuringRotatingCW(Event)
Declare/Set ReturnEvent to Event
If Event type is ES_ENTRY:
Call RotateRight function with parameter TURN_CW_SPEED
Enable the beacon sensing interrupt
Call ResetReloadEdges functions
Else if the Event type is ES_EXIT:
Call StopMotors function
Disable the beacon interrupt
End if
Return ReturnEvent
End of function

DuringDrivingStraight(Event)
Declare/Set ReturnEvent to Event
If Event type is ES_ENTRY:
Call DriveForward function with parameter DEFAULT_DUTY_CYCLE
Call SetDuty function with parameters DEFAULT_DUTY_CYCLE*1.1, LEFT
Else if Event type is ES_EXIT:
Call StopMotors function
End if
Return ReturnEvent
End of function

DuringWaitingAtOpponentGoal(Event)
Declare/Set ReturnEvent to Event
If Event type is ES_ENTRY:
Call StopMotors function
End if
Return ReturnEvent
End of function

Check4SharpEvents(void)
Declare Counts array
Call ADC_MultiRead function with parameter Counts
Declare/Set Count as SHARP value from Counts
Declare/Set Count as SHARP_MOVING_BACKWARD_ADC value from Counts
If Count is within the threshold:
Set ReturnValue to true
Declare ThisEvent
Set ThisEvent type to EV_OBJECT_DETECTED_SHARP
Call PostMasterSM function with parameter ThisEvent
Endif
If Count is within the MovingBackward threshold:
Set ReturnValue to true
Declare ThisEvent
Set ThisEvent type to EV_OBJECT_DETECTED_SHARP_3
Call PostMasterSM function with parameter ThisEvent
Endif
Set LastCountMovingBackwardSharp to CountMovingBackwardSharp
Set LastCount to Count
Return ReturnValue
End of function

Você também pode gostar