State Diagram
Pseudocode
Pseudo-code for the Servo module (a service that implements a state machine)
Data private to the module: CurrentState, ServoIncrement, IncrementsLeft, CurrentPosition
InitServo
Takes a priority number, returns True if no errors
Initialize the MyPriority variable with the passed in parameter
Call ServoInitialize
Set CurrentState to ServoStandby
Post the initial transition event
End of InitServo
PostServo
Posts an event to this state machine's queue (false if the enqueue operation failed, true otherwise)
Return post given event with parameters MyPriority and ThisEvent
End of PostServo
RunServo
Takes an event ThisEvent with EventType that is one of ES_INIT, ES_TIMEOUT, TOT_DETECTED, TOT_REMOVED, RESET, or END_POTATO
Returns ES_NO_EVENT if no error ES_ERROR otherwise
Based on the state of the CurrentState variable choose one of the following blocks of code:
CurrentState is ServoStandby
If ThisEvent is TOT_DETECTED
Reset the timing servo position
Initialize the game timer and the timing servo timer
End
End ServoStandby block
CurrentState is ServoRunning
If ThisEvent is TOT_REMOVED
Reset the timing servo position
Reset IncrementsLeft
Else If ThisEvent is ES_TIMEOUT
Increment the timing servo
Initialize the timing servo timer
Else If ThisEvent is RESET or END_POTATO
Reset the timing servo position
Change CurrentState to ServoStandby
End
End ServoRunning block
End of RunServo
QueryServo
Return the CurrentState
End of QueryServo
ServoInitialize
Set the timing servo to its default position
End of ServoInitialize
IncrementServo
Calculate the ServoIncrement based on the angles remaining and IncrementsLeft
Subtract the ServoIncrement from the CurrentPosition
Move the timing servo to CurrentPosition
Decrement IncrementsLeft by 1
End of IncrementServo
ResetServo
Set the CurrentPosition to the default position
Stop the timing servo timer
End of ResetServo
Data private to the module: CurrentState, ServoIncrement, IncrementsLeft, CurrentPosition
InitServo
Takes a priority number, returns True if no errors
Initialize the MyPriority variable with the passed in parameter
Call ServoInitialize
Set CurrentState to ServoStandby
Post the initial transition event
End of InitServo
PostServo
Posts an event to this state machine's queue (false if the enqueue operation failed, true otherwise)
Return post given event with parameters MyPriority and ThisEvent
End of PostServo
RunServo
Takes an event ThisEvent with EventType that is one of ES_INIT, ES_TIMEOUT, TOT_DETECTED, TOT_REMOVED, RESET, or END_POTATO
Returns ES_NO_EVENT if no error ES_ERROR otherwise
Based on the state of the CurrentState variable choose one of the following blocks of code:
CurrentState is ServoStandby
If ThisEvent is TOT_DETECTED
Reset the timing servo position
Initialize the game timer and the timing servo timer
End
End ServoStandby block
CurrentState is ServoRunning
If ThisEvent is TOT_REMOVED
Reset the timing servo position
Reset IncrementsLeft
Else If ThisEvent is ES_TIMEOUT
Increment the timing servo
Initialize the timing servo timer
Else If ThisEvent is RESET or END_POTATO
Reset the timing servo position
Change CurrentState to ServoStandby
End
End ServoRunning block
End of RunServo
QueryServo
Return the CurrentState
End of QueryServo
ServoInitialize
Set the timing servo to its default position
End of ServoInitialize
IncrementServo
Calculate the ServoIncrement based on the angles remaining and IncrementsLeft
Subtract the ServoIncrement from the CurrentPosition
Move the timing servo to CurrentPosition
Decrement IncrementsLeft by 1
End of IncrementServo
ResetServo
Set the CurrentPosition to the default position
Stop the timing servo timer
End of ResetServo
Header
ES_Configure.h
Source Code
Download
servo.h | |
File Size: | 0 kb |
File Type: | h |
servo.c | |
File Size: | 7 kb |
File Type: | c |