Last active
December 14, 2015 12:29
-
-
Save davstott/5087039 to your computer and use it in GitHub Desktop.
A snippet illustrating 20% and 30% PWM as well as the hardware emergency stop switch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def decide(sensors, cycle, lastCommand): | |
if sensors.userCommand == Commands.NONE: #no changes to input | |
sensors.userCommand = lastCommand | |
if sensors.frontBumper: # hardware stop triggered so stop regardless of user's opinion | |
newState = State(Commands.STOP) | |
elif sensors.userCommand == Commands.FORWARD_slow: | |
if cycle in [3,8]: # slow is 20% duty cycle | |
newState = State(Commands.FORWARD_full) | |
else: | |
newState = State(Commands.STOP) | |
elif sensors.userCommand == Commands.FORWARD_medium: | |
if cycle in [3,6,9]: # medium is 30% duty cycle | |
newState = State(Commands.STOP) | |
else: | |
newState = State(Commands.FORWARD_full) | |
else: | |
newState = State(sensors.userCommand) | |
return newState |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment