Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Vicente Castellano Gómez
/
robotAmbientales
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
eac09de1
authored
May 03, 2024
by
Vicente Castellano Gómez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Añadidos metodos de giro y velocidad cambiada, falta probar
parent
7bead975
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
52 deletions
main.py
robot.py
main.py
View file @
eac09de1
...
@@ -10,12 +10,12 @@ from pybricks.media.ev3dev import SoundFile, ImageFile
...
@@ -10,12 +10,12 @@ from pybricks.media.ev3dev import SoundFile, ImageFile
robot
=
Robot
()
robot
=
Robot
()
robot
.
sigue
LineaHastaNegr
o
()
robot
.
sigue
Rect
o
()
robot
.
sigue
LineaHastaNegr
o
()
robot
.
sigue
Rect
o
()
#robot.sigueLineaHastaNegro()
#robot.sigueLineaHastaNegro()
#robot.sigueLineaHastaNegro()
#robot.sigueLineaHastaNegro()
robot
.
giro
2
(
90
)
robot
.
giro
(
90
)
robot
.
sigue
LineaHastaNegr
o
()
robot
.
sigue
Rect
o
()
robot
.
giro
2
(
-
90
)
robot
.
giro
(
-
90
)
#robot.calibraSensorColor()
#robot.calibraSensorColor()
robot.py
View file @
eac09de1
...
@@ -12,7 +12,7 @@ class Robot:
...
@@ -12,7 +12,7 @@ class Robot:
contadorNegros
=
0
contadorNegros
=
0
valorW
=
30
valorW
=
30
w
=
0
w
=
0
velocidad
=
10
0
velocidad
=
5
0
negroFlag
=
False
negroFlag
=
False
def
__init__
(
self
):
def
__init__
(
self
):
...
@@ -54,29 +54,16 @@ class Robot:
...
@@ -54,29 +54,16 @@ class Robot:
return
True
return
True
return
False
return
False
# Recogemos la lista de movimientos del algoritmo
def
calibraSensorColor
(
self
):
#def recogeListaMovimientosPedido(self, lMovimientos):
while
True
:
# for movimiento in lMovimientos:
print
(
self
.
colorSensor
.
rgb
())
# self.colaMovimientos.put(movimiento)
wait
(
20
)
#Metodos para el movimiento
#Metodos para el movimiento
def
giro
(
self
,
grados
):
def
giro
(
self
,
grados
):
self
.
giroSensor
.
reset_angle
(
0
)
self
.
giroSensor
.
reset_angle
(
0
)
self
.
robot
.
turn
(
grados
)
self
.
robot
.
turn
(
grados
)
while
(
self
.
giroSensor
.
angle
()
!=
grados
):
diferencia
=
self
.
giroSensor
.
angle
()
-
grados
ajuste
=
diferencia
*
-
1
for
i
in
range
(
abs
(
ajuste
)):
if
(
ajuste
>
0
):
self
.
robot
.
turn
(
1
)
else
:
if
(
ajuste
<
0
):
self
.
robot
.
turn
(
-
1
)
def
giro2
(
self
,
grados
):
self
.
robot
.
straight
(
60
)
self
.
giroSensor
.
reset_angle
(
0
)
self
.
robot
.
turn
(
grados
)
while
(
self
.
giroSensor
.
angle
()
!=
grados
):
while
(
self
.
giroSensor
.
angle
()
!=
grados
):
diferencia
=
self
.
giroSensor
.
angle
()
-
grados
diferencia
=
self
.
giroSensor
.
angle
()
-
grados
ajuste
=
diferencia
*
-
1
ajuste
=
diferencia
*
-
1
...
@@ -86,12 +73,16 @@ class Robot:
...
@@ -86,12 +73,16 @@ class Robot:
else
:
else
:
if
(
ajuste
<
0
):
if
(
ajuste
<
0
):
self
.
robot
.
turn
(
-
1
)
self
.
robot
.
turn
(
-
1
)
def
calibraSensorColor
(
self
):
while
True
:
print
(
self
.
colorSensor
.
rgb
())
wait
(
20
)
def
sigueLineaHastaNegro
(
self
,
color
=
green_rgb
):
def
giraDerecha
(
self
):
self
.
robot
.
straight
(
60
)
self
.
giro
(
90
)
def
giraIzquierda
(
self
):
self
.
robot
.
straight
(
60
)
self
.
giro
(
-
90
)
def
sigueRecto
(
self
,
color
=
green_rgb
):
# Valores iniciales
# Valores iniciales
rgb
=
self
.
colorSensor
.
rgb
()
rgb
=
self
.
colorSensor
.
rgb
()
negroAnteriorFlag
=
self
.
negroFlag
negroAnteriorFlag
=
self
.
negroFlag
...
@@ -127,34 +118,16 @@ class Robot:
...
@@ -127,34 +118,16 @@ class Robot:
self
.
robot
.
drive
(
self
.
velocidad
,
self
.
w
)
self
.
robot
.
drive
(
self
.
velocidad
,
self
.
w
)
print
(
self
.
contadorNegros
,
contNegroAnterior
)
print
(
self
.
contadorNegros
,
contNegroAnterior
)
def
gestionRuta
(
self
):
while
True
:
rgb
=
self
.
colorSensor
.
rgb
()
#caso en que detecta linea verde
#Deficnición y realización de la ruta
if
self
.
is_green
(
rgb
):
self
.
robot
.
drive
(
100
,
0
)
#caso detecta negro
# Recogemos la lista de movimientos del algoritmo
elif
self
.
is_black
(
rgb
):
#def recogeListaMovimientosPedido(self, lMovimientos):
#incremento el contador
# for movimiento in lMovimientos:
contNegroAnterior
=
self
.
contadorNegros
# self.colaMovimientos.put(movimiento)
self
.
incrementaContNegros
()
#miro si es par o impar
if
self
.
queNegroEs
()
==
0
:
#si es par es que es linea por lo que avanzo para sobrepasar la linea
self
.
robot
.
drive
(
100
,
0
)
else
:
#caso en que encuentro cuadrado
self
.
ev3
.
speaker
.
beep
()
self
.
robot
.
stop
()
#caso en que se detecta otro color
else
:
self
.
robot
.
drive
(
0
,
50
)
#Deficnición y realización de la ruta
def
rutaPedido
(
self
):
def
rutaPedido
(
self
):
while
self
.
colaMovimientos
.
not_empty
():
while
self
.
colaMovimientos
.
not_empty
():
movimientoAct
=
self
.
colaMovimientos
.
get
()
movimientoAct
=
self
.
colaMovimientos
.
get
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment