Apaga Velas Final
Apaga Velas Final
/usr/bin/python
# -*- coding: utf-8 -*-
from Robot import *
import numpy
import random
Si = [
227,
250,
266,
300,
345,
445,
670,
740,
]
Sd = [
240,
255,
270,
300,
340,
435,
645,
725,
]
Dcm = [
28,
24,
20,
16,
12,
8,
4,
3,
]
v = [
7,
8,
9,
10,
11,
12,
6,
5,
13,
14,
]
robot = Robot(TOUCH_CONFIG)
camera = PiCamera()
stream = PiRGBArray(camera)
time.sleep(1.5)
# Variables editables
t = 0.000001
nGiros=0
hardSp = 100
softSp = 55
dentro=True
velaApagada = False
try:
while True:
if not robot.error:
rutinaPasillo(robot, hardSp, softSp)
rutinaPasillo(robot, hardSp, softSp)
if not velaApagada: # Entramos en una habitacion
robot.motors(softSp, softSp)
time.sleep(2)
converged = False
nGiros=0
while not converged and nGiros<0.9:
stream.truncate(0)
camera.capture(stream, format='bgr')
image = stream.array
c = candle(image)
if c is None and nGiros < 0.3:
robot.motors(40,-40)
time.sleep(0.1)
nGiros+=0.1
elif c is None and (nGiros >= 0.3 and nGiros <
0.9):
robot.motors(-40,40)
time.sleep(0.1)
nGiros+=0.1
else:
(x, y, w, h) = c
dx = x - 360
motor = dx * 500 / 360
if motor > 50:
motor = 50
if motor < -50:
motor = -50
print 'vueltas vueltas dubidu'
robot.motors(motor, -motor)
time.sleep(0.1)
robot.motors(0, 0)
converged = abs(motor) < 15
w = 0
while w < 160:
stream.truncate(0)
camera.capture(stream, format='bgr')
image = stream.array
c = candle(image)
if c is not None:
(x, y, w, h) = c
print w
robot.motors(softSp, softSp)
time.sleep(0.3)
robot.motors(0, 0)
else:
break
if w>0:
robot.motors(0,70)
time.sleep(0.1)
robot.fan(600)
robot.motors(0, 0)
time.sleep(4)
robot.fan(0)
robot.motors(0, 0)
robot.motors(-softSp, softSp)
time.sleep(2)
velaApagada=True
else:
robot.motors(hardSp, hardSp)
time.sleep(0.5)
robot.motors(0,0)
break
time.sleep(t)
else:
print 'Error!'
except KeyboardInterrupt:
robot.terminate()
camera.close()
robot.terminate()