0% found this document useful (0 votes)
165 views2 pages

Pseudocode Motor

The document describes the initialization and state-based control of a motor. It initializes pins and reads initial values. It then enters a waiting state until receiving a start signal, at which point it enters an in-game state and controls the motor based on received commands. It can also enter states for getting tape, following a line, or being in a game over state. It continuously checks limit switches and tape sensors to detect collisions or tape and update the motor control appropriately.

Uploaded by

api-438120791
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
165 views2 pages

Pseudocode Motor

The document describes the initialization and state-based control of a motor. It initializes pins and reads initial values. It then enters a waiting state until receiving a start signal, at which point it enters an in-game state and controls the motor based on received commands. It can also enter states for getting tape, following a line, or being in a game over state. It continuously checks limit switches and tape sensors to detect collisions or tape and update the motor control appropriately.

Uploaded by

api-438120791
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

InitMotor

Initialize AD pins and read initial values


Initialize limit switch pins and direction pins
Set Duty on Motor PWM ports to zero
Post ES_INIT to self

RunMotor
Current State is InitPState
If ES_INIT received, change state to Waiting

Current State is Waiting


If ES_START received, change state to InGame
If ES_GAMEOVER received, change state to GameOver

Current State is InGame


If ES_BACKCRASH is received, Hold the motors at zero speed
If ES_FULLFRONT is received, Set both motors to forward
If ES_FULLBACK is received, Set both motors to backward
If ES_HOLD is received, Hold the motors at zero speed
If ES_GAMEOVER is received, Hold the motors at zero speed, switch state to GameOver
If ES_CW is received, Rotate Left Motor and hold right motor
If ES_CCW is received, Rotate Right motor and hold the left motor
If ES_GETOPPONENTBEACON is received, Rotate Left motor and hold the right motor
If ES_GETTAPE is received, move both motors forward, set master tape flag and switch to GetTapeMonster State

Current State is GetTapeMonster


If ES_BACKCRASH is received, Hold the motors at zero speed
If ES_FULLFRONT is received, Set both motors to forward
If ES_FULLBACK is received, Set both motors to backward
If ES_HOLD is received, Hold the motors at zero speed
If ES_GAMEOVER is received, Hold the motors at zero speed, switch state to GameOver
If ES_FOLLOWLINECW_R is received, Rotate Right Motor in reverse and hold other motor, set all three tape flags
If ES_FOLLOWLINECCW_R is received, Rotate Left motor in reverse and hold other motor, set all three tape flags
If ES_GETOPPONENTBEACON is received, Rotate Left motor and hold the right motor, move to InGame state
If ES_TAPEMIDDLE is received, move both motors backwards, move to FollowLine state

Current State is FollowLine


If ES_BACKCRASH is received, Hold the motors at zero speed, reset TapeFlags, move to InGame state
If ES_FULLFRONT is received, Set both motors to forward
If ES_FULLBACK is received, Set both motors to backward
If ES_HOLD is received, Hold the motors at zero speed
If ES_GAMEOVER is received, Hold the motors at zero speed, switch state to GameOver
If ES_TAPERIGHT is received, Rotate Left motor in reverse and hold other motor, set all three tape flags
If ES_TAPELEFT is received, Rotate Left motor and hold the right motor, move to InGame state
If ES_TAPEMIDDLE is received, move both motors backwards, move to FollowLine state

CurrentState is GameOver
------

Check4FrontWall
If front limit switch position has changed, and is pressed, post ES_FRONTCRASH to MainMasterSM
Update Lastlimitswitch position as currentposition
Check4RearWall
If rear limit switch position has changed, and is pressed, post ES_BACKCRASH to MainMasterSM and MotorService
Update Lastlimitswitch position as currentposition

Check4Tape
If MasterTapeFlag is set, check if any tape sensor senses tape and post ES_TAPEDETECTED to masterservice if Tape is
detected
If TapeLeftFlag is set, check if left sensor detects tape and post ES_TAPE_LEFT to motor service if Tape is detected
If TapeMiddle is set, check if Middle sensor detects tape and post ES_TAPE_MIDDLE to motor service if Tape is detected
If TapeRight is set, check if Right sensor detects tape and post ES_TAPE_RIGHT to motor service if Tape is detected

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy