pseudocode.
MasterControl.c
boolean InitMasterControl
Create Event with Event Type ES_ENTRY
Call the StartMasterControl Function
void StartMasterControl
Create a Local Event that equals CurrentEvent (ES_ENTRY)
Call the RunMasterControl function.
ES_Event RunMasterControl
//Call DuringMasterControl function by setting Current Event equal to DuringMasterControl
Create a Switch-Case loop to control whether we are in WAITING or PLAYING GAME.
If the state is WAITING:
- Call the DuringWaiting function. Remember, every State in every State Machine has its own During Function. In this case, the During function does nothing because Waiting has no internal State Machine.
- If the case is Caution Flag Down, transition to PLAYING GAME by setting MakeTransition equal to true, setting NextState equal to PLAYING GAME, and setting the EventType to ES_ENTRY_HISTORY.
- If the case is Game Start, transition to PLAYING GAME by setting MakeTransition equal to true and setting NextState equal to PLAYING GAME.
- Call the DuringPlayingGame function. This will start all the madness by initializing us into state Finding Tape or another state, if we’re re-entering with History. We’ll do this by - within DuringPlaying Game - calling StartPlayingGame if the eventType is Entry/w_History, or RunPlayingGame is the event type is Exit or anything else.
- If the case is Caution Flag Up, transition to WAITING by setting MakeTransition equal to true, setting NextState equal to WAITING, and setting the EventType to ES_ENTRY_HISTORY.
- If the case is Game End, transition to WAITING by setting MakeTransition to True and NextState to Waiting.
- Execute EXIT function for the current state by recursively calling RunMasterControl with event type ES_EXIT.
- Then set the CurrentState to the NextState and recursively call RunMasterControl again with the event type ES_Entry.
Return the Return Event.
ES_Event DuringWaiting
If the Event is Entry, turn off all the robots motors, both shooting and drive.
If the Event is Exit, do nothing.
There is nothing else to do as there are no sub state machines here.
ES_Event DuringPlayingGame
If the EventType is Entry, call StartPlayingGame. This will start the game running in the PlayingGame.c module.
If the EventType is Exit, do nothing.
Otherwise, run the game by setting local variable NewEvent equal to RunPlayingGame. If an event occurs, it will be posted to RunMasterControl. Depending on the state this will flow down to WAITING or PLAYING GAME. If state is WAITING, nothing will happen. If the state is PLAYING GAME, this will get picked up by the DuringPlayingGame function, which will pass it into RunPlayingGame(ES_Event). Therefore, if we’re in state FINDING TAPE within PlayingGame.c, we’ll see the event type Entering_Shooter_Zone (for instance), and act accordingly.
Roboting.c.
RunRoboting
- Create a boolean MakeTransition and set it equal to false
- Set the NextState equal to the currentState
- switch between different states
- Case Waiting
- call the duringWaiting function
- switch between events
- Case Flag Dropped
- Set the Next State equal to the Playing Game State
- Set the Make Transition Flag equal to true
- Case PlayingGame
- Call the during function for playing game
- switch between events
- Case Caution Flag Dropped
- Set the Next State equal to the Waiting State
- Set the Make Transition Flag equal to true
- If Make Transition is equal to True
- Execute the exit function for the current state
- Execute the entry function for the next state
StartRoboting
- Set local variable to get debugger to display the value of CurrentEvent
- Set CurrentState equal to Waiting for Start
DuringWaiting
- If the event is equal to ES_ENTRY
- Set all Motors off
- If the event is equal to ES_EXIT
- Call StartPlayingGameSM
DuringPlayingGame
- If the event is equal to ES_ENTRY
- Call RunPlayingGameSM
- If the event is equal to ES_EXIT
- Call RunWaiting with Caution Flag
define the entry state as STARTING_ZONE
PlayingGame.c.
RunPlayingGameSM
- Declare Boolean MakeTransaction and set to False
- Set the NextState equal to the Current State
- Assume we are not consuming an event and set ReturnEvent to CurrentEvent
- If the Start Flag is set to True
- Switch between CurrentStates
- Do this for Case Finding Wire
- Execute the during function by setting the CurrentEvent equal to Calling the DuringFindingWire function
- If the Current event is active (!=ES_No_Event)
- Switch between the currentEvents
- Do this for the case Exit
- Set the NextState = FollowingWire
- Set the MakeTransition variable to true
- break;
- Do this for Case Following Wire
- Execute the during function by setting the CurrentEvent equal to Calling the DuringFollowingWire function
- Do this for Case Shooting
- Execute the during function by setting the CurrentEvent equal to Calling the DuringShooting function
- Do this for Case ObstacleCrossing
- Execute the during function by setting the CurrentEvent equal to Calling the DuringObstacle function
- If we are making a state transition
- Execute exit function for the current state
- Execute entry functions for the new state
- return the ReturnEvent
StartPlayingGameSM
- Set local variable to get debugger to display the value of CurrentEvent
- Set current state to Finding Wire (Always start in Finding Wire)
DuringFindingWire
- If the event equals ES_ENTRY event //set the initial state of findingwire
- call StartFindingWire
- Else If the event equals ES_EXIT event gives all the lower level functions a chance to clean up
- Set a NewEvent qual to RunFindingWire(Event)
- Else , perform the during function for this state
- Set NewEvent equal to RunFindingWire(Event)
- Return(NewEvent)
DuringShooting
Start Shooting SM.
DuringObstacle
Start Obstacle Crossing SM.
ObstacleCrossing.c
StartObstacleCrossing
If Event is entering with History, then Start with the last Current State.
Else, start with Entry_State
RunObstacleCrossing
Set MakeTransition to False
Switch:
If the State is ALIGNING
Call DuringAligning
Switch:
If Orientation matches the desired Orientation, MakeTransition=True
If the State is DRIVING
Call DuringDriving
Switch:
When the timeout ends, move to next state.
If the State is DRIVING_TWO
Wait for event LeftShootingZone to take you out of Obstacle Crossing into Orienting Tape.
DuringAligning
Calculate the vector from our current position to the desired waypoint (middle of the bridge).
If our robot orientation is greater than the desired orientation, turn left. Otherwise, turn right.
Do this until our orientation matches the desired orientation, +/- 2.5 degrees.
During Driving
Drive slowly using PID Control. Calculate the Error between the robot orientation and the desired orientation (our robot position → midbridge waypoint).
If the error is positive, slightly adjust orientation to the right.
If the error is negative, slightly adjust orientation to the left.
When the midbridge point, STOP and BRAKE both drive motors. Start a Timer (wait for bridge to fall).
During Driving_Two
Drive Slowly.
ShooterSM.c.
- Create a boolean for MakeTransition
- Set the NextState equal to the CurrentState
- Assume we are not consuming an event
- Switch between Current State
- If the case equals TurnCC90
- Call the during for TurnCC90
- If an event is active
- Create an event switch statement
- Case ES_TIMEOUT (we are following the wire for the first time)
- if the event param = End Maneuver Timeout
- Set Next State equal to Driving Forward
- Set MakeTransition= True
- If the case equals Driving Forward
- Call the during for DrivingForward
- If an event is active
- Create an event switch statement
- Case ES_TIMEOUT
- if the event param = End Maneuver Timeout
- Set the Next State equal to SweepingForBeacon
- Set MakeTransition = true
- If the case equals Sweeping For Beacon
- Call the during for SweepingForBeacon
- If an event is active
- Create an event switch statement
- Case EV_IR High
- Set the next state equal to Launching Ball
- Set MakeTransition = true;
- If the case equals Launching Ball
- Turn the DC Motor on (start a timer in DC Motor)
- Turn the Servo On
- Switch Case for Event
- If the Event param = Launch DC Motor
- If we are making a state transition
- Execute exit functions for the current state
- Set CurrentState equal to NextState
- Execute entry functions for the current state
- return the ReturnEvent
StartShootingSM
- Set local variable to get debugger to display the value of CurrentEvent
- Set current state to STARTING ZONE ( always start in STARTING ZONE)
DuringTurningCCW90
- new event = event //assume no new event
- If the event is ES ENTRY
- Call function to turn 90
- If the event is ES EXIT
- If the event is all else
- return new event
DuringDrivingForward
- new event = event //assume no new event
- If the event is ES ENTRY
- Call function to drive forward
- If the event is ES EXIT
- If the event is all else
- return new event
DuringSweepingForBeacon
- new event = event //assume no new event
- If the event is ES ENTRY
- Call StartSweepingForBeacon
- If the event is ES EXIT
- If the event is all else
- Return new Event
DuringLaunchingBall
- new event = event //asume no new event
- If the event is ES ENTRY
- Call Turn DC Motor
- Start a timer
- Call Servo On
- If the event is ES EXIT
- Turn DC Motor Off
- If the event is all else
define the entry state as STARTING_ZONE
code.
code listings.
controlling_motor.c | |
File Size: | 13 kb |
File Type: | c |
dcmotorservice.c | |
File Size: | 7 kb |
File Type: | c |
dsrcontrol.c | |
File Size: | 15 kb |
File Type: | c |
eventcheckers.c | |
File Size: | 17 kb |
File Type: | c |
findingwirefromstartsm.c | |
File Size: | 8 kb |
File Type: | c |
followingwiresm.c | |
File Size: | 3 kb |
File Type: | c |
gamestatus.c | |
File Size: | 9 kb |
File Type: | c |
irsensingmodule.c | |
File Size: | 3 kb |
File Type: | c |
kart1datasm.c | |
File Size: | 9 kb |
File Type: | c |
kart2datasm.c | |
File Size: | 8 kb |
File Type: | c |
kart3datasm.c | |
File Size: | 8 kb |
File Type: | c |
mapkeys.c | |
File Size: | 5 kb |
File Type: | c |
mastersm.c | |
File Size: | 6 kb |
File Type: | c |
obstaclecrossingsm.c | |
File Size: | 17 kb |
File Type: | c |
periodicinterruptpid.c | |
File Size: | 7 kb |
File Type: | c |
playinggamesm.c | |
File Size: | 21 kb |
File Type: | c |
pwmgenerator.c | |
File Size: | 7 kb |
File Type: | c |
robotingsm.c | |
File Size: | 13 kb |
File Type: | c |
shootingsm.c | |
File Size: | 21 kb |
File Type: | c |
spidrs.c | |
File Size: | 16 kb |
File Type: | c |
sweepingforbeaconsm.c | |
File Size: | 12 kb |
File Type: | c |
es_configure.h | |
File Size: | 14 kb |
File Type: | h |
startup_rvmdk.s | |
File Size: | 17 kb |
File Type: | s |