def test1(): led.green.on() assert led.green.is_on() assert gpio.Input(led.green.pin).is_low() # pin is output led.green.off() assert led.green.is_off() assert gpio.Input(led.green.pin).is_low() # pin is output led.red.on() assert led.red.is_on() assert gpio.Input(led.red.pin).is_low() # pin is output led.red.off() assert led.red.is_off() assert gpio.Input(led.red.pin).is_low() # pin is output
def cont_voice_recog(command_predictor): outputSignal = gpio.Output(3, 2) inputSignal = gpio.Input(3, 1) outputSignal.set(gpio.LOW) map = {0: "Hit me", 1: "Left", 2: "Right", 3: "Up", 4: "Down", 5: "Garbo"} #print("Say command") window = 1 #seconds steps = 1 shift = window / steps fs = 6000 Nshift = int(shift * fs) N = window * fs n = np.arange(N) w = 0.54 - 0.46 * np.cos(2 * np.pi * n / (N - 1)) a = 0.95 samps = np.zeros((int(fs * window), 1)) while True: newsamps = (record(shift, fs, ch) - 2048) / 2048 t1 = time.time() newsamps[np.isnan(newsamps)] = 0 newsamps[abs(newsamps) > 1] = 0 samps = np.append(samps[Nshift:], newsamps) if np.mean(samps**2) > .001: melcep_out = np.zeros((12, 1)) x = samps - a * np.roll(samps, -1) #x = x[:, 0] s = x * w #DCT S = np.real(np.fft.rfft(s, axis=0)) #power P = (1 / N) * S**2 mels = np.zeros(nfilterbank) for j in range(nfilterbank): mels[j] = sum(fbank[j, :] * P[:np.shape(fbank)[1]]) melcep_out[:, 0] = np.real(np.fft.rfft(np.log(mels), axis=0)[0:12]) prediction = command_predictor.predict(melcep_out) #if prediction[0] != 3: print(map[prediction[0]]) t2 = time.time() print('delay: ', t2 - t1) if prediction[0] == 0: comm(-1, -1, -1) time.sleep(1) scan() elif prediction[0] == 2: comm(-2, -2, -2) time.sleep(1) track()
def track(): inputSignal = gpio.Input(3, 1) outputSignal = gpio.Output(3, 2) i = 0 while (1): num = take_pic(i) im = Image.open("scan" + str(i) + ".jpg") h, w, mass = processing(im) outputSignal.set(gpio.HIGH) time.sleep(0.1) outputSignal.set(gpio.LOW) comm(mass, h, w) while (not inputSignal.is_high()): pass i += 1 i %= 10
def scan(): inputSignal = gpio.Input(3, 1) outputSignal = gpio.Output(3, 2) for i in range(8): num = take_pic(i) im = Image.open("scan" + str(i) + ".jpg") #print(im.format, im.size, im.mode) h, w, mass = processing(im) #comm(mass, h, w) outputSignal.set(gpio.HIGH) time.sleep(0.01) outputSignal.set(gpio.LOW) comm(mass, h, w) while (not inputSignal.is_high()): pass while (not inputSignal.is_high()): pass n = take_pic(9)
import rcpy import rcpy.button as button import rcpy.gpio as gpio from rcpy.button import mode, pause if mode.pressed(): print('<MODE> pressed!') if mode.released(): print('<MODE> released!') pause_button = gpio.Input(gpio.PAUSE_BTN) if pause_button.low(): print('Got <PAUSE>!')