Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Demo of haptic feedback glove for ycombinator hardware hackathon

View Haptic Demo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
#!/usr/bin/python
 
import time
import RPi.GPIO as GPIO
from robot_brain.servo import Servo
 
GPIO.setmode(GPIO.BCM)
 
GPIO_TRIGGER = 25
GPIO_ECHO = 24
k = .7 # filter constant
rotation_filtered = 0
servo = Servo(min=60, max=250)
scalar = 50 # smaller is more finger movement
 
GPIO.setup(GPIO_TRIGGER, GPIO.OUT) # Trigger
GPIO.setup(GPIO_ECHO, GPIO.IN) # Echo
 
GPIO.output(GPIO_TRIGGER, False)
 
# Allow module to settle
time.sleep(0.5)
 
while True:
# Send 10us pulse to trigger
GPIO.output(GPIO_TRIGGER, True)
time.sleep(0.00001)
GPIO.output(GPIO_TRIGGER, False)
 
while GPIO.input(GPIO_ECHO)==0:
pass # wait for pin to go high
 
start = time.time()
while GPIO.input(GPIO_ECHO)==1:
stop = time.time()
if (stop - start) > .1:
break
 
# Calculate pulse length
elapsed = stop - start
 
# Distance pulse travelled in that time is time
# multiplied by the speed of sound (cm/s)
distance = elapsed * 34300
 
# That was the distance there and back so halve the value
distance = distance / 2
 
# Calculate how much to rotate the servo (scale between 0 and 1)
rotation = distance / 50
if rotation > 1:
rotation = 1
# A simple moving average filter
rotation_filtered = k * rotation_filtered + (1.0 - k) * rotation
rot = 1 - rotation_filtered
servo.set(rot)
print 'setting servo to:', rot
time.sleep(.1)
Owner

You can find the robot_brain package here: https://github.com/jminardi/RobotBrain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.