Skip to content

Instantly share code, notes, and snippets.

@davstott
Last active December 14, 2015 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davstott/5087039 to your computer and use it in GitHub Desktop.
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
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