Movimiento funca

parent 4c6f6419
Showing with 46 additions and 9 deletions
......@@ -11,4 +11,10 @@ from pybricks.media.ev3dev import SoundFile, ImageFile
robot = Robot()
robot.sigueLineaHastaNegro()
robot.sigueLineaHastaNegro()
robot.giro(90)
robot.sigueLineaHastaNegro()
robot.giro(-90)
robot.sigueLineaHastaNegro()
#robot.calibraSensorColor()
......@@ -6,13 +6,14 @@ from pybricks.robotics import DriveBase
from pybricks.media.ev3dev import SoundFile, ImageFile
class Robot:
green_rgb = (27, 47, 16)
black_rgb = (4, 2, 7)
blue_rgb = (0,0,0)
tolerancia = 7
green_rgb = (36, 70, 38)
black_rgb = (5, 5, 16)
tolerancia = 10
contadorNegros = 0
w = 10
valorW = 30
w = 0
velocidad = 100
negroFlag = False
def __init__(self):
self.ev3 = EV3Brick()
......@@ -25,6 +26,8 @@ class Robot:
#Metodos gestion negros
def queNegroEs(self):
if self.contadorNegros == 0:
return 0
if self.contadorNegros % 2 == 0:
return 0
return 1
......@@ -70,20 +73,48 @@ class Robot:
else:
if (ajuste < 0):
self.robot.turn(-1)
def calibraSensorColor(self):
while True:
print(self.colorSensor.rgb())
wait(20)
def sigueLineaHastaNegro(self,color=green_rgb):
rgb = self.colorSensor.rgb()
negroAnterior = self.negroFlag
while not self.is_black(rgb) or self.queNegroEs() == 0:
#Valores iniciales
if self.is_black(rgb):
self.negroFlag = True
while self.queNegroEs() == 1 or self.contadorNegros == 0:
#Fase de lectura
rgb = self.colorSensor.rgb()
if self.is_green(rgb):
self.w = 10
self.w = self.valorW
negroAnterior= self.negroFlag
self.negroFlag = False
self.velocidad = 50
elif self.is_black(rgb):
negroAnterior = self.negroFlag
self.negroFlag = True
self.w = 0
self.velocidad = 50
else:
self.w = -10
negroAnterior= self.negroFlag
self.negroFlag = False
self.w = -self.valorW
self.velocidad = 50
#Fase de ejecución
if negroAnterior and not self.negroFlag:
self.incrementaContNegros()
self.robot.drive(self.velocidad,self.w)
print(self.contadorNegros)
self.resetContadorNegros()
def gestionRuta(self):
while True:
rgb = self.colorSensor.rgb()
......
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 sign in to comment