def body(self, dev, *args): """Initialize movement variables""" acc = freenect.get_accel(dev) accX = int(acc[0]) accY = int(acc[1]) accZ = int(acc[2]) accX = accX - self.acceleration[0] accY = accY - self.acceleration[1] accZ = accZ - self.acceleration[2] self.velocity[0] += accX self.velocity[1] += accY self.velocity[2] += accZ self.acceleration[0] = int(acc[0]) self.acceleration[1] = int(acc[1]) self.acceleration[2] = int(acc[2]) if self.connected: self.send_kinect_info(self.velocity, [accX, accY, accZ]) if self.kill_kinect: freenect.shutdown(dev)
def body(dev, ctx): global last_time if time.time() - last_time < 3: return last_time = time.time() led = random.randint(0, 6) tilt = random.randint(0, 30) freenect.set_led(dev, led) freenect.set_tilt_degs(dev, tilt) print('led[%d] tilt[%d] accel[%s]' % (led, tilt, freenect.get_accel(dev)))
def body(dev, ctx): #global last_time if not keep_running: raise freenect.Kill #last_time = time.time() led = 1 tilt = int(input("Enter a degree 0 - 30: ")) #tilt = random.randint(0, 30) freenect.set_led(dev, led) freenect.set_tilt_degs(dev, tilt) print('led[%d] tilt[%d] accel[%s]' % (led, tilt, freenect.get_accel(dev)))
def body(dev, ctx): global last_time print "Doing something" if not keep_running: raise freenect.Kill if time.time() - last_time < 3: return last_time = time.time() led = random.randint(0, 6) tilt = 30 #random.randint(0, 30) freenect.set_led(dev, led) freenect.set_tilt_degs(dev, tilt) print('led[%d] tilt[%d] accel[%s]' % (led, tilt, freenect.get_accel(dev)))
def body(dev, ctx): global last_time global led global tilt if not keep_running: raise freenect.Kill if led > 6 and tilt > 30: return freenect.set_led(dev, led) freenect.set_tilt_degs(dev, tilt) print('led[%d] tilt[%d] accel[%s]' % (led, tilt, freenect.get_accel(dev))) time.sleep(1) led = led + 1 tilt = tilt + 5
def mybody(*args): dev, ctx = args global last_time print(last_time) if not keep_running: raise freenect.Kill if time.time() - last_time < 3: return last_time = time.time() led = random.randint(0, 6) tilt = random.randint(0, 30) freenect.set_led(dev, led) freenect.set_tilt_degs(dev, tilt) print('led[%d] tilt[%d] accel[%s]' % (led, tilt, freenect.get_accel(dev)))
def body(dev, *args): global alpha global previousAcc global velocity global was_moving acc = freenect.get_accel(dev) accX = int(acc[0]) accY = int(acc[1]) accZ = int(acc[2]) accX = accX - previousAcc[0] accY = accY - previousAcc[1] accZ = accZ - previousAcc[2] velocity[0] += accX velocity[1] += accY velocity[2] += accZ previousAcc[0] = int(acc[0]) previousAcc[1] = int(acc[1]) previousAcc[2] = int(acc[2]) if abs(velocity[0]) > 0 or abs(velocity[2]) > 0: print("Moving!!\tX: " + str(velocity[0]) + "m/s\tZ: " + str(velocity[2]) + "m/s") was_moving = True elif was_moving: print("Stopped moving") was_moving = False buf = ByteBuffer(bytearray([0] * 24), 0, 24) buf.put_SLInt32(accX) buf.put_SLInt32(accY) buf.put_SLInt32(accZ) buf.put_SLInt32(velocity[0]) buf.put_SLInt32(velocity[1]) buf.put_SLInt32(velocity[2]) arr = bytearray([0] * 25) arr[0] = 0x03 buf.set_position(0) buf.get(arr, 1, 24) sock.send(arr) if not keep_running: raise freenect.Kill
def body(dev, ctx): global last_time if not keep_running: raise freenect.Kill if time.time() - last_time < 3: return print "boop" last_time = time.time() led = random.randint(0, 6) tilt = random.randint(0, 30) print "set_led(%s)" % led freenect.set_led(dev, led) print "set_tilt_degs(%s)" % tilt freenect.set_tilt_degs(dev, tilt) print('led[%d] tilt[%d] accel[%s]' % (led, tilt, freenect.get_accel(dev)))
def rand_led_tilt(dev, ctx): """Randomly changes the led and tilt position every 3 seconds""" global last_time if time.time() - last_time < 3: return last_time = time.time() led = random.randint(0, 6) tilt = random.randint(0, 30) freenect.set_led(dev, led) freenect.set_tilt_degs(dev, tilt) print('led[%d] tilt[%d] accel[%s]' % (led, tilt, freenect.get_accel(dev)))
def body(dev): global last_time if not keep_running: raise freenect.Kill if time.time() - last_time < 3: return last_time = time.time() for i in range(0, 6): led = i tilt = i * 5 time.sleep(3) freenect.set_led(dev, led) freenect.set_tilt_degs(dev, tilt) print('led[%d] tilt[%d] accel[%s]' % (led, tilt, freenect.get_accel(dev)))
def body(dev, ctx): global last_time global tilt global light if not keep_running: raise freenect.Kill if tilt == 30: return if time.time() - last_time < 3: return last_time = time.time() led = light freenect.set_led(dev, led) freenect.set_tilt_degs(dev, tilt) print('led[%d] tilt[%d] accel[%s]' % (led, tilt, freenect.get_accel(dev)))
def body(dev, ctx): global last_time, tilt0 if not keep_running: raise freenect.Kill if time.time() - last_time < 1: return last_time = time.time() led = 2 if faceFound and abs(tilt - tilt0) > 0: led = 3 if faceFound and abs(tilt - tilt0) == 0: led = 4 tilt0 = tilt freenect.set_led(dev, led) freenect.set_tilt_degs(dev, tilt) print('led[%d] tilt[%d] accel[%s]' % (led, tilt, freenect.get_accel(dev))) if not keep_running: raise freenect.Kill
def body(dev, ctx): global last_time if not keep_running: raise freenect.Kill if time.time() - last_time < 3: return last_time = time.time() # rotate through the different colors if led > 6: led = 0 else: led = led + 1 freenect.set_led(dev, led) # tilt back and forth if (tilt > 30 or tilt < 0): tilt = 0 if (time.time() % 30 < 15): tilt = tile + 5 else: tilt = tilt - 5 freenect.set_tilt_degs(dev, tilt) print('led[%d] tilt[%d] accel[%s]' % (led, tilt, freenect.get_accel(dev)))
def body(dev, ctx): global deg freenect.set_tilt_degs(dev, deg) print('tilt[%d] accel[%s]' % (tilt, freenect.get_accel(dev)))