Commit ea3d4cea authored by Malte Schmitz's avatar Malte Schmitz
Browse files

Add eye movement

parent 536e3a88
......@@ -36,6 +36,34 @@ PIN_BUTTON = 24
GPIO.setup(PIN_BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# setup mini servos for eyes
PIN_SERVO_DATA_RIGHT = 2
PIN_SERVO_DATA_LEFT = 9
GPIO.setup(PIN_SERVO_DATA_RIGHT, GPIO.OUT)
GPIO.setup(PIN_SERVO_DATA_LEFT, GPIO.OUT)
pr = GPIO.PWM(PIN_SERVO_DATA_RIGHT, 50) # 50 Hz
pl = GPIO.PWM(PIN_SERVO_DATA_LEFT, 50) # 50 Hz
eyes_started = False
eyes_position = 0
def eyes_goto(degrees):
global eyes_started, eyes_position
degrees = int(round(degrees / 10.0)) * 10
right_degrees = degrees + degrees / 5
right_cycles = 12.5 - right_degrees / 18.0
left_cycles = 2.5 + degrees / 18.0
if eyes_started:
if degrees != eyes_position:
pr.ChangeDutyCycle(right_cycles)
pl.ChangeDutyCycle(left_cycles)
eyes_position = degrees
else:
pr.start(right_cycles)
pl.start(left_cycles)
eyes_started = True
# define the lower and upper boundaries of the "green"
# ball in the HSV color space, then initialize the
......@@ -105,6 +133,10 @@ def trackDepth():
print(target_x)
goto(target_x)
target_y = (450 - center[1]) / 9
print(target_y)
eyes_goto(target_y)
return rgb #video or rgb(for depth)
def track():
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment