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
import matplotlib.pyplot as plt #needs a better plotter | |
import numpy as np | |
class doesIt: | |
ITERATIONS = 30 | |
DIVERGETHRESHOLD = 4.0 | |
DEBUG = False | |
def iterate(self, x, c): | |
for i in range(self.ITERATIONS): |
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
mc.postToChat("Starting drawing") | |
#draw blocks at this height | |
z = 10 | |
#if we assume the most common colour will be white, we can pre-paint the backgrund to save many setBlock()s | |
#35, 0 is tileID for wool, tileData for white | |
mc.setBlocks(0,z,0,WIDTH,z,HEIGHT,35,0) | |
for x in range(WIDTH): | |
for y in range(HEIGHT): | |
# fetch the pixel value at the current position, the units are the indexes into our palette |
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
#!/usr/bin/pythonRoot | |
# bring in the libraries | |
import RPi.GPIO as G | |
from flup.server.fcgi import WSGIServer | |
import sys, urlparse | |
# set up our GPIO pins | |
G.setmode(G.BCM) | |
G.setup(18, G.OUT) |
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) |
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
import sys, fcntl, os, termios, tty | |
def init(): | |
#take the current settings | |
fnctlSettings = fcntl.fcntl(sys.stdin.fileno(), fcntl.F_GETFL) | |
termiosSettings = termios.tcgetattr(sys.stdin.fileno()) | |
# set the new ones | |
fcntl.fcntl(sys.stdin.fileno(), fcntl.F_SETFL, os.O_NONBLOCK | fnctlSettings) | |
tty.setraw(sys.stdin.fileno()) |
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
#Replacing | |
thisChar = sys.stdin.read(1) | |
#With | |
import select | |
try: | |
if select.select([sys.stdin,], [], [], 0)[0]: | |
thisChar = sys.stdin.read(1) | |
else: | |
if (debug): | |
print "nothing to read" |
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
init() | |
#target number of updates per second. hopefully The Loop completes in less time than that. | |
targetSpeed = 10 | |
# for each trip around This Seems Obvious to Dav AI Loop | |
# sleep for a bit / find out if it's time to do anything yet. | |
# read next input from sensors | |
# make any decisions | |
# set any output |