Sei sulla pagina 1di 5

OVERALL TREE STATE MACHINE

Controls the distribution of events and services to the rest of the software
MODULE VARIABLES
CurrentState
MyPriority
GrowingBranch

Current state of the tree


ES_Framework priority
Branch currently growing (if applicable)

InitTreeSM
Parameters:
Priority number of this service
Returns:
success/failure
Local Variables: Pseudo-code:
Set CurrentState to InitTSM
Post ES_INIT Event to this service
PostTreeSM
Parameters:
Returns:
Local Variables: Pseudo-code:
ES_PostToService
Return success/failure
RunTreeSM
Parameters:
Returns:
Local Variables:

ThisEvent
ReturnEvent
ReturnEvent
PostEvent

Event we are handling


ES_NO_EVENT if no errors
ES_Event to return (ES_NO_EVENT if no errors)
ES_Event for posting to other services

Pseudo-code:
SWITCH CurrentState
CurrentState is InitTSM
IF ThisEvent is ES_INIT
Set CurrentState to WaitingForArtist
Post WAITING event to this service
END IF
CurrentState is WaitingForArtist
IF ThisEvent is WAITING
Post WAITING event to motor, audio, and start buttons
END IF
IF ThisEvent is DONE_REPLAYING
Post WELCOME_REPLAY to Branch Service
END IF
IF ThisEvent is BTN_START
Set SEASON_TIMER for fraction of a second
Post RESET Event to branch and motor services
END IF
IF ThisEvent is ES_TIMEOUT and timer is SEASON_TIMER
Set CurrentState to Spring

Set SEASON_TIMER for SEASON_TIME


Post START Event to all services (Motors, Branch, Audio,
Start Button)
END IF
CurrentState is Spring
Switch ThisEvent
ThisEvent is ES_TIMEOUT and timer is SEASON_TIMER
Set CurrentState to Summer
Call ChangeSeasonTo function with parameter SUMMER
ThisEvent is BTN_WEATHER
Call HandleWeather function with parameter SPRING
ThisEvent is PROX_NEAR
Set CurrentState to SpringGrowing
Call HandleProx function with parameter of ThisEvent
ThisEvent is ANALOG_CHANGE
Call HandleAnalog function with parameter ThisEvent
END SWITCH
CurrentState is SpringGrowing
Switch ThisEvent
ThisEvent is ES_TIMEOUT
If ThisEvent Param is SEASON_TIMER
Set CurrentState to SummerGrowing
Call ChangeSeasonTo function with parameter
SUMMER
Elseif ThisEvent Param is GROWING_TIMER
Call HandleGrow function
Endif
ThisEvent is BTN_WEATHER
Call HandleWeather function with parameter SPRING
ThisEvent is PROX_FAR
Set CurrentState to Spring
Call HandleProx function with parameter of ThisEvent
ThisEvent is ANALOG_CHANGE
Call HandleAnalog function with parameter of ThisEvent
END SWITCH
CurrentState is Summer
Switch ThisEvent
ThisEvent is ES_TIMEOUT and timer is SEASON_TIMER
Set CurrentState to Fall
Call ChangeSeasonTo function with parameter FALL
ThisEvent is BTN_WEATHER
Call HandleWeather function with parameter SUMMER
ThisEvent is PROX_NEAR
Set CurrentState to SummerGrowing
Call HandleProx function with parameter of ThisEvent
ThisEvent is ANALOG_CHANGE
Call HandleAnalog function with parameter ThisEvent
END SWITCH
CurrentState is SummerGrowing

Switch ThisEvent
ThisEvent is ES_TIMEOUT
IF ThisEvent Param is SEASON_TIMER
Set CurrentState to FallGrowing
Call ChangeSeasonTo function with parameter FALL
ELSE IF ThisEvent Param is GROWING_TIMER
Call HandleGrow function
END IF
ThisEvent is BTN_WEATHER
Call HandleWeather function with parameter SUMMER
ThisEvent is PROX_FAR with param for which sensor
Set CurrentState to Summer
Call HandleProx function with parameter of ThisEvent
ThisEvent is ANALOG_CHANGE
Call HandleAnalog function with parameter of ThisEvent
END SWITCH
CurrentState is Fall
Switch ThisEvent
ThisEvent is ES_TIMEOUT and timer is SEASON_TIMER
Set CurrentState to Winter
Call ChangeSeasonTo function with parameter WINTER
ThisEvent is BTN_WEATHER
Call HandleWeather function with parameter FALL
ThisEvent is PROX_NEAR
Set CurrentState to FallGrowing
Call HandleProx function with parameter of ThisEvent
ThisEvent is ANALOG_CHANGE
Call HandleAnalog function with parameter ThisEvent
END SWITCH
CurrentState is FallGrowing
Switch ThisEvent
ThisEvent is ES_TIMEOUT
If ThisEvent Param is SEASON_TIMER
Set CurrentState to WinterGrowing
Call ChangeSeasonTo function with parameter
WINTER
Elseif ThisEvent Param is GROWING_TIMER
Call HandleGrow function
Endif
ThisEvent is BTN_WEATHER
Call HandleWeather function with parameter FALL
ThisEvent is PROX_FAR
Set CurrentState to Fall
Call HandleProx function with parameter of ThisEvent
ThisEvent is ANALOG_CHANGE
Call HandleAnalog function with parameter of ThisEvent
END SWITCH
CurrentState is Winter
Switch ThisEvent

ThisEvent is ES_TIMEOUT and timer is SEASON_TIMER


Set CurrentState to ReplayTree
Post REPLAY event to Branch Service
Turn vibration motor off
Call ChangeSeasonTo function with parameter SPRING
ThisEvent is BTN_WEATHER
Call HandleWeather function with parameter WINTER
ThisEvent is PROX_NEAR
Set CurrentState to WinterGrowing
Call HandleProx function with parameter of ThisEvent
ThisEvent is ANALOG_CHANGE
Call HandleAnalog function with parameter ThisEvent
END Switch
CurrentState is WinterGrowing
Switch ThisEvent
ThisEvent is ES_TIMEOUT
IF ThisEvent Param is SEASON_TIMER
Set CurrentState to ReplayTree
Post REPLAY event to Branch Service
Turn vibration motor off
Call ChangeSeasonTo function with parameter
SPRING
ELSE IF ThisEvent Param is GROWING_TIMER
Call HandleGrow function
END IF
ThisEvent is BTN_WEATHER
Call HandleWeather function with parameter WINTER
ThisEvent is PROX_FAR
Set CurrentState to Winter
Call HandleProx function with parameter of ThisEvent
ThisEvent is ANALOG_CHANGE
Call HandleAnalog function with parameter of ThisEvent
END Switch
CurrentState is ReplayTree
IF ThisEvent is REPLAY
Post REPLAY event to AudioBoard Service
ELSE IF ThisEvent is DONE_REPLAYING
Post WAITING event to services (Audio, Motors, Start Button)
Set CurrentState to WaitingForArtist
Post WELCOME_REPLAY event to Branch Service
END IF
END IF

HandleWeather
Parameters:
Returns:
Local Variables:

Season
-

Current season

Pseudo-code:
Post WEATHER event to Audio and Branch Service with EventParam Season
HandleProx
Parameters:
ThisEvent
A proximity sensor event
Returns:
Local Variables: Pseudo-code:
IF ThisEvent is PROX_NEAR
Store the growing branch in GrowingBranch from the event parameter
Call ChangeVibrationMotor with parameter ON
Set GROWING_TIMER for GROWING_TIME
ELSE IF ThisEvent is PROX_FAR
Call ChangeVibrationMotor with parameter OFF
END IF
HandleAnalog
Parameters:
ThisEvent
Analog event
Returns:
Local Variables: Pseudo-code:
Call SetNewColorLimit function with parameter ThisEvent.EventParam
ChangeSeasonTo
Parameters:
Season
Current season
Returns:
Local Variables: PostEvent
Event to post to other services
Pseudo-code:
Post SEASON_CHANGE event with EventParam Season to Branch Service
If CurrentState is not ReplayTree
Set SEASON_TMER for SEASON_TIME
Endif
HandleGrow
Parameters:
Returns:
Local Variables: PostEvent
Event to post to other services
Pseudo-code:
Post GROW event with EventParam GrowingBranch to BranchService
Set GROWING_TIMER for GROWING_TIME

Potrebbero piacerti anche